avoid-inverted-boolean-checks
Warns when a condition has an inverted check.
Inverted checks are harder to spot because of the single !
symbol, which completely inverts the condition. Removing inverted conditions helps other developers understand the code faster.
Example
❌ Bad:
// LINT: Avoid inverted boolean checks. Try rewriting this expression.
if (!(x == 1)) {}
// LINT: Avoid inverted boolean checks. Try rewriting this expression.
if (!(x != 1)) {}
// LINT: Avoid inverted boolean checks. Try rewriting this expression.
var b = !(x != 1) ? 1 : 2;
// LINT: Avoid inverted boolean checks. Try rewriting this expression.
if (!(a > 4 && b < 2)) {}
✅ Good:
if (x != 1) {} // Correct, == is replaced with !=
if (x == 1) {}
var b = x == 1 ? 1 : 2;
if (a <= 4 || b >= 2) {}