Class: RuboCop::Cop::Tablecop::AlignAssignments

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/tablecop/align_assignments.rb

Overview

Aligns consecutive assignment statements on the ‘=` operator.

Handles simple assignments (‘=`), compound assignments (`||=`, `&&=`, `+=`, etc.), and constant assignments. Skips lines containing heredocs entirely to avoid infinite loops with Layout/SpaceAroundOperators.

Examples:

# bad
x = 1
foo = 2
barbaz = 3

# good
x      = 1
foo    = 2
barbaz = 3

Compound operators

# bad
data ||= attrs
options = default

# good
data    ||= attrs
options = default

Constant Summary collapse

MSG =
"Align assignment with other assignments in group"
ASSIGNMENT_TYPES =

Assignment types we handle

%i[lvasgn ivasgn cvasgn gvasgn casgn op_asgn or_asgn and_asgn].freeze

Instance Method Summary collapse

Instance Method Details

#on_new_investigationObject



40
41
42
43
44
45
# File 'lib/rubocop/cop/tablecop/align_assignments.rb', line 40

def on_new_investigation
  return if processed_source.blank?

  groups = find_assignment_groups
  groups.each { |group| check_group(group) }
end