Class: RuboCop::Cop::HashAlignment::KeyAlignment

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

Overview

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

Instance Method Summary collapse

Instance Method Details

#checkable_layout?(_node) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/rubocop/cop/mixin/hash_alignment.rb', line 9

def checkable_layout?(_node)
  true
end

#deltas(first_pair, current_pair) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubocop/cop/mixin/hash_alignment.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) ⇒ Object



13
14
15
16
17
18
# File 'lib/rubocop/cop/mixin/hash_alignment.rb', line 13

def deltas_for_first_pair(first_pair, _node)
  {
    separator: separator_delta(first_pair),
    value: value_delta(first_pair)
  }
end