-
-
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
False positive Lint/SafeNavigationConsistency on .nil? check #5840
Comments
2018年4月30日(月) 21:13 Konstantin Mikhnievych <[email protected]>:
… Expected behavior
Lint/SafeNavigationConsistency should at least not autocorrect .nil?
calls.
Actual behavior
Lint/SafeNavigationConsistency replaces .nil? call with safe navigation
like &.nil?
Steps to reproduce the problem
say you have a sample code like this:
class Foo
def bar
return true if a.nil? || a&.whatever?
end
end
you get a warning:
app/test.rb:5:20: W: Lint/SafeNavigationConsistency: Ensure that safe
navigation is used consistently inside of && and ||. return true if a.nil?
|| a&.whatever?
if you run rubocop with autocorrect, the code is replaced with:
return true if a&.nil? || a&.whatever?
in that case the code is broken, as if a == nil, the code returns nil
instead of true.
RuboCop version
$ rubocop -V
0.55.0 (using Parser 2.5.1.0, running on ruby 2.5.1 x86_64-linux)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#5840>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHpqZrVuMVGEv_E3RBRu5oprzauSRgw5ks5ttv_xgaJpZM4TsfmL>
.
|
@michniewicz thanks for the bug report. This is a bug. Like the other safe navigation cops, I probably need to ignore methods that |
rrosenblum
added a commit
to rrosenblum/rubocop
that referenced
this issue
May 2, 2018
bbatsov
pushed a commit
that referenced
this issue
May 5, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected behavior
Lint/SafeNavigationConsistency
should at least not autocorrect.nil?
calls.Actual behavior
Lint/SafeNavigationConsistency
replaces.nil?
call with safe navigation like&.nil?
Steps to reproduce the problem
say you have a sample code like this:
you get a warning:
app/test.rb:5:20: W: Lint/SafeNavigationConsistency: Ensure that safe navigation is used consistently inside of && and ||. return true if a.nil? || a&.whatever?
if you run rubocop with autocorrect, the code is replaced with:
in that case the code is broken, as if a == nil, the code returns
nil
instead oftrue
.RuboCop version
The text was updated successfully, but these errors were encountered: