noNegationElse (since v0.7.0)
Disallow negation in the condition of an if
statement if it has an else
clause
Examples
Invalid
if (!true) {consequent;} else {alternate;}
style/noNegationElse.js:1:1 lint/style/noNegationElse FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Invert blocks when performing a negation test.
> 1 │ if (!true) {consequent;} else {alternate;}
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Suggested fix: Exchange alternate and consequent of the node
1 │ - if·(!true)·{consequent;}·else·{alternate;}
1 │ + if·(true)·{alternate;}·else·{consequent;}
2 2 │
!true ? consequent : alternate
style/noNegationElse.js:1:1 lint/style/noNegationElse FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Invert blocks when performing a negation test.
> 1 │ !true ? consequent : alternate
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Suggested fix: Exchange alternate and consequent of the node
1 │ - !true·?·consequent·:·alternate
1 │ + true·?·alternate·:·consequent
2 2 │
Valid
if (!true) {consequent;}
true ? consequent : alternate