Skip to content

Commit 10ec6cf

Browse files
pelikhanCopilot
andauthored
Fix CGO unit failures from typeassertionnil registry drift (#64919)
Synchronize analyzer documentation and spec coverage, and record the pending cross-platform CI enforcement audit. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent a72f1c7 commit 10ec6cf

4 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎pkg/linters/README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ This package currently provides custom Go analyzers in the following subpackages
7373
- `timenowsub` — reports `time.Now().Sub(t)` calls that should be simplified to `time.Since(t)`.
7474
- `tolowerequalfold` — reports case-insensitive string comparisons using `strings.ToLower`/`ToUpper` that should use `strings.EqualFold`.
7575
- `trimleftright` — reports `strings.TrimLeft`/`TrimRight` calls with a multi-character literal cutset where `TrimPrefix`/`TrimSuffix` was likely intended.
76+
- `typeassertionnil` — reports single-value type assertions to pointer types and recommends the two-value form.
7677
- `typeassertionokdiscarded` — reports two-value type assertions whose `ok` result is discarded.
7778
- `uncheckedsliceindex` — reports slice and string indexes without proven bounds checks.
7879
- `uncheckedtypeassertion` — reports single-value type assertions where unchecked panics are possible.
@@ -175,6 +176,7 @@ environment variable and gates findings on the recorded execution hit count for
175176
| `timenowsub` | Custom `go/analysis` analyzer that flags `time.Now().Sub(t)` calls that should use `time.Since(t)` |
176177
| `tolowerequalfold` | Custom `go/analysis` analyzer that flags case-insensitive comparisons via `strings.ToLower`/`ToUpper` that should use `strings.EqualFold` |
177178
| `trimleftright` | Custom `go/analysis` analyzer that flags `strings.TrimLeft`/`TrimRight` calls with a multi-character literal cutset where `TrimPrefix`/`TrimSuffix` was likely intended |
179+
| `typeassertionnil` | Custom `go/analysis` analyzer that flags single-value type assertions to pointer types and recommends the two-value form |
178180
| `typeassertionokdiscarded` | Custom `go/analysis` analyzer that flags two-value type assertions whose `ok` result is discarded |
179181
| `uncheckedsliceindex` | Custom `go/analysis` analyzer that reports slice and string indexes without proven bounds checks |
180182
| `uncheckedtypeassertion` | Custom `go/analysis` analyzer that flags unchecked single-value type assertions |
@@ -222,6 +224,7 @@ import (
222224
"github.com/github/gh-aw/pkg/linters/ssljson"
223225
"github.com/github/gh-aw/pkg/linters/timesleepnocontext"
224226
"github.com/github/gh-aw/pkg/linters/trimleftright"
227+
"github.com/github/gh-aw/pkg/linters/typeassertionnil"
225228
)
226229

227230
// Use with multichecker, singlechecker, or custom go/analysis driver.
@@ -252,6 +255,7 @@ _ = sprintfint.Analyzer
252255
_ = ssljson.Analyzer
253256
_ = timesleepnocontext.Analyzer
254257
_ = trimleftright.Analyzer
258+
_ = typeassertionnil.Analyzer
255259
```
256260

257261
## Dependencies
@@ -314,6 +318,7 @@ _ = trimleftright.Analyzer
314318
- `github.com/github/gh-aw/pkg/linters/timesleepnocontext` — time-sleep-no-context analyzer subpackage
315319
- `github.com/github/gh-aw/pkg/linters/tolowerequalfold` — to-lower-equal-fold analyzer subpackage
316320
- `github.com/github/gh-aw/pkg/linters/trimleftright` — trim-left-right analyzer subpackage
321+
- `github.com/github/gh-aw/pkg/linters/typeassertionnil` — type-assertion-nil analyzer subpackage
317322
- `github.com/github/gh-aw/pkg/linters/typeassertionokdiscarded` — type-assertion-ok-discarded analyzer subpackage
318323
- `github.com/github/gh-aw/pkg/linters/unchecked-slice-index` — unchecked-slice-index analyzer subpackage
319324
- `github.com/github/gh-aw/pkg/linters/uncheckedtypeassertion` — unchecked-type-assertion analyzer subpackage
@@ -336,6 +341,7 @@ _ = trimleftright.Analyzer
336341

337342
- The package is intentionally organized as a namespace (`pkg/linters/*`) so individual analyzers remain isolated and independently testable.
338343
- CI currently enforces the `errstringmatch`, `manualmutexunlock`, `panicinlibrarycode`, `osexitinlibrary`, and `rawloginlib` analyzers via `.github/workflows/cgo.yml`.
344+
- `typeassertionnil` is registered but excluded from CI enforcement pending a cross-platform enforcement-readiness audit.
339345
- `excessivefuncparams` exposes a `-max-params` analyzer flag and defaults to `8` parameters (`DefaultMaxParams`).
340346
- `largefunc` exposes a `-max-lines` analyzer flag, defaults to `60` lines (`DefaultMaxLines`), and skips `_test.go` files.
341347
- `osexitinlibrary` helps enforce separation between library logic and process-level termination.

‎pkg/linters/doc.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Package linters is a namespace for gh-aw's custom Go analysis linters.
22
//
3-
// All 74 active analyzers:
3+
// All 75 active analyzers:
44
//
55
// - appendbytestring — flags append(b, []byte(s)...) calls where s is a string that can be simplified to append(b, s...)
66
// - appendoneelement — flags append(s, []T{x}...) calls where a single-element slice literal is spread and can be simplified to append(s, x)
@@ -69,6 +69,7 @@
6969
// - timenowsub — reports time.Now().Sub(t) calls that should be simplified to time.Since(t)
7070
// - tolowerequalfold — flags case-insensitive comparisons via ToLower/ToUpper that should use EqualFold
7171
// - trimleftright — flags strings.TrimLeft/TrimRight calls with a multi-character literal cutset where TrimPrefix/TrimSuffix was likely intended
72+
// - typeassertionnil — flags single-value type assertions to pointer types and recommends the two-value form
7273
// - typeassertionokdiscarded — flags two-value type assertions whose ok result is discarded
7374
// - uncheckedsliceindex — reports slice and string indexes without proven bounds
7475
// - uncheckedtypeassertion — flags unchecked single-value type assertions

‎pkg/linters/doc_sync_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var notYetEnforced = map[string]string{
3939
"sprintferrdot": "has not yet completed an enforcement-readiness audit",
4040
"ssljson": "has not yet completed an enforcement-readiness audit",
4141
"stringsconcatloop": "has not yet completed an enforcement-readiness audit",
42+
"typeassertionnil": "needs a cross-platform enforcement-readiness audit before CI enables it",
4243
"typeassertionokdiscarded": "existing production violations need remediation before enforcement; nolint suppression already works",
4344
"uncheckedsliceindex": "existing production violations need remediation before enforcement; nolint suppression already works",
4445
}

‎pkg/linters/spec_test.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import (
7878
"github.com/github/gh-aw/pkg/linters/timesleepnocontext"
7979
"github.com/github/gh-aw/pkg/linters/tolowerequalfold"
8080
"github.com/github/gh-aw/pkg/linters/trimleftright"
81+
"github.com/github/gh-aw/pkg/linters/typeassertionnil"
8182
"github.com/github/gh-aw/pkg/linters/typeassertionokdiscarded"
8283
uncheckedsliceindex "github.com/github/gh-aw/pkg/linters/unchecked-slice-index"
8384
"github.com/github/gh-aw/pkg/linters/uncheckedflushreturn"
@@ -100,7 +101,7 @@ type docAnalyzer struct {
100101
}
101102

102103
// documentedAnalyzers returns the analyzer subpackages documented in the README
103-
// "Public API > Subpackages" table. The README documents 73 analyzers
104+
// "Public API > Subpackages" table. The README documents 75 analyzer
104105
// subpackages (the non-analyzer `internal` helper subpackage is excluded because
105106
// it exposes no Analyzer).
106107
//
@@ -112,7 +113,7 @@ type docAnalyzer struct {
112113
// logfatallibrary, manualmutexunlock, manualpathconcat, mapclearloop, mapdeletecheck, nilctxpassed, osexitinlibrary, osgetenvlibrary, ossetenvlibrary, packagelevelmutableslicemap, panic-in-library-code, rawloginlib,
113114
// regexpcompileinfunction, regexpdynamicpattern, seenmapbool, slicemakezerolength, sortslice, sprintferrdot, sprintferrorsnew, sprintfbool, sprintfint, ssljson,
114115
// strconvparseignorederror, stringbytesroundtrip, stringreplaceminusone, stringsconcatloop, stringscountcontains, stringsindexcontains, stringsindexhasprefix, stringsjoinone, timeafterleak, timesleepnocontext, timenowsub,
115-
// tolowerequalfold, trimleftright, typeassertionokdiscarded, uncheckedflushreturn, uncheckedsliceindex, uncheckedtypeassertion, walkfuncerrshadow, wgdonenotdeferred, writebytestring
116+
// tolowerequalfold, trimleftright, typeassertionnil, typeassertionokdiscarded, uncheckedflushreturn, uncheckedsliceindex, uncheckedtypeassertion, walkfuncerrshadow, wgdonenotdeferred, writebytestring
116117
func documentedAnalyzers() []docAnalyzer {
117118
return []docAnalyzer{
118119
{"appendbytestring", appendbytestring.Analyzer},
@@ -182,6 +183,7 @@ func documentedAnalyzers() []docAnalyzer {
182183
{"timenowsub", timenowsub.Analyzer},
183184
{"tolowerequalfold", tolowerequalfold.Analyzer},
184185
{"trimleftright", trimleftright.Analyzer},
186+
{"typeassertionnil", typeassertionnil.Analyzer},
185187
{"typeassertionokdiscarded", typeassertionokdiscarded.Analyzer},
186188
{"uncheckedsliceindex", uncheckedsliceindex.Analyzer},
187189
{"uncheckedtypeassertion", uncheckedtypeassertion.Analyzer},

0 commit comments

Comments
 (0)