Boolean literals should be avoided in comparison expressions ==, != to improve code readability. This rule also reports on redundant boolean operations.

Noncompliant Code Example

if (booleanMethod() == true) { /* ... */ }
if (booleanMethod() == false) { /* ... */ }
if (booleanMethod() || false) { /* ... */ }
doSomething(!false);
doSomething(booleanMethod() == true);

booleanVariable = booleanMethod() ? true : false;
booleanVariable = notBooleanMethod() ? true : false;

Compliant Solution

if (booleanMethod()) { /* ... */ }
if (!booleanMethod()) { /* ... */ }
if (booleanMethod()) { /* ... */ }
doSomething(true);
doSomething(booleanMethod());

booleanVariable = booleanMethod();
booleanVariable = Boolean(notBooleanMethod());

Exceptions

Expressions with strict comparison operators (=== and !==) are ignored.