Class: RuboCop::Cop::HashAlignment::TableAlignment

Inherits:
Object
  • Object
show all
Includes:
ValueAlignment
Defined in:
lib/rubocop/cop/mixin/hash_alignment.rb

Overview

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

Instance Method Summary collapse

Methods included from ValueAlignment

#checkable_layout?, #deltas

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.



59
60
61
62
63
64
65
66
67
# 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