Skip to content
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

Merged
merged 3 commits into from
Jan 26, 2021

Conversation

pugnascotia
Copy link
Contributor

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.

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.
@elasticmachine elasticmachine added the Team:Delivery Meta label for Delivery team label Jan 21, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-delivery (Team:Delivery)

Copy link
Contributor

@pgomulka pgomulka left a 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;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@pugnascotia
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/bwc

@pugnascotia pugnascotia merged commit ad1f876 into elastic:master Jan 26, 2021
@pugnascotia pugnascotia deleted the equality-with-false-part1 branch January 26, 2021 14:47
pugnascotia added a commit that referenced this pull request Jan 27, 2021
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.
@pugnascotia
Copy link
Contributor Author

Backported to 7.x in e8da7e3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Delivery/Build Build or test infrastructure >enhancement Team:Delivery Meta label for Delivery team v7.12.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants