no-negated-condition
March 27, 2026 ยท View on GitHub
๐ Disallow negated conditions.
๐ผ This rule is enabled in the following configs: โ
recommended, โ๏ธ unopinionated.
๐ง This rule is automatically fixable by the --fix CLI option.
Negated conditions are more difficult to understand. Code can be made more readable by inverting the condition.
This is an improved version of the no-negated-condition ESLint rule that makes it automatically fixable. ESLint did not want to make it fixable.
Examples
// โ
if (!a) {
doSomethingC();
} else {
doSomethingB();
}
// โ
if (a) {
doSomethingB();
} else {
doSomethingC();
}
// โ
if (a !== b) {
doSomethingC();
} else {
doSomethingB();
}
// โ
if (a === b) {
doSomethingB();
} else {
doSomethingC();
}
// โ
!a ? c : b
// โ
a ? b : c
// โ
if (a != b) {
doSomethingC();
} else {
doSomethingB();
}
// โ
if (a == b) {
doSomethingB();
} else {
doSomethingC();
}
// โ
if (!a) {
doSomething();
}
// โ
if (!a) {
doSomething();
} else if (b) {
doSomethingElse();
}
// โ
if (a != b) {
doSomething();
}