A conditional expression is an operand of another

tx0/ts:nested-conditional-expressionstrictwarningstyle

What it finds

a ? b : c ? d : e packs a whole decision tree into one expression, and the reader has to work out which : belongs to which ?. An if chain, a switch or a lookup table spells the cases out.

A conditional expression is reported when it is the condition or an outcome of another one, also inside parentheses. One nested inside a function, an array, an object or a call argument within the outer one is a separate expression and is left alone.

From the rule's source, nested_conditional_expression.rs.

Example from the rule's tests
function size(n: number) {  const label = n > 100 ? "big" : n > 10 ? "medium" : "small";tx0 reports: nested in another  const plain = n > 1 ? "many" : "one";  const inArray = n > 1 ? [n > 2 ? 1 : 2] : [];  return label + plain + inArray;}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/ts:nested-conditional-expression" = "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:nested-conditional-expression] reason="..."

tx0 explain tx0/ts:nested-conditional-expression shows the same in the terminal. Found a false positive? Report it.