-
-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance/ReverseEach fix is not equivalent #36
Comments
The example that you provided is a bit of an edge case that we can account for in the cop. I find it a bit unusual to chain a method onto We should also check to make sure that |
This may not be desireable. But if there is a noticeable performance upgrade, could you not just tack |
Fixes rubocop#36. This PR fixes a false positive for `Performance/ReverseEach` when `each` is called on `reverse` and using the result value.
…reverse_each [Fix #36] Fix a false positive for `Performance/ReverseEach`
The
ReverseEach
performance cop suggests replacing.reverse.each
with.reverse_each
.Unfortunately
reverse_each
is not a drop-in replacement forreverse.each
as there is a subtle difference between the two:In other words,
reverse_each
runs the block over each element in reverse order, as expected, but then it returns the un-reversed enumerable.Solution
It's a valid performance improvement in most scenarios, but it needs to come with a big warning. I also think that auto-correction should be disabled for this cop because it can break code.
RuboCop version
The text was updated successfully, but these errors were encountered: