lib/rubocop/cop/style/align_hash.rb in rubocop-0.30.1 vs lib/rubocop/cop/style/align_hash.rb in rubocop-0.31.0

- old
+ new

@@ -17,15 +17,15 @@ def deltas_for_first_pair(*) {} # The first pair is always considered correct. end - def deltas(first_pair, prev_pair, current_pair) - if current_pair.loc.line == prev_pair.loc.line - {} - else + def deltas(first_pair, current_pair) + if Util.begins_its_line?(current_pair.loc.expression) { key: first_pair.loc.column - current_pair.loc.column } + else + {} end end end # Common functionality for the styles where not only keys, but also @@ -33,11 +33,11 @@ class AlignmentOfValues def checkable_layout(node) !any_pairs_on_the_same_line?(node) && all_have_same_separator?(node) end - def deltas(first_pair, _prev_pair, current_pair) + def deltas(first_pair, current_pair) key_delta = key_delta(first_pair, current_pair) current_separator = current_pair.loc.operator separator_delta = separator_delta(first_pair, current_separator, key_delta) value_delta = value_delta(first_pair, current_pair) - @@ -55,15 +55,13 @@ hash_rocket_delta(first_pair, current_separator) - key_delta end end def any_pairs_on_the_same_line?(node) - lines_of_the_children = node.children.map do |pair| - key, _value = *pair - key.loc.line + node.children[1..-1].any? do |pair| + !Util.begins_its_line?(pair.loc.expression) end - lines_of_the_children.uniq.size < lines_of_the_children.size end def all_have_same_separator?(node) first_separator = node.children.first.loc.operator.source node.children[1..-1].all? do |pair| @@ -101,11 +99,11 @@ first_pair.loc.column + @max_key_width + 1 - current_separator.column end def value_delta(first_pair, current_pair) - first_key, _ = *first_pair + first_key, = *first_pair _, current_value = *current_pair correct_value_column = first_key.loc.column + spaced_separator(current_pair).length + @max_key_width correct_value_column - current_value.loc.column @@ -178,13 +176,12 @@ first_pair = node.children.first @column_deltas = alignment_for(first_pair) .deltas_for_first_pair(first_pair, node) add_offense(first_pair, :expression) unless good_alignment? - node.children.each_cons(2) do |prev, current| - @column_deltas = alignment_for(current).deltas(first_pair, prev, - current) + node.children.each do |current| + @column_deltas = alignment_for(current).deltas(first_pair, current) add_offense(current, :expression) unless good_alignment? end end def ignore_last_argument_hash?(node) @@ -231,10 +228,10 @@ separator_delta = @column_deltas[:separator] || 0 value_delta = @column_deltas[:value] || 0 key, value = *node - @corrections << lambda do |corrector| + lambda do |corrector| adjust(corrector, key_delta, key.loc.expression) adjust(corrector, separator_delta, node.loc.operator) adjust(corrector, value_delta, value.loc.expression) end end