Skip to content

Commit

Permalink
[Fix rubocop#8475] Fix a false positive for Style/HashAsLastArrayItem…
Browse files Browse the repository at this point in the history
… when there are duplicate hashes in the array Co-authored-by: Koichi ITO <koic.ito@gmail.com>
  • Loading branch information
William Montgomery committed Aug 7, 2020
1 parent 7552fed commit d08a919
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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][])

## 0.89.0 (2020-08-05)

Expand Down Expand Up @@ -4764,3 +4765,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 d08a919

Please sign in to comment.