Summary
The uncheckedtypeassertion analyzer is registered (cmd/linters/main.go:36) but not enforced in CI. A comprehensive scan of all production Go (pkg/ + cmd/, excluding tests/testdata) finds exactly 2 single-value type-assertion violations — and both are inside the linter framework itself, in the two newest analyzers. Every one of the other 16 analyzers already uses the safe two-value form. Fixing these 2 lines brings the codebase to zero violations, so the analyzer can be added to the enforced set the same way the last four linters were.
- Linter:
uncheckedtypeassertion (registered, unenforced)
- Total prod violations: 2 (entire
pkg/+cmd/ tree)
- Severity: Medium (panic-safety + framework self-consistency)
- Effort: Small (2-line change + 1 CI flag)
The 2 violations
Both sites are the identical pattern, in the analyzers added in the previous round:
| Location |
Code |
pkg/linters/jsonmarshalignoredeerror/jsonmarshalignoredeerror.go:26 |
insp := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) |
pkg/linters/strconvparseignorederror/strconvparseignorederror.go:34 |
insp := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) |
The uncheckedtypeassertion analyzer (pkg/linters/uncheckedtypeassertion/uncheckedtypeassertion.go) only exempts the two-value form (len(Lhs)==2 && len(Rhs)==1), type-switch guards (Type==nil), and test files. A single-value ResultOf assertion is therefore a real violation by the analyzer's own rules.
Why this is the right fix (self-consistency)
All 16 sibling analyzers already use the safe two-value form. Canonical example — pkg/linters/ctxbackground/ctxbackground.go:29-32:
insp, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
if !ok {
return nil, fmt.Errorf("inspect analyzer result has unexpected type %T", pass.ResultOf[inspect.Analyzer])
}
The two newest analyzers regressed from this established idiom. The linter framework should pass its own lint.
Recommended change
Before (both files):
func run(pass *analysis.Pass) (any, error) {
insp := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
After (match the 16 siblings):
func run(pass *analysis.Pass) (any, error) {
insp, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
if !ok {
return nil, fmt.Errorf("inspect analyzer result has unexpected type %T", pass.ResultOf[inspect.Analyzer])
}
Then append -uncheckedtypeassertion to the enforced LINTER_FLAGS in .github/workflows/cgo.yml:1040 (joining the 9 already enforced).
Validation
Context
This follows the proven pattern that has landed 3 consecutive runs: osexitinlibrary/rawloginlib (enforced after R20), regexpcompileinfunction/fprintlnsprintf/strconvparseignorederror (after R22), jsonmarshalignoredeerror (after R23, now enforced at cgo.yml:1040). uncheckedtypeassertion is the last near-zero-violation analyzer remaining unenforced.
References: run 26703919548
Generated by 🤖 Sergo - Serena Go Expert · opus48 3.5M · ◷
Summary
The
uncheckedtypeassertionanalyzer is registered (cmd/linters/main.go:36) but not enforced in CI. A comprehensive scan of all production Go (pkg/+cmd/, excluding tests/testdata) finds exactly 2 single-value type-assertion violations — and both are inside the linter framework itself, in the two newest analyzers. Every one of the other 16 analyzers already uses the safe two-value form. Fixing these 2 lines brings the codebase to zero violations, so the analyzer can be added to the enforced set the same way the last four linters were.uncheckedtypeassertion(registered, unenforced)pkg/+cmd/tree)The 2 violations
Both sites are the identical pattern, in the analyzers added in the previous round:
pkg/linters/jsonmarshalignoredeerror/jsonmarshalignoredeerror.go:26insp := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)pkg/linters/strconvparseignorederror/strconvparseignorederror.go:34insp := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)The
uncheckedtypeassertionanalyzer (pkg/linters/uncheckedtypeassertion/uncheckedtypeassertion.go) only exempts the two-value form (len(Lhs)==2 && len(Rhs)==1), type-switch guards (Type==nil), and test files. A single-valueResultOfassertion is therefore a real violation by the analyzer's own rules.Why this is the right fix (self-consistency)
All 16 sibling analyzers already use the safe two-value form. Canonical example —
pkg/linters/ctxbackground/ctxbackground.go:29-32:The two newest analyzers regressed from this established idiom. The linter framework should pass its own lint.
Recommended change
Before (both files):
After (match the 16 siblings):
Then append
-uncheckedtypeassertionto the enforcedLINTER_FLAGSin.github/workflows/cgo.yml:1040(joining the 9 already enforced).Validation
uncheckedtypeassertionviolations acrosspkg/+cmd/(scan done: only these 2 — no chained.(T).method, noreturn x.(T), no argument-position single-value forms; allpkg/workflowfrontmatter assertions already use the named-bool two-value form)-uncheckedtypeassertiontocgo.yml:1040LINTER_FLAGSmake golint-customContext
This follows the proven pattern that has landed 3 consecutive runs:
osexitinlibrary/rawloginlib(enforced after R20),regexpcompileinfunction/fprintlnsprintf/strconvparseignorederror(after R22),jsonmarshalignoredeerror(after R23, now enforced atcgo.yml:1040).uncheckedtypeassertionis the last near-zero-violation analyzer remaining unenforced.References: run 26703919548