-
-
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
Rule Proposal: Inverse of ConditionalAssignment #2828
Comments
I'm fine with the suggestion. @rrosenblum can you tackle this? |
I can code up this change. It is going to take a while to implement. There are a ton of test cases for this. Also, the code for the cop is going to need to be cleaned up quite a bit. If I remember correctly, this cop is at limit for most of the Metrics cops. |
I have the new configuration for the cop functionally complete. I need to do some refactoring to reduce the complexity. |
I hit a bit of a snag with this. Assignment using a Example: bar = foo? ? 1 : 2
# parses as: bar = foo? ? 1 : 2
s(:ivasgn, :@bar,
s(:if,
s(:send, nil, :foo?),
s(:int, 1),
s(:int, 2)) bar << foo? ? 1 : 2
# parses as: "bar << foo?"
s(:send,
s(:send, nil, :bar), :<<,
s(:send, nil, :foo?))
# node.parent
# "bar << foo? ? 1 : 2"
s(:if,
s(:send,
s(:send, nil, :bar), :<<,
s(:send, nil, :foo?)),
s(:int, 1),
s(:int, 2)) This isn't a problem for registering an offense, but it is a problem for auto-correcting. I have a few ideas on how to account for this. |
I figured out why the ternary operation was not parsing the way that I thought it would. The issue is order of operations. Reading Using parentheses to show it off bar << foo? ? 1 : 2 is actually (bar << foo?) ? 1 : 2 when what I really wanted is bar << (foo? ? 1 : 2) I need to check the auto-correction of ternary operators for the current use case of this cop. We might be introducing bugs with the correction. |
Good catch @rrosenblum and thanks for working on this |
Fixed in #2915. |
We'd like to ban all conditional assignment. Can we get an option to invert this? Basically we want all
to become
The text was updated successfully, but these errors were encountered: