Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/linters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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"
Expand All @@ -89,6 +92,7 @@ _ = errormessage.Analyzer
_ = errstringmatch.Analyzer
_ = fileclosenotdeferred.Analyzer
_ = largefunc.Analyzer
_ = lenstringzero.Analyzer
_ = manualmutexunlock.Analyzer
_ = osexitinlibrary.Analyzer
_ = panicinlibrarycode.Analyzer
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/linters/doc.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions pkg/linters/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -47,18 +48,18 @@ 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).
//
// Spec (README "Public API > Subpackages"):
//
// 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},
Expand All @@ -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},
Expand Down
Loading