noNegationInEqualityCheck
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/noNegationInEqualityCheck - This rule has an unsafe fix.
- The default severity of this rule is warning.
- Sources:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noNegationInEqualityCheck": "error" } } }}Description
Section titled “Description”Disallow negated expressions on the left side of an equality check.
When a negation operator (!) is used on the left side of an equality check (=== or !==),
the negation binds more tightly than the comparison operator due to operator precedence.
This means !foo === bar is evaluated as (!foo) === bar, which is almost always
unintended. The developer likely meant foo !== bar.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”if (!foo === bar) {}code-block.js:1:5 lint/nursery/noNegationInEqualityCheck FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ A negation is used on the left side of this equality check.
> 1 │ if (!foo === bar) {}
│ ^^^^^^^^^^^^
2 │
ℹ Due to operator precedence, the negation binds more tightly than the equality operator. The expression !foo === bar evaluates as (!foo) === bar, not !(foo === bar).
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Use the proper negated comparison operator instead.
1 │ - if·(!foo·===·bar)·{}
1 │ + if·(foo·!==·bar)·{}
2 2 │
if (!foo !== bar) {}code-block.js:1:5 lint/nursery/noNegationInEqualityCheck FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ A negation is used on the left side of this equality check.
> 1 │ if (!foo !== bar) {}
│ ^^^^^^^^^^^^
2 │
ℹ Due to operator precedence, the negation binds more tightly than the equality operator. The expression !foo === bar evaluates as (!foo) === bar, not !(foo === bar).
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Use the proper negated comparison operator instead.
1 │ - if·(!foo·!==·bar)·{}
1 │ + if·(foo·===·bar)·{}
2 2 │
if (foo !== bar) {}if (!(foo === bar)) {}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.