Class: RuboCop::Cop::HashAlignmentStyles::SeparatorAlignment
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
self,
ValueAlignment
|
|
| 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
-
#deltas(first_pair, current_pair)
Keys are right-aligned by the column their last line ends on.
- #deltas_for_first_pair(_first_pair)
- #hash_rocket_delta(first_pair, current_pair) private
- #key_delta(first_pair, current_pair) private
- #value_delta(first_pair, current_pair) private
ValueAlignment - Included
| #checkable_layout?, | |
| #deltas | With several enforced styles, deltas are computed even for a hash this style can’t check. |
| #alignable_values?, #pair_after_kwsplat_on_same_line?, #separator_delta, #separator_shift, #value_on_later_line? | |
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.
# File 'lib/rubocop/cop/mixin/hash_alignment_styles.rb', line 181
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 172
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 193
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 189
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 197
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