-
-
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
Auto-correct for Style/AndOr does not handle precedence change correctly #8053
Labels
Comments
It should be easy to avoid in theory: do the correction without the '(' ')', parse the result and check if the AST is the same or not. If not, add them... |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding! |
Thanks for keeping this alive. |
koic
added a commit
to koic/rubocop
that referenced
this issue
Nov 25, 2020
Fixes rubocop#8053. This PR fixes an incorrect auto-correct for `Style/AndOr` when `or` precedes `and`.
8 tasks
bbatsov
pushed a commit
that referenced
this issue
Nov 25, 2020
Fixes #8053. This PR fixes an incorrect auto-correct for `Style/AndOr` when `or` precedes `and`.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The auto-correct for Style/AndOr incorrectly replaces expressions like:
a or b and c
with
a || b && c
rather than
(a || b) && c
I wasn't able to find an open issue that relates to this issue. If this behavior is unavoidable for some reason, then I recommend not marking Style/AndOr a "safe" auto-correctable cop.
Expected behavior
I expect it to correctly handle the change in precedence between
and
andor
(which have the same precedence and&&
and||
(&&
has higher precedence).Actual behavior
Running
rubocop --safe-auto-correct
on this code:results in:
The original code prints
false
, but the resulting code printstrue
.Steps to reproduce the problem
See above.
RuboCop version
I originally discovered this using 0.75.1 at work and replicated on a local personal project that is running 0.83.0.
The text was updated successfully, but these errors were encountered: