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.
Examples
Section titled “Examples”if (!value === true) { doSomething();}if (!count === 0) { handleEmpty();}if (value !== true) { doSomething();}if (!(value === true)) { doSomething();}if (count !== 0) { handleEmpty();}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.