Class: RuboCop::Cop::Style::AlignHash::TableAlignment

Inherits:
AlignmentOfValues show all
Defined in:
lib/rubocop/cop/style/align_hash.rb

Overview

Handles calculation of deltas when the enforced style is ‘table’.

Instance Method Summary collapse

Methods inherited from AlignmentOfValues

#checkable_layout, #deltas

Methods included from HashNode

#any_pairs_on_the_same_line?

Instance Method Details

#deltas_for_first_pair(first_pair, node) ⇒ Object

The table style is the only one where the first key-value pair can be considered to have bad alignment.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rubocop/cop/style/align_hash.rb', line 72

def deltas_for_first_pair(first_pair, node)
  key_widths = node.children.map do |pair|
    key, _value = *pair
    key.source.length
  end
  @max_key_width = key_widths.max

  separator_delta = separator_delta(first_pair,
                                    first_pair.loc.operator, 0)
  {
    separator: separator_delta,
    value:     value_delta(first_pair, first_pair) - separator_delta
  }
end