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 error for Style/RedundantDoubleSplatHashBraces #12326

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 @@
* [#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