Skip to content

noNegationInEqualityCheck

biome.json
{
"linter": {
"rules": {
"nursery": {
"noNegationInEqualityCheck": "error"
}
}
}
}

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.

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)) {}