Skip to content

Commit

Permalink
Fix an incorrect autocorrect for Style/RedundantDoubleSplatHashBraces
Browse files Browse the repository at this point in the history
Fixes standardrb/standard#505.

This PR fixes an incorrect autocorrect for `Style/RedundantDoubleSplatHashBraces`
using double splat in double splat hash braces.
  • Loading branch information
koic committed Jan 5, 2023
1 parent aa19ccd commit 36d8ea7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11392](https://github.com/rubocop/rubocop/pull/11392): Fix an incorrect autocorrect for `Style/RedundantDoubleSplatHashBraces` using double splat in double splat hash braces. ([@koic][])
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def on_hash(node)
return unless double_splat_hash_braces?(grandparent)

add_offense(grandparent) do |corrector|
corrector.replace(grandparent, node.pairs.map(&:source).join(', '))
corrector.replace(grandparent, node.children.map(&:source).join(', '))
end
end
end
Expand Down
11 changes: 11 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 @@ -12,6 +12,17 @@
RUBY
end

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

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

it 'does not register an offense when using keyword arguments' do
expect_no_offenses(<<~RUBY)
do_something(foo: bar, baz: qux)
Expand Down

0 comments on commit 36d8ea7

Please sign in to comment.