Skip to main content

no-boolean-literal-compare

added in: 1.5.0
style
🛠

Warns on comparison to a boolean literal, as in x == true. Comparing boolean values to boolean literals is unnecessary, as those expressions will result in booleans too. Just use the boolean values directly or negate them.

Example

❌ Bad:

  var b = x == true; // LINT
var c = x != true; // LINT

// LINT
if (x == true) {
...
}

// LINT
if (x != false) {
...
}

✅ Good:

  var b = x;
var c = !x;

if (x) {
...
}

if (!x) {
...
}