Skip to content

Commit

Permalink
Fix a false negative for Performance/ReverseEach when safe navigati…
Browse files Browse the repository at this point in the history
…on is between `reverse` and `each`
  • Loading branch information
fatkodima committed Nov 25, 2023
1 parent 4a4fb1d commit 1f9237a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/fix_false_negative_for_reverse_each.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#390](https://github.com/rubocop/rubocop-performance/issues/390): Fix a false negative for `Performance/ReverseEach` when safe navigation is between `reverse` and `each`. ([@fatkodima][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/performance/reverse_each.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ReverseEach < Base
RESTRICT_ON_SEND = %i[each].freeze

def_node_matcher :reverse_each?, <<~MATCHER
(send (call _ :reverse) :each)
({send csend} (call _ :reverse) :each)
MATCHER

def on_send(node)
Expand Down
2 changes: 2 additions & 0 deletions spec/rubocop/cop/performance/reverse_each_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
expect_offense(<<~RUBY)
array&.reverse.each { |e| puts e }
^^^^^^^^^^^^ Use `reverse_each` instead of `reverse.each`.
array&.reverse&.each { |e| puts e }
^^^^^^^^^^^^^ Use `reverse_each` instead of `reverse.each`.
RUBY
end

Expand Down

0 comments on commit 1f9237a

Please sign in to comment.