Transforms the negation of a disjunction into the equivalent conjunction of negations according to De Morgan’s second law.
This rule enforces that when a disjunction is negated, the expression is rewritten according to De Morgan’s law. Instead of writing a negated disjunction like:
if (!(a || b)) {
/* ... */
}
The rule suggests (and can auto-fix) the equivalent form:
if (!a && !b) {
/* ... */
}
Negated disjunctions can sometimes be less clear or counterintuitive. Transforming them into a conjunction of negations makes the logic explicit:
- It clearly indicates that both conditions must be false.
- It may help avoid mistakes in complex boolean logic by making the individual conditions more explicit.
- The rule applies only when the operand of the negation is a pure disjunction — 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-conjunction — A similar rule for transforming the negation of a conjunction
(!(A && B))
into the equivalent disjunction of negations(!A || !B)
, based on De Morgan’s first law.