Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an incorrect auto-correct for Layout/HashAlignment #9897

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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