Skip to content
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

Fix a false negative for Performance/ReverseEach when safe navigation is between reverse and each #392

Merged
merged 1 commit into from
Nov 26, 2023

Conversation

fatkodima
Copy link
Contributor

Fixes #390.

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
({send csend} (call _ :reverse) :each)
(call (call _ :reverse) :each)

@koic
Copy link
Member

koic commented Nov 25, 2023

CI has been failed. Can you rebase with the latest master branch?

@fatkodima fatkodima force-pushed the reverse_each-more-safe-navigation branch from 1f9237a to 73b8334 Compare November 25, 2023 18:32
@fatkodima
Copy link
Contributor Author

Updated.

@@ -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`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please separate this, an independent test instead of mixing it in the existing it block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hate inventing new names for tests 😅 Updated

@fatkodima fatkodima force-pushed the reverse_each-more-safe-navigation branch from 73b8334 to 761025b Compare November 26, 2023 10:45
@koic koic merged commit c5bc8f4 into rubocop:master Nov 26, 2023
11 checks passed
@fatkodima fatkodima deleted the reverse_each-more-safe-navigation branch November 26, 2023 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Performance/ReverseEach aware of safe navigation operator
2 participants