Transforms the negation of a conjunction into the equivalent disjunction of negations according to De Morgan’s first law.
This rule enforces that when a conjunction is negated, the expression is rewritten according to De Morgan’s law. Instead of writing a negated conjunction like:
if (!(a && b)) {
/* ... */
}
The rule suggests (and can auto-fix) the equivalent form:
if (!a || !b) {
/* ... */
}
Negated conjunctions can sometimes be harder to read and understand. Transforming them into a disjunction of negations makes the logic explicit:
- It clearly shows that at least one of the conditions must be false.
- It may help avoid mistakes in complex boolean logic.
- The rule applies only when the operand of the negation is a pure conjunction — that is, when all operands are combined with && at the same nesting level.
- If the expression inside the negation contains a mix of logical operators (for example,
!(a && b || c))
, the rule will not apply the transformation.
This rule is auto-fixable. When applied, it automatically rewrites code such as:
const foo = !(a && !b && c >= 10)
To:
const foo = !a || b || c < 10
This rule has no options.
- no-negated-disjunction — A similar rule for transforming the negation of a disjunction
(!(A || B))
into the equivalent conjunction of negations(!A && !B)
, based on De Morgan’s second law.