From 709d3dfb8c86cebf331c9547132fb6a6eb07dc3b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 8 Jun 2026 05:41:12 +0000 Subject: [PATCH 1/2] Initial plan From c390892972715e091e91b7a420ab9a42ee6a3335 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 8 Jun 2026 05:51:07 +0000 Subject: [PATCH 2/2] Sync lenstringzero docs and linter spec coverage Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- pkg/linters/README.md | 5 +++++ pkg/linters/doc.go | 3 ++- pkg/linters/spec_test.go | 12 +++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pkg/linters/README.md b/pkg/linters/README.md index b4311be03c8..617227fb8ea 100644 --- a/pkg/linters/README.md +++ b/pkg/linters/README.md @@ -16,6 +16,7 @@ This package currently provides custom Go analyzers in the following subpackages - `fprintlnsprintf` — reports `fmt.Fprintln(..., fmt.Sprintf(...))` patterns and recommends direct formatting calls. - `jsonmarshalignoredeerror` — reports `json.Marshal` and `json.Unmarshal` calls where the error return is discarded with `_`. - `largefunc` — reports function bodies that exceed a configurable line-count threshold. +- `lenstringzero` — reports `len(s) == 0` / `len(s) != 0` comparisons on string values that should use `s == ""` / `s != ""`. - `manualmutexunlock` — reports non-deferred mutex `Unlock()` calls that can lead to deadlocks on early returns or panics. - `osexitinlibrary` — reports `os.Exit` calls in library packages (`pkg/*`) where process termination should be delegated to `cmd/*` entry points. - `ossetenvlibrary` — reports `os.Setenv` calls in library packages (`pkg/*`) where side effects should be isolated. @@ -45,6 +46,7 @@ This package currently provides custom Go analyzers in the following subpackages | `fprintlnsprintf` | Custom `go/analysis` analyzer that flags `fmt.Fprintln(..., fmt.Sprintf(...))` patterns | | `jsonmarshalignoredeerror` | Custom `go/analysis` analyzer that flags `json.Marshal`/`json.Unmarshal` calls where the error return is discarded with `_` | | `largefunc` | Custom `go/analysis` analyzer that flags large functions with actionable diagnostics | +| `lenstringzero` | Custom `go/analysis` analyzer that flags `len(s) == 0` / `len(s) != 0` on string values that should use `s == ""` / `s != ""` | | `manualmutexunlock` | Custom `go/analysis` analyzer that flags mutex `Unlock()` calls that are not deferred | | `osexitinlibrary` | Custom `go/analysis` analyzer that flags `os.Exit` usage in library packages | | `ossetenvlibrary` | Custom `go/analysis` analyzer that flags `os.Setenv` usage in library packages | @@ -74,6 +76,7 @@ import ( "github.com/github/gh-aw/pkg/linters/errstringmatch" "github.com/github/gh-aw/pkg/linters/fileclosenotdeferred" "github.com/github/gh-aw/pkg/linters/largefunc" + "github.com/github/gh-aw/pkg/linters/lenstringzero" "github.com/github/gh-aw/pkg/linters/manualmutexunlock" "github.com/github/gh-aw/pkg/linters/osexitinlibrary" panicinlibrarycode "github.com/github/gh-aw/pkg/linters/panic-in-library-code" @@ -89,6 +92,7 @@ _ = errormessage.Analyzer _ = errstringmatch.Analyzer _ = fileclosenotdeferred.Analyzer _ = largefunc.Analyzer +_ = lenstringzero.Analyzer _ = manualmutexunlock.Analyzer _ = osexitinlibrary.Analyzer _ = panicinlibrarycode.Analyzer @@ -110,6 +114,7 @@ _ = ssljson.Analyzer - `github.com/github/gh-aw/pkg/linters/fprintlnsprintf` — fprintln-sprintf analyzer subpackage - `github.com/github/gh-aw/pkg/linters/jsonmarshalignoredeerror` — json-marshal-ignored-error analyzer subpackage - `github.com/github/gh-aw/pkg/linters/largefunc` — large-func analyzer subpackage +- `github.com/github/gh-aw/pkg/linters/lenstringzero` — len-string-zero analyzer subpackage - `github.com/github/gh-aw/pkg/linters/manualmutexunlock` — manual-mutex-unlock analyzer subpackage - `github.com/github/gh-aw/pkg/linters/osexitinlibrary` — os-exit-in-library analyzer subpackage - `github.com/github/gh-aw/pkg/linters/ossetenvlibrary` — os-setenv-library analyzer subpackage diff --git a/pkg/linters/doc.go b/pkg/linters/doc.go index e165315b470..85ffd1d5461 100644 --- a/pkg/linters/doc.go +++ b/pkg/linters/doc.go @@ -1,6 +1,6 @@ // Package linters is a namespace for gh-aw's custom Go analysis linters. // -// The actual analyzers are implemented in subpackages. All 21 active analyzers: +// The actual analyzers are implemented in subpackages. All 22 active analyzers: // // - contextcancelnotdeferred — flags context cancel functions called directly instead of deferred // - ctxbackground — flags context.Background() inside functions that already receive a context @@ -12,6 +12,7 @@ // - fprintlnsprintf — flags fmt.Fprintln(..., fmt.Sprintf(...)) patterns // - jsonmarshalignoredeerror — flags json.Marshal/Unmarshal calls where the error is discarded with _ // - largefunc — flags function bodies that exceed a configurable line-count threshold +// - lenstringzero — flags len(s) == 0 / len(s) != 0 on string values that should use s == "" / s != "" // - manualmutexunlock — flags non-deferred mutex Unlock() calls // - osexitinlibrary — flags os.Exit calls in library packages // - ossetenvlibrary — flags os.Setenv calls in library packages diff --git a/pkg/linters/spec_test.go b/pkg/linters/spec_test.go index ecbbcbe9759..a9f80fa6388 100644 --- a/pkg/linters/spec_test.go +++ b/pkg/linters/spec_test.go @@ -21,6 +21,7 @@ import ( "github.com/github/gh-aw/pkg/linters/fprintlnsprintf" "github.com/github/gh-aw/pkg/linters/jsonmarshalignoredeerror" "github.com/github/gh-aw/pkg/linters/largefunc" + "github.com/github/gh-aw/pkg/linters/lenstringzero" "github.com/github/gh-aw/pkg/linters/manualmutexunlock" "github.com/github/gh-aw/pkg/linters/osexitinlibrary" "github.com/github/gh-aw/pkg/linters/ossetenvlibrary" @@ -47,7 +48,7 @@ type docAnalyzer struct { } // documentedAnalyzers returns the analyzer subpackages documented in the README -// "Public API > Subpackages" table. The README documents 21 analyzer +// "Public API > Subpackages" table. The README documents 22 analyzer // subpackages (the non-analyzer `internal` helper subpackage is excluded because // it exposes no Analyzer). // @@ -55,10 +56,10 @@ type docAnalyzer struct { // // contextcancelnotdeferred, ctxbackground, excessivefuncparams, errormessage, // errstringmatch, fileclosenotdeferred, fmterrorfnoverbs, fprintlnsprintf, -// jsonmarshalignoredeerror, largefunc, manualmutexunlock, osexitinlibrary, -// ossetenvlibrary, panic-in-library-code, rawloginlib, regexpcompileinfunction, -// seenmapbool, ssljson, strconvparseignorederror, tolowerequalfold, -// uncheckedtypeassertion +// jsonmarshalignoredeerror, largefunc, lenstringzero, manualmutexunlock, +// osexitinlibrary, ossetenvlibrary, panic-in-library-code, rawloginlib, +// regexpcompileinfunction, seenmapbool, ssljson, strconvparseignorederror, +// tolowerequalfold, uncheckedtypeassertion func documentedAnalyzers() []docAnalyzer { return []docAnalyzer{ {"contextcancelnotdeferred", contextcancelnotdeferred.Analyzer}, @@ -71,6 +72,7 @@ func documentedAnalyzers() []docAnalyzer { {"fprintlnsprintf", fprintlnsprintf.Analyzer}, {"jsonmarshalignoredeerror", jsonmarshalignoredeerror.Analyzer}, {"largefunc", largefunc.Analyzer}, + {"lenstringzero", lenstringzero.Analyzer}, {"manualmutexunlock", manualmutexunlock.Analyzer}, {"osexitinlibrary", osexitinlibrary.Analyzer}, {"ossetenvlibrary", ossetenvlibrary.Analyzer},