--- source: crates/biome_js_analyze/tests/spec_tests.rs expression: invalid.js --- # Input ```jsx var a = x ? true : true; var a = x ? false : false; var a = foo() ? false : true; var a = foo ? false : true; var a = foo === 1 ? false : true; var a = foo + 1 ? false : true; var a = foo() ? true : false; var a = foo ? true : false; var a = foo === 1 ? true : false; var a = foo + 1 ? true : false; var a= !foo? true : false; var a = x instanceof foo ? false : true; var a = x instanceof foo ? true : false; var a = 'make' in car ? true : false; var a = 'make' in car ? false : true; ``` # Diagnostics ``` invalid.js:1:9 lint/nursery/noUselessTernary FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary use of boolean literals in conditional expression. > 1 │ var a = x ? true : true; │ ^^^^^^^^^^^^^^^ 2 │ var a = x ? false : false; 3 │ i Simplify your code by directly assigning the result without using a ternary operator. i If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code. Check for more details about NOT operator. i Unsafe fix: Remove the conditional expression with 1 │ var·a·=·x·?·true·:·true; │ ----------- ``` ``` invalid.js:2:9 lint/nursery/noUselessTernary FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary use of boolean literals in conditional expression. 1 │ var a = x ? true : true; > 2 │ var a = x ? false : false; │ ^^^^^^^^^^^^^^^^^ 3 │ 4 │ var a = foo() ? false : true; i Simplify your code by directly assigning the result without using a ternary operator. i If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code. Check for more details about NOT operator. i Unsafe fix: Remove the conditional expression with 2 │ var·a·=·x·?·false·:·false; │ ------------ ``` ``` invalid.js:4:9 lint/nursery/noUselessTernary FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary use of boolean literals in conditional expression. 2 │ var a = x ? false : false; 3 │ > 4 │ var a = foo() ? false : true; │ ^^^^^^^^^^^^^^^^^^^^ 5 │ var a = foo ? false : true; 6 │ var a = foo === 1 ? false : true; i Simplify your code by directly assigning the result without using a ternary operator. i If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code. Check for more details about NOT operator. i Unsafe fix: Remove the conditional expression with 2 2 │ var a = x ? false : false; 3 3 │ 4 │ - var·a·=·foo()·?·false·:·true; 4 │ + var·a·=·!foo(); 5 5 │ var a = foo ? false : true; 6 6 │ var a = foo === 1 ? false : true; ``` ``` invalid.js:5:9 lint/nursery/noUselessTernary FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary use of boolean literals in conditional expression. 4 │ var a = foo() ? false : true; > 5 │ var a = foo ? false : true; │ ^^^^^^^^^^^^^^^^^^ 6 │ var a = foo === 1 ? false : true; 7 │ var a = foo + 1 ? false : true; i Simplify your code by directly assigning the result without using a ternary operator. i If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code. Check for more details about NOT operator. i Unsafe fix: Remove the conditional expression with 3 3 │ 4 4 │ var a = foo() ? false : true; 5 │ - var·a·=·foo·?·false·:·true; 5 │ + var·a·=·!foo; 6 6 │ var a = foo === 1 ? false : true; 7 7 │ var a = foo + 1 ? false : true; ``` ``` invalid.js:6:9 lint/nursery/noUselessTernary FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary use of boolean literals in conditional expression. 4 │ var a = foo() ? false : true; 5 │ var a = foo ? false : true; > 6 │ var a = foo === 1 ? false : true; │ ^^^^^^^^^^^^^^^^^^^^^^^^ 7 │ var a = foo + 1 ? false : true; 8 │ i Simplify your code by directly assigning the result without using a ternary operator. i If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code. Check for more details about NOT operator. i Unsafe fix: Remove the conditional expression with 4 4 │ var a = foo() ? false : true; 5 5 │ var a = foo ? false : true; 6 │ - var·a·=·foo·===·1·?·false·:·true; 6 │ + var·a·=·foo·!==1; 7 7 │ var a = foo + 1 ? false : true; 8 8 │ ``` ``` invalid.js:7:9 lint/nursery/noUselessTernary FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary use of boolean literals in conditional expression. 5 │ var a = foo ? false : true; 6 │ var a = foo === 1 ? false : true; > 7 │ var a = foo + 1 ? false : true; │ ^^^^^^^^^^^^^^^^^^^^^^ 8 │ 9 │ var a = foo() ? true : false; i Simplify your code by directly assigning the result without using a ternary operator. i If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code. Check for more details about NOT operator. i Unsafe fix: Remove the conditional expression with 5 5 │ var a = foo ? false : true; 6 6 │ var a = foo === 1 ? false : true; 7 │ - var·a·=·foo·+·1·?·false·:·true; 7 │ + var·a·=·!(foo·+·1·); 8 8 │ 9 9 │ var a = foo() ? true : false; ``` ``` invalid.js:9:9 lint/nursery/noUselessTernary FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary use of boolean literals in conditional expression. 7 │ var a = foo + 1 ? false : true; 8 │ > 9 │ var a = foo() ? true : false; │ ^^^^^^^^^^^^^^^^^^^^ 10 │ var a = foo ? true : false; 11 │ var a = foo === 1 ? true : false; i Simplify your code by directly assigning the result without using a ternary operator. i If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code. Check for more details about NOT operator. i Unsafe fix: Remove the conditional expression with 7 7 │ var a = foo + 1 ? false : true; 8 8 │ 9 │ - var·a·=·foo()·?·true·:·false; 9 │ + var·a·=·!!foo(); 10 10 │ var a = foo ? true : false; 11 11 │ var a = foo === 1 ? true : false; ``` ``` invalid.js:10:9 lint/nursery/noUselessTernary FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary use of boolean literals in conditional expression. 9 │ var a = foo() ? true : false; > 10 │ var a = foo ? true : false; │ ^^^^^^^^^^^^^^^^^^ 11 │ var a = foo === 1 ? true : false; 12 │ var a = foo + 1 ? true : false; i Simplify your code by directly assigning the result without using a ternary operator. i If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code. Check for more details about NOT operator. i Unsafe fix: Remove the conditional expression with 8 8 │ 9 9 │ var a = foo() ? true : false; 10 │ - var·a·=·foo·?·true·:·false; 10 │ + var·a·=·!!foo; 11 11 │ var a = foo === 1 ? true : false; 12 12 │ var a = foo + 1 ? true : false; ``` ``` invalid.js:11:9 lint/nursery/noUselessTernary FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary use of boolean literals in conditional expression. 9 │ var a = foo() ? true : false; 10 │ var a = foo ? true : false; > 11 │ var a = foo === 1 ? true : false; │ ^^^^^^^^^^^^^^^^^^^^^^^^ 12 │ var a = foo + 1 ? true : false; 13 │ i Simplify your code by directly assigning the result without using a ternary operator. i If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code. Check for more details about NOT operator. i Unsafe fix: Remove the conditional expression with 9 9 │ var a = foo() ? true : false; 10 10 │ var a = foo ? true : false; 11 │ - var·a·=·foo·===·1·?·true·:·false; 11 │ + var·a·=·foo··===·1; 12 12 │ var a = foo + 1 ? true : false; 13 13 │ ``` ``` invalid.js:12:9 lint/nursery/noUselessTernary FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary use of boolean literals in conditional expression. 10 │ var a = foo ? true : false; 11 │ var a = foo === 1 ? true : false; > 12 │ var a = foo + 1 ? true : false; │ ^^^^^^^^^^^^^^^^^^^^^^ 13 │ 14 │ var a= !foo? true : false; i Simplify your code by directly assigning the result without using a ternary operator. i If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code. Check for more details about NOT operator. i Unsafe fix: Remove the conditional expression with 10 10 │ var a = foo ? true : false; 11 11 │ var a = foo === 1 ? true : false; 12 │ - var·a·=·foo·+·1·?·true·:·false; 12 │ + var·a·=·!!(foo·+·1·); 13 13 │ 14 14 │ var a= !foo? true : false; ``` ``` invalid.js:14:8 lint/nursery/noUselessTernary FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary use of boolean literals in conditional expression. 12 │ var a = foo + 1 ? true : false; 13 │ > 14 │ var a= !foo? true : false; │ ^^^^^^^^^^^^^^^^^^ 15 │ 16 │ var a = x instanceof foo ? false : true; i Simplify your code by directly assigning the result without using a ternary operator. i If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code. Check for more details about NOT operator. i Unsafe fix: Remove the conditional expression with 14 │ var·a=·!foo?·true·:·false; │ -------------- ``` ``` invalid.js:16:9 lint/nursery/noUselessTernary FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary use of boolean literals in conditional expression. 14 │ var a= !foo? true : false; 15 │ > 16 │ var a = x instanceof foo ? false : true; │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17 │ var a = x instanceof foo ? true : false; 18 │ i Simplify your code by directly assigning the result without using a ternary operator. i If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code. Check for more details about NOT operator. i Unsafe fix: Remove the conditional expression with 14 14 │ var a= !foo? true : false; 15 15 │ 16 │ - var·a·=·x·instanceof·foo·?·false·:·true; 16 │ + var·a·=·!(x·instanceof·foo·); 17 17 │ var a = x instanceof foo ? true : false; 18 18 │ ``` ``` invalid.js:17:9 lint/nursery/noUselessTernary FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary use of boolean literals in conditional expression. 16 │ var a = x instanceof foo ? false : true; > 17 │ var a = x instanceof foo ? true : false; │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 18 │ 19 │ var a = 'make' in car ? true : false; i Simplify your code by directly assigning the result without using a ternary operator. i If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code. Check for more details about NOT operator. i Unsafe fix: Remove the conditional expression with 15 15 │ 16 16 │ var a = x instanceof foo ? false : true; 17 │ - var·a·=·x·instanceof·foo·?·true·:·false; 17 │ + var·a·=·x··instanceof·foo; 18 18 │ 19 19 │ var a = 'make' in car ? true : false; ``` ``` invalid.js:19:9 lint/nursery/noUselessTernary FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary use of boolean literals in conditional expression. 17 │ var a = x instanceof foo ? true : false; 18 │ > 19 │ var a = 'make' in car ? true : false; │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20 │ var a = 'make' in car ? false : true; i Simplify your code by directly assigning the result without using a ternary operator. i If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code. Check for more details about NOT operator. i Unsafe fix: Remove the conditional expression with 17 17 │ var a = x instanceof foo ? true : false; 18 18 │ 19 │ - var·a·=·'make'·in·car·?·true·:·false; 19 │ + var·a·=·'make'··in·car; 20 20 │ var a = 'make' in car ? false : true; ``` ``` invalid.js:20:9 lint/nursery/noUselessTernary FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Unnecessary use of boolean literals in conditional expression. 19 │ var a = 'make' in car ? true : false; > 20 │ var a = 'make' in car ? false : true; │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ i Simplify your code by directly assigning the result without using a ternary operator. i If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code. Check for more details about NOT operator. i Unsafe fix: Remove the conditional expression with 18 18 │ 19 19 │ var a = 'make' in car ? true : false; 20 │ - var·a·=·'make'·in·car·?·false·:·true; 20 │ + var·a·=·!('make'·in·car·); ```