Skip to content

unicorn/no-negated-condition Pedantic

🚧 An auto-fix is still under development.

What it does

Disallow negated conditions.

Why is this bad?

Negated conditions are more difficult to understand. Code can be made more readable by inverting the condition.

Example

Examples of incorrect code for this rule:

javascript
if (!a) {
  doSomethingC();
} else {
  doSomethingB();
}

!a ? doSomethingC() : doSomethingB();

Examples of correct code for this rule:

javascript
if (a) {
  doSomethingB();
} else {
  doSomethingC();
}

a ? doSomethingB() : doSomethingC();

References

Released under the MIT License.