Skip to content

equalityOperatorNegations

Reports negated expressions on the left side of equality checks.

✅ This rule is included in the ts preset.

Using a negated expression as the left operand of an equality check is almost always a mistake. The logical not operator (!) has higher precedence than equality operators, so !a === b is evaluated as (!a) === b, not !(a === b). This converts the left operand to a boolean before comparing, which is rarely the intended behavior.

if (!value === true) {
doSomething();
}
if (!count === 0) {
handleEmpty();
}

This rule is not configurable.

If you intentionally compare a negated boolean value with an equality operator, you may want to disable this rule. However, such code would be clearer if rewritten to use the opposite equality operator without the negation.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.