Skip to main content

no-negated-conditions

Disallow negated conditions.

Targeted pattern scopeโ€‹

This rule reports selected negation patterns in conditions:

  • if (!value)
  • if (value !== other)
  • top-level logical combinations that include those negations (&& / ||)

The selector is intentionally focused and does not rewrite all possible boolean equivalences.

What this rule reportsโ€‹

This rule reports selected negated patterns in conditions and top-level logical expressions, including !foo and foo !== bar forms.

Why this rule existsโ€‹

Negated conditions can increase cognitive load, especially in compound boolean expressions. Positive predicates are usually easier to scan and reason about.

โŒ Incorrectโ€‹

if (!x && y) {
}
if (x !== 1 && y) {
}
const value = !x || y;

โœ… Correctโ€‹

if (x && y) {
}
if (x === 1 && y) {
}
const value = x && y;

Behavior and migration notesโ€‹

This rule reports only and does not provide an autofix.

Migrations typically involve flipping comparisons (!== โ†’ ===) and restructuring condition branches for positive checks.

Optionsโ€‹

This rule has no options.

Additional examplesโ€‹

if (!isReady || hasError) {
return;
}
// โŒ reported

if (isReady && hasNoError) {
start();
}
// โœ… valid when predicates are already positive.

ESLint flat config exampleโ€‹

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-negated-conditions": "error",
},
},
];

When not to use itโ€‹

Disable this rule if your codebase intentionally allows negated condition forms.

Package documentationโ€‹

Rule catalog ID: R033

Further readingโ€‹

Adoption resourcesโ€‹

  • Start at warning level in CI, then move to error after cleanup.
  • Use focused codemods/autofix batches per package or directory.