-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
Add new Rails/PluckInWhere
cop
#269
Conversation
be310e1
to
65bcce7
Compare
65bcce7
to
28ee6b8
Compare
Updated. |
|
||
def in_where?(node) | ||
send_node = node.each_ancestor(:send).first | ||
WHERE_METHODS.include?(send_node&.method_name) |
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.
Why are safe navigation operator (&.
) used?
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.
pluck
can be not within other send node, so send_node
can be nil.
I rewrote this line without &
to make it a little bit clear.
28ee6b8
to
f0a5fbc
Compare
Updated. |
Thank you! 👍 |
Thank you @fatkodima! Excellent to see and learn from this PR! 🎉 |
Closes #246
This pattern is very common and I have seen its usage a lot of times.
Maybe there are other places where
pluck
can be replaced withselect
, but inwhere
- is the most common one I can think of right now.