diff --git a/changelog/fix_a_false_positive_for_style_hash_as_last_array_item.md b/changelog/fix_a_false_positive_for_style_hash_as_last_array_item.md new file mode 100644 index 00000000000..32cbc4fb9ce --- /dev/null +++ b/changelog/fix_a_false_positive_for_style_hash_as_last_array_item.md @@ -0,0 +1 @@ +* [#11161](https://github.com/rubocop/rubocop/issues/11161): Fix a false positive for `Style/HashAsLastArrayItem` when using double splat operator. ([@koic][]) diff --git a/lib/rubocop/cop/style/hash_as_last_array_item.rb b/lib/rubocop/cop/style/hash_as_last_array_item.rb index 985254a8d83..d6eed3a1af6 100644 --- a/lib/rubocop/cop/style/hash_as_last_array_item.rb +++ b/lib/rubocop/cop/style/hash_as_last_array_item.rb @@ -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) diff --git a/spec/rubocop/cop/style/hash_as_last_array_item_spec.rb b/spec/rubocop/cop/style/hash_as_last_array_item_spec.rb index 50518a661b1..e370040d11b 100644 --- a/spec/rubocop/cop/style/hash_as_last_array_item_spec.rb +++ b/spec/rubocop/cop/style/hash_as_last_array_item_spec.rb @@ -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