diff --git a/changelog/fix_an_incorrect_autocorrect_for_style_redundant_double_splat_hash_braces.md b/changelog/fix_an_incorrect_autocorrect_for_style_redundant_double_splat_hash_braces.md new file mode 100644 index 000000000000..2db511d80b17 --- /dev/null +++ b/changelog/fix_an_incorrect_autocorrect_for_style_redundant_double_splat_hash_braces.md @@ -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][]) diff --git a/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb b/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb index c7fe17ceba7d..193b1aaa53aa 100644 --- a/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +++ b/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb @@ -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 diff --git a/spec/rubocop/cop/style/redundant_double_splat_hash_braces_spec.rb b/spec/rubocop/cop/style/redundant_double_splat_hash_braces_spec.rb index 66023992baa7..364ea6783bfa 100644 --- a/spec/rubocop/cop/style/redundant_double_splat_hash_braces_spec.rb +++ b/spec/rubocop/cop/style/redundant_double_splat_hash_braces_spec.rb @@ -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)