Class: RuboCop::Cop::Layout::OrderedMethods
- Inherits:
-
RuboCop::Cop
- Object
- RuboCop::Cop
- RuboCop::Cop::Layout::OrderedMethods
- Includes:
- IgnoredMethods, RangeHelp
- Defined in:
- lib/rubocop/cop/layout/ordered_methods.rb
Overview
Constant Summary collapse
- COMPARISONS =
{ 'alphabetical' => lambda do |left_method, right_method| (left_method.method_name <=> right_method.method_name) != 1 end }.freeze
- ERR_INVALID_COMPARISON =
'Invalid "Comparison" config for ' \ "#{cop_name}. Expected one of: #{COMPARISONS.keys.join(', ')}".freeze
Instance Method Summary collapse
Instance Method Details
#autocorrect(node) ⇒ Object
45 46 47 |
# File 'lib/rubocop/cop/layout/ordered_methods.rb', line 45 def autocorrect(node) @corrector.correct(node, @previous_node) end |
#on_begin(node) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rubocop/cop/layout/ordered_methods.rb', line 49 def on_begin(node) cache(node) consecutive_methods(@siblings) do |previous, current| unless ordered?(previous, current) @previous_node = previous add_offense( current, message: 'Methods should be sorted in ' \ "#{cop_config['EnforcedStyle']} order." ) end end end |