Closed
Description
Performance/ReverseEach
only catches offenses if the receiver of reverse.each
is an array literal. If the receiver is a variable or a method call, it does not match the node and does not register an offense.
I would be happy to contribute a PR to fix this, but I'm not sure how to detect what receivers this should apply to. If it's okay to apply this cop to any receiver, I have a fix ready to go, but I'm not sure how to detect that the receiver is an Enumerable (if that's even possible).
Expected behavior
Neither of these examples are picked up by the cop:
arr = [1, 2, 3]
arr.reverse.each
def arr
[1, 2, 3]
end
arr.reverse.each
Actual behavior
Neither of the above examples register offenses.
Steps to reproduce the problem
Both of the above examples reproduce the problem.
RuboCop version
$ rubocop -V
0.55.0 (using Parser 2.5.1.0, running on ruby 2.4.3 x86_64-darwin16)
Metadata
Metadata
Assignees
Labels
No labels