A switch has no default case for values that no case lists
What it finds
A switch without a default case does nothing for values that no case lists. That may be intended, but a reader cannot tell, and a value added later, such as a new constant of an enumeration, silently falls through. A default, even one with only a comment, says what happens.
Reported are expression and type switches with at least one case and no default. Many switches list only the values they act on by design, so the rule runs only when every rule is enabled.
From the rule's source, switch_without_default.rs.
package p func f(n int, v any) int { switch n {tx0 reports: this switch has no default case case 1: return 1 } switch v.(type) {tx0 reports: this switch has no default case case int: return 2 } switch { case n > 3: return 3 default: return 4 }} Turn it on, off or suppress it
The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/go: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/go:switch-without-default] reason="..."tx0 explain tx0/go:switch-without-default shows the same in the terminal. Found a false positive? Report it.