Class: RuboCop::Cop::HashAlignmentStyles::KeyAlignment
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rubocop/cop/mixin/hash_alignment_styles.rb |
Overview
Handles calculation of deltas when the enforced style is 'key'.
Instance Method Summary
Instance Method Details
#checkable_layout?(_node) ⇒ Boolean
# File 'lib/rubocop/cop/mixin/hash_alignment_styles.rb', line 9
def checkable_layout?(_node) true end
#deltas(first_pair, current_pair)
[ GitHub ]# File 'lib/rubocop/cop/mixin/hash_alignment_styles.rb', line 20
def deltas(first_pair, current_pair) if Util.begins_its_line?(current_pair.source_range) key_delta = first_pair.key_delta(current_pair) separator_delta = separator_delta(current_pair) value_delta = value_delta(current_pair) { key: key_delta, separator: separator_delta, value: value_delta } else {} end end
#deltas_for_first_pair(first_pair, _node)
[ GitHub ]# File 'lib/rubocop/cop/mixin/hash_alignment_styles.rb', line 13
def deltas_for_first_pair(first_pair, _node) { separator: separator_delta(first_pair), value: value_delta(first_pair) } end
#separator_delta(pair) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/hash_alignment_styles.rb', line 34
def separator_delta(pair) if pair.hash_rocket? correct_separator_column = pair.key.source_range.end.column + 1 actual_separator_column = pair.loc.operator.column correct_separator_column - actual_separator_column else 0 end end
#value_delta(pair) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/hash_alignment_styles.rb', line 45
def value_delta(pair) return 0 if pair.value_on_new_line? || pair.value_omission? correct_value_column = pair.loc.operator.end.column + 1 actual_value_column = pair.value.loc.column correct_value_column - actual_value_column end