--- source: crates/biome_js_analyze/tests/spec_tests.rs expression: invalid.js --- # Input ```jsx // Comment if (!true) { // a consequent; } else { // b alternate; } !condition ? consequent : alternate; let a = !test ? c : d; if (!true) { consequent; } else something(); if (!true) something(); else { alternate } !-a ? b : c /*1*/!/*2*/cond/*3*/ ? /*a*/ b /*c*/ : /*d*/ e /*f*/ ``` # Diagnostics ``` invalid.js:2:1 lint/style/noNegationElse FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Invert blocks when performing a negation test. 1 │ // Comment > 2 │ if (!true) { // a │ ^^^^^^^^^^^^^^^^^ > 3 │ consequent; > 4 │ } else { // b > 5 │ alternate; > 6 │ } │ ^ 7 │ 8 │ !condition ? consequent : alternate; i Safe fix: Invert the condition and the blocks. 1 1 │ // Comment 2 │ - if·(!true)·{·//·a 3 │ - → consequent; 4 │ - }·else·{·//·b 5 │ - → alternate; 2 │ + if·(true)·{·//·b 3 │ + → alternate; 4 │ + }·else·{·//·a 5 │ + → consequent; 6 6 │ } 7 7 │ ``` ``` invalid.js:8:1 lint/style/noNegationElse FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Invert blocks when performing a negation test. 6 │ } 7 │ > 8 │ !condition ? consequent : alternate; │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 9 │ 10 │ let a = !test ? c : d; i Safe fix: Invert the condition and the blocks. 6 6 │ } 7 7 │ 8 │ - !condition·?·consequent·:·alternate; 8 │ + condition·?·alternate·:·consequent; 9 9 │ 10 10 │ let a = !test ? c : d; ``` ``` invalid.js:10:9 lint/style/noNegationElse FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Invert blocks when performing a negation test. 8 │ !condition ? consequent : alternate; 9 │ > 10 │ let a = !test ? c : d; │ ^^^^^^^^^^^^^ 11 │ 12 │ if (!true) { i Safe fix: Invert the condition and the blocks. 8 8 │ !condition ? consequent : alternate; 9 9 │ 10 │ - let·a·=·!test·?·c·:·d; 10 │ + let·a·=·test·?·d·:·c; 11 11 │ 12 12 │ if (!true) { ``` ``` invalid.js:12:1 lint/style/noNegationElse FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Invert blocks when performing a negation test. 10 │ let a = !test ? c : d; 11 │ > 12 │ if (!true) { │ ^^^^^^^^^^^^ > 13 │ consequent; > 14 │ } else something(); │ ^^^^^^^^^^^^^^^^^^^ 15 │ 16 │ if (!true) something(); else { i Safe fix: Invert the condition and the blocks. 10 10 │ let a = !test ? c : d; 11 11 │ 12 │ - if·(!true)·{ 12 │ + if·(true)·something();·else·{ 13 13 │ consequent; 14 │ - }·else·something(); 14 │ + } 15 15 │ 16 16 │ if (!true) something(); else { ``` ``` invalid.js:16:1 lint/style/noNegationElse FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Invert blocks when performing a negation test. 14 │ } else something(); 15 │ > 16 │ if (!true) something(); else { │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > 17 │ alternate > 18 │ } │ ^ 19 │ 20 │ !-a ? b : c i Safe fix: Invert the condition and the blocks. 14 14 │ } else something(); 15 15 │ 16 │ - if·(!true)·something();·else·{ 16 │ + if·(true)·{ 17 17 │ alternate 18 │ - } 18 │ + }·else·something(); 19 19 │ 20 20 │ !-a ? b : c ``` ``` invalid.js:20:1 lint/style/noNegationElse FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Invert blocks when performing a negation test. 18 │ } 19 │ > 20 │ !-a ? b : c │ ^^^^^^^^^^^ 21 │ 22 │ /*1*/!/*2*/cond/*3*/ ? /*a*/ b /*c*/ : /*d*/ e /*f*/ i Safe fix: Invert the condition and the blocks. 18 18 │ } 19 19 │ 20 │ - !-a·?·b·:·c 20 │ + -a·?·c·:·b 21 21 │ 22 22 │ /*1*/!/*2*/cond/*3*/ ? /*a*/ b /*c*/ : /*d*/ e /*f*/ ``` ``` invalid.js:22:6 lint/style/noNegationElse FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Invert blocks when performing a negation test. 20 │ !-a ? b : c 21 │ > 22 │ /*1*/!/*2*/cond/*3*/ ? /*a*/ b /*c*/ : /*d*/ e /*f*/ │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 23 │ i Safe fix: Invert the condition and the blocks. 20 20 │ !-a ? b : c 21 21 │ 22 │ - /*1*/!/*2*/cond/*3*/·?·/*a*/·b·/*c*/·:·/*d*/·e·/*f*/ 22 │ + /*1*/cond/*3*/·?·/*a*/·e·/*f*/·:·b·/*f*/ 23 23 │ ```