-
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
Remove comparison to true for booleans #51723
Conversation
While we use `== false` as a more visible form of boolean negation (instead of `!`), the true case is implied and the true value does not need to explicitly checked. This commit converts cases that have slipped into the code checking for `== true`.
Pinging @elastic/es-core-infra (:Core/Infra/Core) |
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.
I did a CheckStyle experiment, and you can forbid such comparisons with this:
<!-- Forbid equality comparisons with `true` -->
<module name="DescendantToken">
<property name="tokens" value="EQUAL"/>
<property name="limitedTokens" value="LITERAL_TRUE"/>
<property name="maximumNumber" value="0"/>
<property name="maximumDepth" value="1"/>
<message key="descendant.token.max" value="Do not check for equality with 'true', since it is implied"/>
</module>
The minor irritation with that is that it doesn't detect all the violations in one go, rather (1) CheckStyle finds some, (2) you fix them, (3) GOTO 1. What do you think? If it's worth creating a PR to remove these, it's probably worth preventing them from being added in the first place.
@pugnascotia If the check isn't too expensive, I do think it would be worthwhile to add. Could we also add the case to not allow |
While we use `== false` as a more visible form of boolean negation (instead of `!`), the true case is implied and the true value does not need to explicitly checked. This commit converts cases that have slipped into the code checking for `== true`.
Add a Checkstyle rule to forbid equality checks against a literal 'true' value, since this is redundant. Follow up to elastic#51723.
Add a Checkstyle rule to forbid equality checks against a literal 'true' value, since this is redundant. Follow up to #51723.
While we use
== false
as a more visible form of boolean negation(instead of
!
), the true case is implied and the true value does notneed to explicitly checked. This commit converts cases that have slipped
into the code checking for
== true
.