Skip to content

Commit

Permalink
[Fix #9954] Fix an infinite loop error for Layout/HashAlignment
Browse files Browse the repository at this point in the history
Fixes #9954.

This PR fixes an infinite loop error for `Layout/HashAlignment` when
`EnforcedStyle: with_fixed_indentation` is specified for `Layout/ArgumentAlignment`.
  • Loading branch information
koic authored and bbatsov committed Aug 3, 2021
1 parent c3e717f commit 06d0eba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
@@ -0,0 +1 @@
* [#9954](https://github.com/rubocop/rubocop/issues/9954): Fix infinite loop error for `Layout/HashAlignment` when `EnforcedStyle: with_fixed_indentation` is specified for `Layout/ArgumentAlignment`. ([@koic][])
10 changes: 7 additions & 3 deletions lib/rubocop/cop/layout/hash_alignment.rb
Expand Up @@ -218,9 +218,13 @@ def on_hash(node)
private

def autocorrect_incompatible_with_other_cops?(node)
enforce_first_argument_with_fixed_indentation? &&
node.pairs.any? &&
node.parent&.call_type? && node.parent.loc.selector&.line == node.pairs.first.loc.line
return false unless enforce_first_argument_with_fixed_indentation? &&
node.pairs.any? &&
node.parent&.call_type?

parent_loc = node.parent.loc
selector = parent_loc.selector || parent_loc.expression
selector.line == node.pairs.first.loc.line
end

def reset!
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cli/autocorrect_spec.rb
Expand Up @@ -1875,6 +1875,9 @@ def do_even_more_stuff
foo
.do_something(foo: bar,
baz: qux)
do_something.(foo: bar, baz: qux,
quux: corge)
RUBY

create_file('.rubocop.yml', <<~YAML)
Expand All @@ -1898,6 +1901,9 @@ def do_even_more_stuff
foo
.do_something(foo: bar,
baz: qux)
do_something.(foo: bar, baz: qux,
quux: corge)
RUBY
end

Expand Down

0 comments on commit 06d0eba

Please sign in to comment.