class RuboCop::Cop::HashAlignment::TableAlignment
Handles calculation of deltas when the enforced style is 'table'.
Attributes
max_key_width[RW]
Public Instance Methods
deltas_for_first_pair(first_pair, node)
click to toggle source
The table style is the only one where the first key-value pair can be considered to have bad alignment.
# File lib/rubocop/cop/mixin/hash_alignment.rb, line 59 def deltas_for_first_pair(first_pair, node) self.max_key_width = node.keys.map { |key| key.source.length }.max separator_delta = separator_delta(first_pair, first_pair, 0) { separator: separator_delta, value: value_delta(first_pair, first_pair) - separator_delta } end
Private Instance Methods
hash_rocket_delta(first_pair, current_pair)
click to toggle source
# File lib/rubocop/cop/mixin/hash_alignment.rb, line 77 def hash_rocket_delta(first_pair, current_pair) first_pair.loc.column + max_key_width + 1 - current_pair.loc.operator.column end
key_delta(first_pair, current_pair)
click to toggle source
# File lib/rubocop/cop/mixin/hash_alignment.rb, line 73 def key_delta(first_pair, current_pair) first_pair.key_delta(current_pair) end
value_delta(first_pair, current_pair)
click to toggle source
# File lib/rubocop/cop/mixin/hash_alignment.rb, line 82 def value_delta(first_pair, current_pair) return 0 if current_pair.kwsplat_type? correct_value_column = first_pair.key.loc.column + current_pair.delimiter(true).length + max_key_width correct_value_column - current_pair.value.loc.column end