-
-
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
Style/AndOr suggests replacing "and" with "&&", and doesn't autocorrect, in places where "and" and "&&" have different semantics #2531
Comments
Did you use ...Though even if not autocorrecting, RC could mention precedence in cases where it makes a difference. We have the technology to do that. |
It doesn't autocorrect. Maybe that's the bug?
|
As a side note, the failure to autocorrect got me to actually read up on the |
When I cut-and-paste # encoding: utf-8
def find_value_1(k1, k2)
(h1 = @h[k1]) && h1[k2]
end The second example is corrected to: # encoding: utf-8
(products = product_registry[k]) && products[v.to_s] ...Maybe there is some surrounding context in |
@dmolesUC3 what's your RuboCop version btw? |
I did a little digging. Found that the inspected code must have been and older revision (e.g. Stripping down the code to a minimal example, I found that there's no auto-correction of def x
end
def y
a = b and a.c
end but if I remove the method |
Awesome detective work @jonas054! |
Just pushing a fix to my open PR. It turns out this is my bug. |
@jonas054 Nice work! Thanks. |
Consider the following:
Rubocop suggests “Use && instead of and” for methods like
find_value_1
. (To its credit, it doesn't autocorrect with-a
, though.)I understand that the style guide bans use of
and
for any purpose, but in that case it seems like Rubocop should suggest a different idiom (and/or warn about parentheses / precedence) here, rather than a substitution that will fail.The text was updated successfully, but these errors were encountered: