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 #11161] Fix a false positive for Style/HashAsLastArrayItem #11162

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 @@
* [#11161](https://github.com/rubocop/rubocop/issues/11161): Fix a false positive for `Style/HashAsLastArrayItem` when using double splat operator. ([@koic][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/style/hash_as_last_array_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class HashAsLastArrayItem < Base
extend AutoCorrector

def on_hash(node)
return if node.children.first&.kwsplat_type?
return unless (array = containing_array(node))
return unless last_array_item?(array, node) && explicit_array?(array)

Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/style/hash_as_last_array_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
[1, {}]
RUBY
end

it 'does not register an offense when using double splat operator' do
expect_no_offenses(<<~RUBY)
[1, **options]
RUBY
end
end

context 'when EnforcedStyle is no_braces' do
Expand Down