Skip to content

Commit

Permalink
Fix an incorrect auto-correct for Layout/HashAlignment
Browse files Browse the repository at this point in the history
Fixes standardrb/standard#306.

This PR fixes an incorrect auto-correct for `Layout/HashAlignment` when setting
`EnforcedStyle: with_fixed_indentation` of `Layout/ArgumentAlignment` and using
misaligned keyword arguments.
  • Loading branch information
koic authored and bbatsov committed Jun 30, 2021
1 parent 02b1b14 commit 1ca14c9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
@@ -0,0 +1 @@
* [#9897](https://github.com/rubocop/rubocop/pull/9897): Fix an incorrect auto-correct for `Layout/HashAlignment` when setting `EnforcedStyle: with_fixed_indentation` of `Layout/ArgumentAlignment` and using misaligned keyword arguments. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/layout/hash_alignment.rb
Expand Up @@ -220,7 +220,7 @@ def on_hash(node)
def autocorrect_incompatible_with_other_cops?(node)
enforce_first_argument_with_fixed_indentation? &&
node.pairs.any? &&
node.parent&.call_type? && node.parent.loc.line == node.pairs.first.loc.line
node.parent&.call_type? && node.parent.loc.selector.line == node.pairs.first.loc.line
end

def reset!
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cli/autocorrect_spec.rb
Expand Up @@ -1849,6 +1849,10 @@ def do_even_more_stuff
self&.update(foo: bar,
baz: boo,
pony: party)
foo
.do_something(foo: bar,
baz: qux)
RUBY

create_file('.rubocop.yml', <<~YAML)
Expand All @@ -1868,6 +1872,10 @@ def do_even_more_stuff
self&.update(foo: bar,
baz: boo,
pony: party)
foo
.do_something(foo: bar,
baz: qux)
RUBY
end

Expand Down

0 comments on commit 1ca14c9

Please sign in to comment.