A switch is written inside a case of another switch

tx0/go:switch-in-casestrictwarningmaintainability

What it finds

A switch in a case of another switch makes the reader track two sets of cases at once, and a break in the inner one leaves only the inner switch. Moving the inner switch into a function with a name says what it decides.

Expression and type switches are checked; a switch inside a function literal in a case is not nested in this sense.

From the rule's source, switch_in_case.rs.

Example from the rule's tests
package p func f(a, b int) int {	switch a {	case 1:		switch b {tx0 reports: this switch is nested in a case of another switch		case 2:			return 3		}	case 2:		g := func() int {			switch b {			case 1:				return 1			}			return 0		}		return g()	}	return 0}
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/go:switch-in-case" = "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-in-case] reason="..."

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