-
-
Notifications
You must be signed in to change notification settings - Fork 263
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 an error for Rails/NegateInclude
when there is no receiver
#920
Conversation
private | ||
|
||
def within_exclude_method?(node) | ||
def_node = node.each_ancestor(:def, :defs).first |
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.
Can you add a test for :defs
?
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.
Added.
9414529
to
994f368
Compare
def self.foo | ||
!include?(2) | ||
^^^^^^^^^^^^ Use `.exclude?` and remove the negation part. | ||
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.
That's what I noticed after reconsidering. It looks better to allow if there is no receiver because there may be user-defined include?
, which may not have exclude?
.
And can you separate the tests for def
and defs
?
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.
Updated to not raise an offense when there is no receiver. Now this PR is tiny 👍.
And that was actually an overkill from my side to detect cases like !include?
inside def exclude?
.
994f368
to
55381fd
Compare
55381fd
to
ca1c242
Compare
Great! Thank you! |
This PR fixes an error when there is no receiver. And handles the case when it is used within
exclude?
method (because correcting would cause infinite recursion).Example from rails: https://github.com/rails/rails/blob/d75fdd1c2f6002d62e5ecf65dda2942065f071f0/activesupport/lib/active_support/core_ext/string/exclude.rb#L10-L12