-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 #13766] Fix false positives for Style/InverseMethods
#13927
[Fix #13766] Fix false positives for Style/InverseMethods
#13927
Conversation
e3fd2c3
to
fd4f559
Compare
def incompatible_method?(node) | ||
return false if node.send_type? | ||
|
||
INCOMPATIBLE_INVERSE_METHODS.include?(node.method_name) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are only incompatible with safe navigation, correct? I think it'd make sense to make the method name more descriptive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finding a better name is difficult 😅 but incompatible_context?
has been chosen.
026b4dc
to
63c778b
Compare
@koic You should probably add a note in the docs about this case, so it's obvious we have special handling for it. |
@@ -46,6 +46,7 @@ class InverseMethods < Base | |||
|
|||
MSG = 'Use `%<inverse>s` instead of inverting `%<method>s`.' | |||
CLASS_COMPARISON_METHODS = %i[<= >= < >].freeze | |||
INCOMPATIBLE_INVERSE_METHODS = %i[any? none?].freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably add a comment here mentioning they are incompatible only in the context of safe navigation.
This PR fixes false positives for `Style/InverseMethods` when using `any?` or `none?` with safe navigation operator. Additionally, some specs for the existing incorrect behavior has been updated. Fixes rubocop#13766.
63c778b
to
eff6547
Compare
I adjusted the naming and logic based on the background of safe navigation instead of adding comments. I hope the naming appropriately reflects the background, considering the amount of code changes. If there is still any lack of clarity, I will add comments, so please let me know. |
I think that's enough for now. |
This PR fixes false positives for
Style/InverseMethods
when usingany?
ornone?
with safe navigation operator.Additionally, some specs for the existing incorrect behavior has been updated.
Fixes #13766.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.