Skip to content

Commit

Permalink
Merge pull request #11162 from koic/fix_a_false_positive_for_style_ha…
Browse files Browse the repository at this point in the history
…sh_as_last_array_item

[Fix #11161] Fix a false positive for `Style/HashAsLastArrayItem`
  • Loading branch information
koic committed Nov 8, 2022
2 parents c94f499 + 3f4bf54 commit cb29d08
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
@@ -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
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
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

0 comments on commit cb29d08

Please sign in to comment.