Skip to content

Commit

Permalink
Fix an error for Style/RedundantDoubleSplatHashBraces
Browse files Browse the repository at this point in the history
Fixes #12275 (comment).

This PR fixes an error for `Style/RedundantDoubleSplatHashBraces`
when method call for parenthesized no hash double double splat.
  • Loading branch information
koic committed Oct 31, 2023
1 parent f981a1a commit 930755c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12326](https://github.com/rubocop/rubocop/pull/12326): Fix an error for `Style/RedundantDoubleSplatHashBraces` when method call for parenthesized no hash double double splat. ([@koic][])
6 changes: 3 additions & 3 deletions lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ class RedundantDoubleSplatHashBraces < Base
MSG = 'Remove the redundant double splat and braces, use keyword arguments directly.'
MERGE_METHODS = %i[merge merge!].freeze

# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def on_hash(node)
return if node.pairs.empty? || node.pairs.any?(&:hash_rocket?)
return unless (parent = node.parent)
return unless parent.call_type? || parent.kwsplat_type?
return unless mergeable?(parent)
return unless (kwsplat = node.each_ancestor(:kwsplat).first)
return if allowed_double_splat_receiver?(kwsplat)
return if !node.braces? || allowed_double_splat_receiver?(kwsplat)

add_offense(kwsplat) do |corrector|
autocorrect(corrector, node, kwsplat)
end
end
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

private

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@
RUBY
end

it 'does not register an offense when method call for parenthesized no hash double double splat' do
expect_no_offenses(<<~RUBY)
do_something(**(options.merge(foo: bar)))
RUBY
end

it 'does not register an offense when using empty double splat hash braces arguments' do
expect_no_offenses(<<~RUBY)
do_something(**{})
Expand Down

0 comments on commit 930755c

Please sign in to comment.