Class: RuboCop::Cop::OrderedMethodsCorrector

Inherits:
Object
  • Object
show all
Includes:
QualifierNodeMatchers
Defined in:
lib/rubocop/cop/correctors/ordered_methods_corrector.rb

Overview

This auto-corrects method order

Constant Summary

Constants included from QualifierNodeMatchers

QualifierNodeMatchers::QUALIFIERS

Instance Method Summary collapse

Methods included from QualifierNodeMatchers

#method_qualifier?, #qualifiers

Constructor Details

#initialize(comment_locations, siblings, cop_config) ⇒ OrderedMethodsCorrector

Returns a new instance of OrderedMethodsCorrector.

Parameters:

  • cop_config

    ::RuboCop::Config



14
15
16
17
18
# File 'lib/rubocop/cop/correctors/ordered_methods_corrector.rb', line 14

def initialize(comment_locations, siblings, cop_config)
  @comment_locations = comment_locations
  @siblings = siblings
  @cop_config = cop_config
end

Instance Method Details

#correct(node, previous_node, corrector) ⇒ Object



20
21
22
23
24
25
# File 'lib/rubocop/cop/correctors/ordered_methods_corrector.rb', line 20

def correct(node, previous_node, corrector)
  AliasMethodOrderVerifier.verify!(node, previous_node)
  current_range = join_surroundings(node)
  previous_range = join_surroundings(previous_node)
  corrector.swap(current_range, previous_range)
end