A switch is inside a case of another switch
What it finds
A switch inside a case of another switch makes two levels of cases to keep apart, and a break in the inner one is easily taken to leave the outer one. Moving the inner switch into a function of its own keeps each readable.
The inner switch is reported when it is in the same function as the outer one; a switch in a callback inside a case is left alone.
From the rule's source, switch_in_switch.rs.
function route(a: number, b: number) { switch (a) { case 1: switch (b) {tx0 reports: this switch is nested in a case of another case 2: return 3; } break; case 2: return [b].map((x) => { switch (x) { case 1: return 1; } return 0; }); } return 0;} 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:switch-in-switch" = "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:switch-in-switch] reason="..."tx0 explain tx0/ts:switch-in-switch shows the same in the terminal. Found a false positive? Report it.