--- source: crates/biome_js_analyze/tests/spec_tests.rs expression: invalid_without_trivia.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; ``` # Diagnostics ``` invalid_without_trivia.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; 1 │ + var·a·=·true; 2 2 │ var a = x?false:false; 3 3 │ ``` ``` invalid_without_trivia.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 1 1 │ var a = x?true:true; 2 │ - var·a·=·x?false:false; 2 │ + var·a·=·false; 3 3 │ 4 4 │ var a = foo()?false:true; ``` ``` invalid_without_trivia.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_without_trivia.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_without_trivia.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_without_trivia.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_without_trivia.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_without_trivia.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_without_trivia.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_without_trivia.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_without_trivia.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; │ ^^^^^^^^^^^^^^^ 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; │ ----------- ```