Skip to content

Commit

Permalink
Merge pull request #8477 from wcmonty/wm/8475
Browse files Browse the repository at this point in the history
[Fix #8475] Fix a false positive for Style/HashAsLastArrayItem when t…
  • Loading branch information
koic committed Aug 8, 2020
2 parents fad44bf + d08a919 commit 1a4e748
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@
* [#8478](https://github.com/rubocop-hq/rubocop/issues/8478): Relax `Lint/BinaryOperatorWithIdenticalOperands` for mathematical operations. ([@marcandre][])
* [#8480](https://github.com/rubocop-hq/rubocop/issues/8480): Tweak callback list of `Lint/MissingSuper`. ([@marcandre][])
* [#8481](https://github.com/rubocop-hq/rubocop/pull/8481): Fix autocorrect for elements with newlines in `Style/SymbolArray` and `Style/WordArray`. ([@biinari][])
* [#8475](https://github.com/rubocop-hq/rubocop/issues/8475): Fix a false positive for `Style/HashAsLastArrayItem` when there are duplicate hashes in the array. ([@wcmonty][])

### Changes

Expand Down Expand Up @@ -4768,3 +4769,4 @@
[@volfgox]: https://github.com/volfgox
[@dsavochkin]: https://github.com/dmytro-savochkin
[@sonalinavlakhe]: https://github.com/sonalinavlakhe
[@wcmonty]: https://github.com/wcmonty
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/hash_as_last_array_item.rb
Expand Up @@ -40,7 +40,7 @@ def last_array_item?(node)
parent = node.parent
return false unless parent

parent.array_type? && parent.values.last == node
parent.array_type? && parent.children.last.equal?(node)
end

def check_braces(node)
Expand Down
6 changes: 3 additions & 3 deletions spec/rubocop/cop/style/hash_as_last_array_item_spec.rb
Expand Up @@ -39,12 +39,12 @@

it 'registers an offense and corrects when hash with braces' do
expect_offense(<<~RUBY)
[{ one: 1 }, 2, { three: 3 }]
^^^^^^^^^^^^ Omit the braces around the hash.
[{ one: 1 }, { three: 3 }, 2, { three: 3 }]
^^^^^^^^^^^^ Omit the braces around the hash.
RUBY

expect_correction(<<~RUBY)
[{ one: 1 }, 2, three: 3 ]
[{ one: 1 }, { three: 3 }, 2, three: 3 ]
RUBY
end

Expand Down

0 comments on commit 1a4e748

Please sign in to comment.