Skip to main content

js/noNegationElse

MISSING DOCUMENTATION

ESLint Equivalent: no-negated-condition

Examples

Invalid

if (!true) {consequent;} else {alternate;}

 file.ts:1 lint/js/noNegationElse  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Invert blocks when performing a negation test.

    if (!true) {consequent;} else {alternate;}
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  Safe fix

    1  - if·(!true)·{
    2  - consequent;
      1+ if·(true)·{
      2+ alternate;
    3 3  }·else·{
    4  - alternate;
      4+ consequent;
    5 5  }


!true ? consequent : alternate

 file.ts:1 lint/js/noNegationElse  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Invert blocks when performing a negation test.

    !true ? consequent : alternate
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  Safe fix

  - !true·?·consequent·:·alternate
  + true·?·alternate·:·consequent

Valid

if (!true) {consequent;}
true ? consequent : alternate