A switch handles only listed cases and none for other values
What it finds
A switch without a default clause silently does nothing for a value none of its cases expects, and a reader cannot tell whether that was intended. A default that throws or says why nothing is done makes the choice visible.
TypeScript can check that a switch over a union covers every member, which this rule cannot see, so it is a strict rule.
From the rule's source, switch_without_default.rs.
function name(n: number) { switch (n) {tx0 reports: this switch has no default clause case 1: return "one"; } switch (n) { case 2: return "two"; default: return "other"; }} 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-without-default" = "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-without-default] reason="..."tx0 explain tx0/ts:switch-without-default shows the same in the terminal. Found a false positive? Report it.