Skip to content

[sergo] Enforce uncheckedtypeassertion in CI — 2 self-inconsistent single-value assertions in newest analyzers (#aw_sg24a1) #36060

@github-actions

Description

@github-actions

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

  • Convert the 2 sites to the two-value form (matching siblings)
  • Confirm zero uncheckedtypeassertion violations across pkg/+cmd/ (scan done: only these 2 — no chained .(T).method, no return x.(T), no argument-position single-value forms; all pkg/workflow frontmatter assertions already use the named-bool two-value form)
  • Append -uncheckedtypeassertion to cgo.yml:1040 LINTER_FLAGS
  • Run make golint-custom

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 ·

  • expires on Jun 7, 2026, 5:23 AM UTC

Metadata

Metadata

Labels

cookieIssue Monster Loves Cookies!sergo

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions