Skip to content

enforce-switch-style: handle type switches#1629

Merged
alexandear merged 1 commit intomgechev:masterfrom
weppos:switch-TypeSwitchStmt
Feb 10, 2026
Merged

enforce-switch-style: handle type switches#1629
alexandear merged 1 commit intomgechev:masterfrom
weppos:switch-TypeSwitchStmt

Conversation

@weppos
Copy link
Copy Markdown
Contributor

@weppos weppos commented Feb 9, 2026

This PR adds support for type-switch to the rule enforce-switch-style.

As described in the associated ticket, this is motivated by a bug we found in our codebase where we missed an else clause for a type-switch. And when trying to enforce the rule via golangci-lint, we found that the type-switch was ignored nonetheless.

Further investigation revealed that Revive is currently skipping type-switches.

This is how a failure will be reported:

example.go:766:3: enforce-switch-style: switch must have a default case clause (revive)
switch v := kv.(type) {
case *dns.SVCBMandatory:
        # ...
case *dns.SVCBAlpn:
        # ...
case *dns.SVCBNoDefaultAlpn:
        # ...
case *dns.SVCBPort:

Closes #1628

@alexandear alexandear changed the title Update enforce-switch-style to work on type switches enforce-switch-style: handle type switches Feb 10, 2026
@alexandear
Copy link
Copy Markdown
Collaborator

@weppos thank you! Merging.

@alexandear alexandear merged commit f9673c6 into mgechev:master Feb 10, 2026
9 checks passed
@weppos weppos deleted the switch-TypeSwitchStmt branch February 10, 2026 17:09
@alexandear alexandear mentioned this pull request Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

enforce-switch-style support for type-switch

2 participants