123456789_123456789_123456789_123456789_123456789_

Class: RuboCop::Cop::HashAlignmentStyles::SeparatorAlignment

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: lib/rubocop/cop/mixin/hash_alignment_styles.rb

Overview

Handles calculation of deltas when the enforced style is 'separator'.

Instance Method Summary

Instance Method Details

#deltas(first_pair, current_pair)

Keys are right-aligned by the column their last line ends on. A key spanning several lines ends on a line other than the one it starts on, so moving its first line would never change that column and the correction would be repeated on every pass. Such pairs are left alone, and so is every pair when the first key spans several lines, since there is then no column to right-align to.

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/hash_alignment_styles.rb', line 160

def deltas(first_pair, current_pair)
  return {} if first_pair.key.multiline? || current_pair.key.multiline?

  super
end

#deltas_for_first_pair(_first_pair)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/hash_alignment_styles.rb', line 151

def deltas_for_first_pair(_first_pair)
  {}
end

#hash_rocket_delta(first_pair, current_pair) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/hash_alignment_styles.rb', line 172

def hash_rocket_delta(first_pair, current_pair)
  first_pair.delimiter_delta(current_pair)
end

#key_delta(first_pair, current_pair) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/hash_alignment_styles.rb', line 168

def key_delta(first_pair, current_pair)
  first_pair.key_delta(current_pair, :right)
end

#value_delta(first_pair, current_pair) (private)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/hash_alignment_styles.rb', line 176

def value_delta(first_pair, current_pair)
  return 0 if first_pair.equal?(current_pair) || current_pair.value_omission?

  expected_value_column = first_pair.loc.operator.end.column + 1
  expected_value_column - current_pair.value.loc.column
end