Why is this an issue?
Comparing a boolean literal to a variable or expression that evaluates to a boolean value is unnecessary and can make the code harder to read and
understand. Therefore, boolean literals should be avoided in equality comparison expressions (==
, ===
, !=
, and
!==
) to improve code readability and reduce unnecessary clutter.
This rule also reports on redundant boolean operations.
if (someValue === true) { /* ... */ } // Noncompliant: Redundant comparison
if (someBooleanValue !== true) { /* ... */ } // Noncompliant: Redundant comparison
if (booleanMethod() || false) { /* ... */ } // Noncompliant: Redundant OR
doSomething(!false); // Noncompliant: Redundant negation
Remove redundant boolean literals to improve readability.
if (someValue) { /* ... */ }
if (!someBooleanValue) { /* ... */ }
if (booleanMethod()) { /* ... */ }
doSomething(true);
Resources
Documentation