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 autocorrect for Style/RedundantDoubleSplatHashBraces #12262

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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12262](https://github.com/rubocop/rubocop/pull/12262): Fix an incorrect autocorrect for `Style/RedundantDoubleSplatHashBraces` when using double splat hash braces with `merge` method call twice. ([@koic][])
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def range_of_merge_methods(merge_methods)
end

def extract_send_methods(kwsplat)
@extract_send_methods ||= kwsplat.each_descendant(:send, :csend)
kwsplat.each_descendant(:send, :csend)
end

def convert_to_new_arguments(node)
Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cop/style/redundant_double_splat_hash_braces_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@
RUBY
end

it 'registers an offense when using double splat hash braces with `merge` method call twice' do
expect_offense(<<~RUBY)
do_something(**{ foo: bar }.merge(options))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Remove the redundant double splat and braces, use keyword arguments directly.
do_something(**{ baz: qux }.merge(options))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Remove the redundant double splat and braces, use keyword arguments directly.
RUBY

expect_correction(<<~RUBY)
do_something(foo: bar, **options)
do_something(baz: qux, **options)
RUBY
end

it 'registers an offense when using double splat hash braces with `merge` multiple arguments method call' do
expect_offense(<<~RUBY)
do_something(**{foo: bar, baz: qux}.merge(options1, options2))
Expand Down