-
Notifications
You must be signed in to change notification settings - Fork 284
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
Add optimize-operands-order rule (#599) #603
Add optimize-operands-order rule (#599) #603
Conversation
ff23a0a
to
851a057
Compare
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.
Thanks for the PR @doniacld, I've made some comments
@chavacava Thanks for the code review. |
I've tested the new rule on revive's code. There are some good warnings:
but also some false positives:
False positives are generated in cases where the right subexpression contains a function call, for example caller(x, y) && (x && caller(y, x)) The conditions in revive/rule/swap-conditional-expr.go Lines 51 to 60 in 5eaf79c
should check if the sub expression tree has a function call (the current check is only on the root of the sub-expression tree) To do that you can use Lines 112 to 116 in 0ee7866
to pick function calls in the sub expression and then check if there is >1 (left) and 0 (right) |
5eaf79c
to
b1ace60
Compare
I've tested the rule over some open source repositories and it looks great! |
ed3f8bd
to
0b66738
Compare
Description
Add swap conditional expression rule that closes #599.
Test
Add a unit test with several cases that should be spotted and other not.
Tested on a repository, here is the output:
Closes #599