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
Rework Lint/RedundantSafeNavigation
to be more safe
#8884
Rework Lint/RedundantSafeNavigation
to be more safe
#8884
Conversation
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.
Good work.
I would remove nil?
from the allowlist, since foo&.nil?
is trivially falsey but foo.nil?
isn't.
Unlikely, but nil.methods - Object.new.methods #=> [:to_h, :&, :to_c, :to_f, :to_i, :to_a, :to_r, :rationalize, :|, :^]
, so foo&.respond_to?(any_of_these)
shouldn't be flagged. Because of this, probably best to mark the autocorrect as unsafe (foo&.respond_to?(variable)
can't be autocorrected safely).
b017f09
to
4fc4956
Compare
Good points 👍 Removed |
Great. Would it be difficult to exclude |
4fc4956
to
d03a9c2
Compare
Updated with suggestion. |
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.
Almost ready
d03a9c2
to
8889b09
Compare
@marcandre Thank you for all reviews 💪 |
8889b09
to
6717823
Compare
Updated with suggestions. Let me know if there is anything else I can improve. |
Thanks! |
Closes #8867
Closes #8868
I reworked this to make an offense only when used inside conditions and only for whitelisted methods.
cc @bbatsov @marcandre @natematykiewicz