Class: Collie::Linter::Rules::LongRule
- Defined in:
- lib/collie/linter/rules/long_rule.rb
Overview
Detects rules with too many alternatives
Constant Summary collapse
- DEFAULT_MAX_ALTERNATIVES =
10
Constants inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#autocorrectable?, #initialize
Constructor Details
This class inherits a constructor from Collie::Linter::Base
Instance Method Details
#check(ast, _context = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/collie/linter/rules/long_rule.rb', line 15 def check(ast, _context = {}) max_alternatives = config_value(:max_alternatives, DEFAULT_MAX_ALTERNATIVES) each_rule_like(ast) do |rule| alternatives_count = rule.alternatives.size next unless alternatives_count > max_alternatives add_offense( rule, message: "Rule '#{rule_like_name(rule)}' has #{alternatives_count} alternatives " \ "(max: #{max_alternatives}). Consider refactoring." ) end @offenses end |