-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Replace NOT operator with explicit false
check
#67817
Replace NOT operator with explicit false
check
#67817
Conversation
We have an in-house rule to compare explicitly against `false` instead of using the logical not operator (`!`). However, this hasn't historically been enforced, meaning that there are many violations in the source at present. We now have a Checkstyle rule that can detect these cases, but before we can turn it on, we need to fix the existing violations. This is being done over a series of PRs, since there are a lot to fix.
Pinging @elastic/es-delivery (Team:Delivery) |
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.
LGTM, some of the expressions are not super obvious, but they were not obvious before either (the once with double negations or alternatives)
@@ -128,7 +128,7 @@ public static boolean parseBooleanLenient(String value, boolean defaultValue) { | |||
if (value == null) { | |||
return defaultValue; | |||
} | |||
return !(value.equals("false") || value.equals("0") || value.equals("off") || value.equals("no")); | |||
return (value.equals("false") || value.equals("0") || value.equals("off") || value.equals("no")) == false; |
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.
this probably requires a little bit head scratching. Would it be easier to read if it was series of && and each being == false? Also not sure this needs to be addressed here.
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.
I refactored it to a switch
.
@elasticmachine run elasticsearch-ci/bwc |
We have an in-house rule to compare explicitly against `false` instead of using the logical not operator (`!`). However, this hasn't historically been enforced, meaning that there are many violations in the source at present. We now have a Checkstyle rule that can detect these cases, but before we can turn it on, we need to fix the existing violations. This is being done over a series of PRs, since there are a lot to fix.
Backported to |
We have an in-house rule to compare explicitly against
false
insteadof using the logical not operator (
!
). However, this hasn'thistorically been enforced, meaning that there are many violations in
the source at present.
We now have a Checkstyle rule that can detect these cases, but before we
can turn it on, we need to fix the existing violations. This is being
done over a series of PRs, since there are a lot to fix.