A switch has fewer than three clauses

tx0/ts:tiny-switchstrictwarningstyle

What it finds

A switch with only one or two clauses is an if statement, or an if and else, with more ceremony: the break and the clause labels add nothing.

Each case label counts as a clause, also when several share one body, and so does the default clause.

From the rule's source, tiny_switch.rs.

Example from the rule's tests
function name(n: number) {  switch (n) {tx0 reports: this switch has one clause    case 1:      return "one";  }  switch (n) {tx0 reports: this switch has two clauses    case 1:      return "one";    default:      return "other";  }  switch (n) {    case 1:    case 2:      return "few";    default:      return "many";  }}
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:tiny-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:tiny-switch] reason="..."

tx0 explain tx0/ts:tiny-switch shows the same in the terminal. Found a false positive? Report it.