A conditional expression picks between true and false
What it finds
c ? true : false is a long way to write !!c, and c ? false : true one to write !c: a conditional expression tests the truth of its condition the same way ! does. When the condition is already a boolean, such as a comparison, it can stand alone.
The fix is safe in every case: it writes the condition alone when it is a comparison, instanceof, in or a negation, and otherwise converts it with !! or !.
From the rule's source, boolean_ternary.rs.
function flags(a: number, b: unknown) { const x = a > 1 ? true : false;tx0 reports: gives the truth of its condition const y = b ? false : true;tx0 reports: gives the negated truth of its condition const z = b ? true : true; return [x, y, z];} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:boolean-ternary" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:boolean-ternary] reason="..."tx0 explain tx0/ts:boolean-ternary shows the same in the terminal. Found a false positive? Report it.