Class: RuboCop::Cop::Layout::AssignmentIndentation
- Includes:
- Alignment, CheckAssignment
- Defined in:
- lib/rubocop/cop/layout/assignment_indentation.rb
Overview
This cop checks the indentation of the first line of the right-hand-side of a multi-line assignment.
The indentation of the remaining lines can be corrected with other cops such as `IndentationConsistency` and `EndAlignment`.
Constant Summary collapse
- MSG =
'Indent the first line of the right-hand-side of a ' \ 'multi-line assignment.'
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Cop
Attributes inherited from Base
Instance Method Summary collapse
- #autocorrect(node) ⇒ Object
- #check_assignment(node, rhs) ⇒ Object
- #leftmost_multiple_assignment(node) ⇒ Object
Methods included from CheckAssignment
extract_rhs, #on_lvasgn, #on_send
Methods inherited from Cop
#add_offense, all, #corrections, #find_location, #highlights, joining_forces, #messages, #on_investigation_end, #on_new_investigation, #parse, qualified_cop_name, registry, support_autocorrect?, #support_autocorrect?
Methods inherited from Base
#add_global_offense, #add_offense, autocorrect_incompatible_with, badge, #callbacks_needed, callbacks_needed, #config_to_allow_offenses, #config_to_allow_offenses=, #cop_config, #cop_name, cop_name, department, documentation_url, exclude_from_registry, #excluded_file?, #external_dependency_checksum, inherited, #initialize, joining_forces, lint?, match?, #message, #offenses, #on_investigation_end, #on_new_investigation, #on_other_file, #ready, #relevant_file?, support_autocorrect?, support_multiple_source?, #target_rails_version, #target_ruby_version
Methods included from AutocorrectLogic
#autocorrect?, #autocorrect_enabled?, #autocorrect_requested?, #correctable?, #disable_uncorrectable?, #safe_autocorrect?
Methods included from IgnoredNode
#ignore_node, #ignored_node?, #part_of_ignored_node?
Methods included from Util
Constructor Details
This class inherits a constructor from RuboCop::Cop::Base
Instance Method Details
#autocorrect(node) ⇒ Object
40 41 42 |
# File 'lib/rubocop/cop/layout/assignment_indentation.rb', line 40 def autocorrect(node) AlignmentCorrector.correct(processed_source, node, column_delta) end |
#check_assignment(node, rhs) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/rubocop/cop/layout/assignment_indentation.rb', line 31 def check_assignment(node, rhs) return unless rhs return unless node.loc.operator return if node.loc.operator.line == rhs.first_line base = display_column(leftmost_multiple_assignment(node).source_range) check_alignment([rhs], base + configured_indentation_width) end |
#leftmost_multiple_assignment(node) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/rubocop/cop/layout/assignment_indentation.rb', line 44 def leftmost_multiple_assignment(node) return node unless same_line?(node, node.parent) && node.parent.assignment? leftmost_multiple_assignment(node.parent) node.parent end |