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
114 changes: 2 additions & 112 deletions cmd/linters/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,119 +16,9 @@ package main
import (
"golang.org/x/tools/go/analysis/multichecker"

"github.com/github/gh-aw/pkg/linters/appendbytestring"
"github.com/github/gh-aw/pkg/linters/appendoneelement"
"github.com/github/gh-aw/pkg/linters/bytesbufferstring"
"github.com/github/gh-aw/pkg/linters/bytescomparestring"
"github.com/github/gh-aw/pkg/linters/contextcancelnotdeferred"
"github.com/github/gh-aw/pkg/linters/ctxbackground"
"github.com/github/gh-aw/pkg/linters/deferinloop"
"github.com/github/gh-aw/pkg/linters/errorfwrapv"
"github.com/github/gh-aw/pkg/linters/errormessage"
"github.com/github/gh-aw/pkg/linters/errortypeassertion"
"github.com/github/gh-aw/pkg/linters/errstringmatch"
"github.com/github/gh-aw/pkg/linters/excessivefuncparams"
"github.com/github/gh-aw/pkg/linters/execcommandwithoutcontext"
"github.com/github/gh-aw/pkg/linters/fileclosenotdeferred"
"github.com/github/gh-aw/pkg/linters/fmterrorfnoverbs"
"github.com/github/gh-aw/pkg/linters/fprintlnsprintf"
"github.com/github/gh-aw/pkg/linters/hardcodedfilepath"
"github.com/github/gh-aw/pkg/linters/httpnoctx"
"github.com/github/gh-aw/pkg/linters/httprespbodyclose"
"github.com/github/gh-aw/pkg/linters/httpstatuscode"
"github.com/github/gh-aw/pkg/linters/ioutildeprecated"
"github.com/github/gh-aw/pkg/linters/jsonmarshalignoredeerror"
"github.com/github/gh-aw/pkg/linters/largefunc"
"github.com/github/gh-aw/pkg/linters/lenstringsplit"
"github.com/github/gh-aw/pkg/linters/lenstringzero"
"github.com/github/gh-aw/pkg/linters/logfatallibrary"
"github.com/github/gh-aw/pkg/linters/manualmutexunlock"
"github.com/github/gh-aw/pkg/linters/mapclearloop"
"github.com/github/gh-aw/pkg/linters/mapdeletecheck"
"github.com/github/gh-aw/pkg/linters/nilctxpassed"
"github.com/github/gh-aw/pkg/linters/osexitinlibrary"
"github.com/github/gh-aw/pkg/linters/osgetenvlibrary"
"github.com/github/gh-aw/pkg/linters/ossetenvlibrary"
panicinlibrarycode "github.com/github/gh-aw/pkg/linters/panic-in-library-code"
"github.com/github/gh-aw/pkg/linters/rawloginlib"
"github.com/github/gh-aw/pkg/linters/regexpcompileinfunction"
"github.com/github/gh-aw/pkg/linters/seenmapbool"
"github.com/github/gh-aw/pkg/linters/sortslice"
"github.com/github/gh-aw/pkg/linters/sprintfbool"
"github.com/github/gh-aw/pkg/linters/sprintferrdot"
"github.com/github/gh-aw/pkg/linters/sprintferrorsnew"
"github.com/github/gh-aw/pkg/linters/sprintfint"
"github.com/github/gh-aw/pkg/linters/ssljson"
"github.com/github/gh-aw/pkg/linters/strconvparseignorederror"
"github.com/github/gh-aw/pkg/linters/stringreplaceminusone"
"github.com/github/gh-aw/pkg/linters/stringscountcontains"
"github.com/github/gh-aw/pkg/linters/stringsindexcontains"
"github.com/github/gh-aw/pkg/linters/timeafterleak"
"github.com/github/gh-aw/pkg/linters/timenowsub"
"github.com/github/gh-aw/pkg/linters/timesleepnocontext"
"github.com/github/gh-aw/pkg/linters/tolowerequalfold"
"github.com/github/gh-aw/pkg/linters/trimleftright"
"github.com/github/gh-aw/pkg/linters/uncheckedtypeassertion"
"github.com/github/gh-aw/pkg/linters/wgdonenotdeferred"
"github.com/github/gh-aw/pkg/linters/writebytestring"
"github.com/github/gh-aw/pkg/linters"
)

func main() {
multichecker.Main(
appendbytestring.Analyzer,
appendoneelement.Analyzer,
bytesbufferstring.Analyzer,
bytescomparestring.Analyzer,
contextcancelnotdeferred.Analyzer,
ctxbackground.Analyzer,
deferinloop.Analyzer,
errormessage.Analyzer,
errortypeassertion.Analyzer,
fprintlnsprintf.Analyzer,
errstringmatch.Analyzer,
errorfwrapv.Analyzer,
execcommandwithoutcontext.Analyzer,
excessivefuncparams.Analyzer,
fileclosenotdeferred.Analyzer,
fmterrorfnoverbs.Analyzer,
hardcodedfilepath.Analyzer,
httpnoctx.Analyzer,
httprespbodyclose.Analyzer,
ioutildeprecated.Analyzer,
httpstatuscode.Analyzer,
largefunc.Analyzer,
logfatallibrary.Analyzer,
manualmutexunlock.Analyzer,
mapclearloop.Analyzer,
mapdeletecheck.Analyzer,
nilctxpassed.Analyzer,
osexitinlibrary.Analyzer,
osgetenvlibrary.Analyzer,
ossetenvlibrary.Analyzer,
panicinlibrarycode.Analyzer,
rawloginlib.Analyzer,
regexpcompileinfunction.Analyzer,
ssljson.Analyzer,
seenmapbool.Analyzer,
sortslice.Analyzer,
sprintferrdot.Analyzer,
sprintferrorsnew.Analyzer,
sprintfbool.Analyzer,
sprintfint.Analyzer,
strconvparseignorederror.Analyzer,
stringreplaceminusone.Analyzer,
stringsindexcontains.Analyzer,
stringscountcontains.Analyzer,
jsonmarshalignoredeerror.Analyzer,
lenstringzero.Analyzer,
lenstringsplit.Analyzer,
timeafterleak.Analyzer,
timesleepnocontext.Analyzer,
timenowsub.Analyzer,
tolowerequalfold.Analyzer,
trimleftright.Analyzer,
uncheckedtypeassertion.Analyzer,
wgdonenotdeferred.Analyzer,
writebytestring.Analyzer,
)
multichecker.Main(linters.All()...)
}
Binary file modified linters
Binary file not shown.
5 changes: 5 additions & 0 deletions pkg/linters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ This package currently provides custom Go analyzers in the following subpackages
- `sortslice` — reports `sort.Slice` / `sort.SliceStable` calls that should use `slices.SortFunc` / `slices.SortStableFunc`.
- `sprintferrdot` — reports redundant `.Error()` calls on error values passed to `fmt` format functions where the fmt package calls `.Error()` automatically.
- `sprintferrorsnew` — reports `errors.New(fmt.Sprintf(...))` calls that should use `fmt.Errorf` instead.
- `sprintfbool` — reports `fmt.Sprintf("%t", b)` calls where `b` is a single bool value and suggests using `strconv.FormatBool(b)` instead.
- `sprintfint` — reports `fmt.Sprintf("%d", ...)` and related conversions that should use `strconv` helpers.
- `ssljson` — validates `ssl.json` skill artifacts found in `.github/skills/` against the SSL spec (enum membership, graph integrity, transition targets, entry pointer validity).
- `strconvparseignorederror` — reports `strconv` parsing calls (`Atoi`, `ParseInt`, etc.) where the error return is discarded with `_`.
Expand Down Expand Up @@ -108,6 +109,7 @@ This package currently provides custom Go analyzers in the following subpackages
| `sortslice` | Custom `go/analysis` analyzer that flags `sort.Slice` / `sort.SliceStable` calls that should use `slices.SortFunc` / `slices.SortStableFunc` |
| `sprintferrdot` | Custom `go/analysis` analyzer that flags redundant `.Error()` calls on error values passed to `fmt` format functions |
| `sprintferrorsnew` | Custom `go/analysis` analyzer that flags `errors.New(fmt.Sprintf(...))` calls that should use `fmt.Errorf` instead |
| `sprintfbool` | Custom `go/analysis` analyzer that flags `fmt.Sprintf("%t", b)` calls where `b` is a single bool value and suggests using `strconv.FormatBool(b)` instead |
| `sprintfint` | Custom `go/analysis` analyzer that flags `fmt.Sprintf` integer conversions that should use `strconv` helpers |
| `ssljson` | Custom `go/analysis` analyzer that validates SSL JSON skill artifacts in `.github/skills/` |
| `strconvparseignorederror` | Custom `go/analysis` analyzer that flags `strconv` parsing calls where the error return is discarded with `_` |
Expand Down Expand Up @@ -155,6 +157,7 @@ import (
"github.com/github/gh-aw/pkg/linters/rawloginlib"
"github.com/github/gh-aw/pkg/linters/regexpcompileinfunction"
"github.com/github/gh-aw/pkg/linters/sortslice"
"github.com/github/gh-aw/pkg/linters/sprintfbool"
"github.com/github/gh-aw/pkg/linters/sprintfint"
"github.com/github/gh-aw/pkg/linters/ssljson"
"github.com/github/gh-aw/pkg/linters/timesleepnocontext"
Expand Down Expand Up @@ -183,6 +186,7 @@ _ = panicinlibrarycode.Analyzer
_ = rawloginlib.Analyzer
_ = regexpcompileinfunction.Analyzer
_ = sortslice.Analyzer
_ = sprintfbool.Analyzer
_ = sprintfint.Analyzer
_ = ssljson.Analyzer
_ = timesleepnocontext.Analyzer
Expand Down Expand Up @@ -231,6 +235,7 @@ _ = trimleftright.Analyzer
- `github.com/github/gh-aw/pkg/linters/sortslice` — sort-slice analyzer subpackage
- `github.com/github/gh-aw/pkg/linters/sprintferrdot` — sprintf-err-dot analyzer subpackage
- `github.com/github/gh-aw/pkg/linters/sprintferrorsnew` — sprintf-errors-new analyzer subpackage
- `github.com/github/gh-aw/pkg/linters/sprintfbool` — sprintf-bool analyzer subpackage
- `github.com/github/gh-aw/pkg/linters/sprintfint` — sprintf-int analyzer subpackage
- `github.com/github/gh-aw/pkg/linters/ssljson` — ssl-json analyzer subpackage
- `github.com/github/gh-aw/pkg/linters/strconvparseignorederror` — strconv-parse-ignored-error 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.
//
// All 54 active analyzers:
// All 55 active analyzers:
//
// - appendbytestring — flags append(b, []byte(s)...) calls where s is a string that can be simplified to append(b, s...)
// - appendoneelement — flags append(s, []T{x}...) calls where a single-element slice literal is spread and can be simplified to append(s, x)
Expand Down Expand Up @@ -42,6 +42,7 @@
// - sortslice — flags sort.Slice / sort.SliceStable calls that should use slices.SortFunc / slices.SortStableFunc
// - sprintferrdot — flags redundant .Error() calls on error values passed to fmt format functions
// - sprintferrorsnew — flags errors.New(fmt.Sprintf(...)) calls that should use fmt.Errorf instead
// - sprintfbool — flags fmt.Sprintf("%t", b) calls where b is a single bool value and suggests using strconv.FormatBool(b) instead
// - sprintfint — flags fmt.Sprintf calls that format integers that should use strconv.Itoa
// - ssljson — validates ssl.json skill artifacts in .github/skills/ against the SSL spec
// - strconvparseignorederror — flags strconv parsing calls where the error is discarded with _
Expand Down
126 changes: 126 additions & 0 deletions pkg/linters/registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package linters

import (
"golang.org/x/tools/go/analysis"

"github.com/github/gh-aw/pkg/linters/appendbytestring"
"github.com/github/gh-aw/pkg/linters/appendoneelement"
"github.com/github/gh-aw/pkg/linters/bytesbufferstring"
"github.com/github/gh-aw/pkg/linters/bytescomparestring"
"github.com/github/gh-aw/pkg/linters/contextcancelnotdeferred"
"github.com/github/gh-aw/pkg/linters/ctxbackground"
"github.com/github/gh-aw/pkg/linters/deferinloop"
"github.com/github/gh-aw/pkg/linters/errorfwrapv"
"github.com/github/gh-aw/pkg/linters/errormessage"
"github.com/github/gh-aw/pkg/linters/errortypeassertion"
"github.com/github/gh-aw/pkg/linters/errstringmatch"
"github.com/github/gh-aw/pkg/linters/excessivefuncparams"
"github.com/github/gh-aw/pkg/linters/execcommandwithoutcontext"
"github.com/github/gh-aw/pkg/linters/fileclosenotdeferred"
"github.com/github/gh-aw/pkg/linters/fmterrorfnoverbs"
"github.com/github/gh-aw/pkg/linters/fprintlnsprintf"
"github.com/github/gh-aw/pkg/linters/hardcodedfilepath"
"github.com/github/gh-aw/pkg/linters/httpnoctx"
"github.com/github/gh-aw/pkg/linters/httprespbodyclose"
"github.com/github/gh-aw/pkg/linters/httpstatuscode"
"github.com/github/gh-aw/pkg/linters/ioutildeprecated"
"github.com/github/gh-aw/pkg/linters/jsonmarshalignoredeerror"
"github.com/github/gh-aw/pkg/linters/largefunc"
"github.com/github/gh-aw/pkg/linters/lenstringsplit"
"github.com/github/gh-aw/pkg/linters/lenstringzero"
"github.com/github/gh-aw/pkg/linters/logfatallibrary"
"github.com/github/gh-aw/pkg/linters/manualmutexunlock"
"github.com/github/gh-aw/pkg/linters/mapclearloop"
"github.com/github/gh-aw/pkg/linters/mapdeletecheck"
"github.com/github/gh-aw/pkg/linters/nilctxpassed"
"github.com/github/gh-aw/pkg/linters/osexitinlibrary"
"github.com/github/gh-aw/pkg/linters/osgetenvlibrary"
"github.com/github/gh-aw/pkg/linters/ossetenvlibrary"
panicinlibrarycode "github.com/github/gh-aw/pkg/linters/panic-in-library-code"
"github.com/github/gh-aw/pkg/linters/rawloginlib"
"github.com/github/gh-aw/pkg/linters/regexpcompileinfunction"
"github.com/github/gh-aw/pkg/linters/seenmapbool"
"github.com/github/gh-aw/pkg/linters/sortslice"
"github.com/github/gh-aw/pkg/linters/sprintfbool"
"github.com/github/gh-aw/pkg/linters/sprintferrdot"
"github.com/github/gh-aw/pkg/linters/sprintferrorsnew"
"github.com/github/gh-aw/pkg/linters/sprintfint"
"github.com/github/gh-aw/pkg/linters/ssljson"
"github.com/github/gh-aw/pkg/linters/strconvparseignorederror"
"github.com/github/gh-aw/pkg/linters/stringreplaceminusone"
"github.com/github/gh-aw/pkg/linters/stringscountcontains"
"github.com/github/gh-aw/pkg/linters/stringsindexcontains"
"github.com/github/gh-aw/pkg/linters/timeafterleak"
"github.com/github/gh-aw/pkg/linters/timenowsub"
"github.com/github/gh-aw/pkg/linters/timesleepnocontext"
"github.com/github/gh-aw/pkg/linters/tolowerequalfold"
"github.com/github/gh-aw/pkg/linters/trimleftright"
"github.com/github/gh-aw/pkg/linters/uncheckedtypeassertion"
"github.com/github/gh-aw/pkg/linters/wgdonenotdeferred"
"github.com/github/gh-aw/pkg/linters/writebytestring"
)

// All returns all registered custom analysis linters.
//
// This is the canonical, importable source of truth for the full set of active
// analyzers. Use it to drive multichecker.Main, test assertions, and
// doc-completeness checks so that every consumer stays in sync automatically.
func All() []*analysis.Analyzer {
Comment on lines +63 to +68
return []*analysis.Analyzer{
appendbytestring.Analyzer,
appendoneelement.Analyzer,
bytesbufferstring.Analyzer,
bytescomparestring.Analyzer,
contextcancelnotdeferred.Analyzer,
ctxbackground.Analyzer,
deferinloop.Analyzer,
errormessage.Analyzer,
errortypeassertion.Analyzer,
fprintlnsprintf.Analyzer,
errstringmatch.Analyzer,
errorfwrapv.Analyzer,
execcommandwithoutcontext.Analyzer,
excessivefuncparams.Analyzer,
fileclosenotdeferred.Analyzer,
fmterrorfnoverbs.Analyzer,
hardcodedfilepath.Analyzer,
httpnoctx.Analyzer,
httprespbodyclose.Analyzer,
ioutildeprecated.Analyzer,
httpstatuscode.Analyzer,
largefunc.Analyzer,
logfatallibrary.Analyzer,
manualmutexunlock.Analyzer,
mapclearloop.Analyzer,
mapdeletecheck.Analyzer,
nilctxpassed.Analyzer,
osexitinlibrary.Analyzer,
osgetenvlibrary.Analyzer,
ossetenvlibrary.Analyzer,
panicinlibrarycode.Analyzer,
rawloginlib.Analyzer,
regexpcompileinfunction.Analyzer,
ssljson.Analyzer,
seenmapbool.Analyzer,
sortslice.Analyzer,
sprintferrdot.Analyzer,
sprintferrorsnew.Analyzer,
sprintfbool.Analyzer,
sprintfint.Analyzer,
strconvparseignorederror.Analyzer,
stringreplaceminusone.Analyzer,
stringsindexcontains.Analyzer,
stringscountcontains.Analyzer,
jsonmarshalignoredeerror.Analyzer,
lenstringzero.Analyzer,
lenstringsplit.Analyzer,
timeafterleak.Analyzer,
timesleepnocontext.Analyzer,
timenowsub.Analyzer,
tolowerequalfold.Analyzer,
trimleftright.Analyzer,
uncheckedtypeassertion.Analyzer,
wgdonenotdeferred.Analyzer,
writebytestring.Analyzer,
}
}
Loading
Loading