linters

package
v0.82.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 56 Imported by: 0

README

linters Package

The linters package namespace contains custom static analysis linters used by gh-aw quality checks.

Overview

This package currently provides custom Go analyzers in the following subpackages:

  • appendbytestring — reports append(b, []byte(s)...) calls where b is []byte and s is a string, which can be simplified to append(b, s...).
  • appendoneelement — reports append(s, []T{x}...) calls where a single-element slice literal is spread and can be simplified to append(s, x).
  • bytescomparestring — reports string(a) == string(b) and string(a) != string(b) comparisons where a and b are []byte values; use bytes.Equal(a, b) for == and !bytes.Equal(a, b) for !=.
  • bytesbufferstring — reports string(buf.Bytes()) calls where buf is a bytes.Buffer value receiver, suggesting buf.String() instead.
  • contextcancelnotdeferred — reports context cancel functions that are called directly instead of deferred.
  • ctxbackground — reports context.Background() calls inside functions that already receive a context.Context parameter.
  • deferinloop — reports defer statements placed directly inside for/range loop bodies, which execute when the enclosing function returns rather than each iteration and can cause resource leaks.
  • errorfwrapv — reports fmt.Errorf calls that pass error arguments without %w wrapping.
  • excessivefuncparams — reports function declarations that exceed a configurable parameter-count threshold.
  • errormessage — reports non-actionable error-message patterns in changed files.
  • errortypeassertion — reports type assertions from error to concrete types and recommends errors.As.
  • errstringmatch — reports strings.Contains(err.Error(), "...") patterns and recommends errors.Is / errors.As.
  • fileclosenotdeferred — reports non-deferred file Close() calls that can leak resources.
  • execcommandwithoutcontext — reports exec.Command(...) calls inside functions that already receive context.Context and should use exec.CommandContext(...).
  • fmterrorfnoverbs — reports fmt.Errorf calls whose format string contains no verbs, recommending errors.New instead.
  • fprintlnsprintf — reports fmt.Fprintln(..., fmt.Sprintf(...)) patterns and recommends direct formatting calls.
  • hardcodedfilepath — reports hard-coded file path string literals that match known path constants or should be extracted into named constants; also annotates paths that appear in log/print calls.
  • httpnoctx — reports HTTP client and package-level HTTP calls that do not accept a context.Context.
  • httprespbodyclose — reports HTTP responses whose Body.Close() call is missing or not deferred.
  • httpstatuscode — reports raw HTTP status-code integer literals that should use net/http named constants.
  • ioutildeprecated — reports uses of deprecated io/ioutil functions (deprecated since Go 1.16) and suggests their replacements in the io and os packages.
  • jsonmarshalignoredeerror — reports json.Marshal and json.Unmarshal calls where the error return is discarded.
  • largefunc — reports function bodies that exceed a configurable line-count threshold.
  • lenstringsplit — reports len(strings.Split(s, sep)) expressions with a non-empty separator that should use strings.Count(s, sep)+1 to avoid an intermediate slice allocation.
  • lenstringzero — reports len(s) == 0 / len(s) != 0 comparisons on string values that should use s == "" / s != "".
  • logfatallibrary — reports log.Fatal, log.Fatalf, and log.Fatalln calls in library packages (pkg/*) where they implicitly call os.Exit and bypass deferred cleanup.
  • mapclearloop — reports range-over-map loops that delete every entry and can be replaced with clear(m).
  • mapdeletecheck — reports redundant map membership checks before delete(m, k) calls since delete is already a no-op for missing keys.
  • manualmutexunlock — reports non-deferred mutex Unlock() calls that can lead to deadlocks on early returns or panics.
  • nilctxpassed — reports function calls where nil is passed as a context.Context argument; the correct idioms are context.Background() or context.TODO().
  • osgetenvlibrary — reports os.Getenv calls in library packages (pkg/*) where environment access should be injected.
  • 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.
  • panic-in-library-code — reports panic() calls in library packages (pkg/*) where errors should be returned instead.
  • rawloginlib — reports direct usage of the standard log package in library packages, where pkg/logger should be used.
  • regexpcompileinfunction — reports regexp.MustCompile / regexp.Compile calls inside functions that should be package-level.
  • seenmapbool — reports map[string]bool used as a set (values always true) that should use map[string]struct{} instead.
  • 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 _.
  • stringreplaceminusone — reports strings.Replace calls whose n argument is -1, which should use the more readable strings.ReplaceAll.
  • stringscountcontains — reports strings.Count(s, sub) comparisons with 0 or 1 (e.g. > 0, >= 1, == 0, != 0, < 1, <= 0) and their yoda-order variants that should use strings.Contains(s, sub) or !strings.Contains(s, sub) instead.
  • stringsindexcontains — reports strings.Index(s, substr) comparisons with -1 or 0 (e.g. != -1, >= 0, > -1, == -1, < 0, <= -1) and their yoda-order variants that should use strings.Contains(s, substr) or !strings.Contains(s, substr) instead.
  • timeafterleak — reports time.After calls used as the channel-receive expression in a select case inside a for or range loop that leak a timer channel on each iteration when another case fires first.
  • timesleepnocontext — reports time.Sleep calls inside functions that already receive a context.Context, where a context-aware select should be used instead.
  • timenowsub — reports time.Now().Sub(t) calls that should be simplified to time.Since(t).
  • tolowerequalfold — reports case-insensitive string comparisons using strings.ToLower/ToUpper that should use strings.EqualFold.
  • trimleftright — reports strings.TrimLeft/TrimRight calls with a multi-character literal cutset where TrimPrefix/TrimSuffix was likely intended.
  • uncheckedtypeassertion — reports single-value type assertions where unchecked panics are possible.
  • wgdonenotdeferred — reports non-deferred sync.WaitGroup.Done() calls that can deadlock on panics or early returns.
  • writebytestring — reports w.Write([]byte(s)) calls where s is a string, which can be replaced with io.WriteString to avoid an unnecessary []byte allocation.
  • internal — shared helper packages for analyzers (file checks and nolint handling).

Public API

Subpackages
Subpackage Description
appendbytestring Custom go/analysis analyzer that flags append(b, []byte(s)...) calls where s is a string that can be simplified to append(b, s...)
appendoneelement Custom go/analysis analyzer that flags append(s, []T{x}...) calls where a single-element slice literal is spread and can be simplified to append(s, x)
bytescomparestring Custom go/analysis analyzer that flags string(a) == string(b) / != comparisons on []byte values; use bytes.Equal(a, b) for == and !bytes.Equal(a, b) for !=
bytesbufferstring Custom go/analysis analyzer that flags string(buf.Bytes()) calls where buf is a bytes.Buffer value and suggests buf.String() instead
contextcancelnotdeferred Custom go/analysis analyzer that flags context cancel functions called directly instead of deferred
ctxbackground Custom go/analysis analyzer that flags context.Background() calls inside functions that already receive a context parameter
deferinloop Custom go/analysis analyzer that flags defer statements inside for/range loop bodies that execute when the enclosing function returns rather than each iteration
errorfwrapv Custom go/analysis analyzer that flags fmt.Errorf calls that pass error arguments without %w wrapping
excessivefuncparams Custom go/analysis analyzer that flags function declarations with too many positional parameters
errormessage Custom go/analysis analyzer that flags non-actionable error message patterns in changed files
errortypeassertion Custom go/analysis analyzer that flags type assertions from error to concrete types and recommends errors.As
errstringmatch Custom go/analysis analyzer that flags brittle strings.Contains(err.Error(), "...") checks
execcommandwithoutcontext Custom go/analysis analyzer that flags exec.Command(...) calls that should use exec.CommandContext(...) in context-receiving functions
fileclosenotdeferred Custom go/analysis analyzer that flags file Close() calls that are not deferred immediately
fmterrorfnoverbs Custom go/analysis analyzer that flags fmt.Errorf calls with no format verbs, recommending errors.New
fprintlnsprintf Custom go/analysis analyzer that flags fmt.Fprintln(..., fmt.Sprintf(...)) patterns
hardcodedfilepath Custom go/analysis analyzer that flags hard-coded file path string literals that match known path constants or should be extracted as named constants; annotates paths in log/print calls
httpnoctx Custom go/analysis analyzer that flags HTTP calls that do not accept a context.Context
httprespbodyclose Custom go/analysis analyzer that flags HTTP response bodies that are not closed (or not deferred)
httpstatuscode Custom go/analysis analyzer that flags raw HTTP status-code integer literals that should use net/http named constants
ioutildeprecated Custom go/analysis analyzer that flags deprecated io/ioutil function calls (deprecated since Go 1.16) and suggests replacements in the io and os packages
jsonmarshalignoredeerror Custom go/analysis analyzer that flags json.Marshal/json.Unmarshal calls where the error return is discarded
largefunc Custom go/analysis analyzer that flags large functions with actionable diagnostics
lenstringsplit Custom go/analysis analyzer that flags len(strings.Split(s, sep)) with a non-empty separator that should use strings.Count(s, sep)+1
lenstringzero Custom go/analysis analyzer that flags len(s) == 0 / len(s) != 0 on string values that should use s == "" / s != ""
logfatallibrary Custom go/analysis analyzer that flags log.Fatal, log.Fatalf, and log.Fatalln calls in library packages where they implicitly call os.Exit and bypass deferred cleanup
mapclearloop Custom go/analysis analyzer that flags range-over-map loops that delete every entry and can be replaced with clear(m)
mapdeletecheck Custom go/analysis analyzer that flags redundant map membership checks before delete(m, k) calls since delete is a no-op for missing keys
manualmutexunlock Custom go/analysis analyzer that flags mutex Unlock() calls that are not deferred
nilctxpassed Custom go/analysis analyzer that flags function calls where nil is passed as a context.Context argument
osgetenvlibrary Custom go/analysis analyzer that flags os.Getenv usage in library packages
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
panic-in-library-code Custom go/analysis analyzer that flags panic() usage in library packages
rawloginlib Custom go/analysis analyzer that flags standard-library log package calls in library packages
regexpcompileinfunction Custom go/analysis analyzer that flags regexp compilation inside function bodies
seenmapbool Custom go/analysis analyzer that flags map[string]bool used as a set that should use map[string]struct{}
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 _
stringreplaceminusone Custom go/analysis analyzer that flags strings.Replace calls with n=-1 that should use strings.ReplaceAll
stringscountcontains Custom go/analysis analyzer that flags strings.Count(s, sub) comparisons with 0 or 1 that should use strings.Contains or !strings.Contains
stringsindexcontains Custom go/analysis analyzer that flags strings.Index(s, substr) comparisons with -1 or 0 that should use strings.Contains or !strings.Contains
timeafterleak Custom go/analysis analyzer that flags time.After in select cases inside loops that leak a timer channel on each iteration when another case fires first
timesleepnocontext Custom go/analysis analyzer that flags time.Sleep calls in context-aware functions
timenowsub Custom go/analysis analyzer that flags time.Now().Sub(t) calls that should use time.Since(t)
tolowerequalfold Custom go/analysis analyzer that flags case-insensitive comparisons via strings.ToLower/ToUpper that should use strings.EqualFold
trimleftright Custom go/analysis analyzer that flags strings.TrimLeft/TrimRight calls with a multi-character literal cutset where TrimPrefix/TrimSuffix was likely intended
uncheckedtypeassertion Custom go/analysis analyzer that flags unchecked single-value type assertions
wgdonenotdeferred Custom go/analysis analyzer that flags non-deferred sync.WaitGroup.Done() calls
writebytestring Custom go/analysis analyzer that flags w.Write([]byte(s)) calls where s is a string that can be replaced with io.WriteString
internal Shared helper subpackages used by analyzers (internal/filecheck, internal/nolint)
Namespace exports
Symbol Description
ErrorMessageAnalyzer Compatibility alias to pkg/linters/errormessage.Analyzer

Usage Examples

import (
	"github.com/github/gh-aw/pkg/linters/deferinloop"
	"github.com/github/gh-aw/pkg/linters/errorfwrapv"
	"github.com/github/gh-aw/pkg/linters/ctxbackground"
	"github.com/github/gh-aw/pkg/linters/excessivefuncparams"
	"github.com/github/gh-aw/pkg/linters/errormessage"
	"github.com/github/gh-aw/pkg/linters/errstringmatch"
	"github.com/github/gh-aw/pkg/linters/execcommandwithoutcontext"
	"github.com/github/gh-aw/pkg/linters/fileclosenotdeferred"
	"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/largefunc"
	"github.com/github/gh-aw/pkg/linters/lenstringzero"
	"github.com/github/gh-aw/pkg/linters/manualmutexunlock"
	"github.com/github/gh-aw/pkg/linters/osgetenvlibrary"
	"github.com/github/gh-aw/pkg/linters/osexitinlibrary"
	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/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"
	"github.com/github/gh-aw/pkg/linters/trimleftright"
)

// Use with multichecker, singlechecker, or custom go/analysis driver.
_ = ctxbackground.Analyzer
_ = deferinloop.Analyzer
_ = errorfwrapv.Analyzer
_ = excessivefuncparams.Analyzer
_ = errormessage.Analyzer
_ = errstringmatch.Analyzer
_ = execcommandwithoutcontext.Analyzer
_ = fileclosenotdeferred.Analyzer
_ = hardcodedfilepath.Analyzer
_ = httpnoctx.Analyzer
_ = httprespbodyclose.Analyzer
_ = httpstatuscode.Analyzer
_ = largefunc.Analyzer
_ = lenstringzero.Analyzer
_ = manualmutexunlock.Analyzer
_ = osgetenvlibrary.Analyzer
_ = osexitinlibrary.Analyzer
_ = panicinlibrarycode.Analyzer
_ = rawloginlib.Analyzer
_ = regexpcompileinfunction.Analyzer
_ = sortslice.Analyzer
_ = sprintfbool.Analyzer
_ = sprintfint.Analyzer
_ = ssljson.Analyzer
_ = timesleepnocontext.Analyzer
_ = trimleftright.Analyzer

Dependencies

Internal:

  • github.com/github/gh-aw/pkg/linters/appendbytestring — append-byte-string analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/appendoneelement — append-one-element analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/bytescomparestring — bytes-compare-string analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/bytesbufferstring — bytes-buffer-string analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/contextcancelnotdeferred — context-cancel-not-deferred analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/ctxbackground — context-background analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/deferinloop — defer-in-loop analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/errorfwrapv — fmt-errorf-wrap-v analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/errormessage — error-message analyzer subpackage (also re-exported as ErrorMessageAnalyzer)
  • github.com/github/gh-aw/pkg/linters/errortypeassertion — error-type-assertion analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/errstringmatch — err-string-match analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/execcommandwithoutcontext — exec-command-without-context analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/excessivefuncparams — excessive-func-params analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/fileclosenotdeferred — file-close-not-deferred analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/fmterrorfnoverbs — fmt-errorf-no-verbs analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/fprintlnsprintf — fprintln-sprintf analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/hardcodedfilepath — hard-coded-file-path analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/httpnoctx — HTTP-no-context analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/httprespbodyclose — HTTP-response-body-close analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/httpstatuscode — http-status-code analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/ioutildeprecated — ioutil-deprecated 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/lenstringsplit — len-strings-split analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/lenstringzero — len-string-zero analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/logfatallibrary — log-fatal-library analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/mapclearloop — map-clear-loop analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/mapdeletecheck — map-delete-check analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/manualmutexunlock — manual-mutex-unlock analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/osgetenvlibrary — os-getenv-library 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
  • github.com/github/gh-aw/pkg/linters/panic-in-library-code — panic-in-library-code analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/rawloginlib — raw-log-in-lib analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/regexpcompileinfunction — regexp-compile-in-function analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/seenmapbool — seen-map-bool analyzer subpackage
  • 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
  • github.com/github/gh-aw/pkg/linters/stringreplaceminusone — string-replace-minus-one analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/stringscountcontains — strings-count-contains analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/stringsindexcontains — strings-index-contains analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/timeafterleak — time-after-leak analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/timesleepnocontext — time-sleep-no-context analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/tolowerequalfold — to-lower-equal-fold analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/trimleftright — trim-left-right analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/uncheckedtypeassertion — unchecked-type-assertion analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/wgdonenotdeferred — wg-done-not-deferred analyzer subpackage
  • github.com/github/gh-aw/pkg/linters/writebytestring — write-byte-string analyzer subpackage

Transitive / Internal helpers:

  • github.com/github/gh-aw/pkg/linters/internal/filecheck — shared file-path filtering helpers used by multiple analyzers
  • github.com/github/gh-aw/pkg/linters/internal/nolint — shared //nolint directive parsing helpers used by multiple analyzers

External:

  • golang.org/x/tools/go/analysis — analyzer framework
  • golang.org/x/tools/go/analysis/passes/inspect — AST inspection support
  • golang.org/x/tools/go/ast/inspector — efficient AST traversal

Design Notes

  • The package is intentionally organized as a namespace (pkg/linters/*) so individual analyzers remain isolated and independently testable.
  • CI currently enforces the errstringmatch, manualmutexunlock, panicinlibrarycode, osexitinlibrary, and rawloginlib analyzers via .github/workflows/cgo.yml.
  • excessivefuncparams exposes a -max-params analyzer flag and defaults to 8 parameters (DefaultMaxParams).
  • largefunc exposes a -max-lines analyzer flag, defaults to 60 lines (DefaultMaxLines), and skips _test.go files.
  • osexitinlibrary helps enforce separation between library logic and process-level termination.

Source-verified export coverage

This appendix is generated from the current non-test Go source files in this package and records any exported top-level symbols that are not already described above.

Category Count
Types 0
Constants 0
Variables 1
Functions and methods 0
Additional symbols documented in this appendix 0

The sections above already mention every exported top-level symbol in the current source tree.


This specification is automatically maintained by the spec-extractor workflow.

Documentation

Overview

Package linters is a namespace for gh-aw's custom Go analysis linters.

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)
  • bytesbufferstring — reports string(buf.Bytes()) calls where buf is a bytes.Buffer value and suggests buf.String() instead
  • bytescomparestring — flags string(a) == string(b) and string(a) != string(b) comparisons where a and b are []byte values and recommends bytes.Equal for clearer intent
  • contextcancelnotdeferred — flags context cancel functions called directly instead of deferred
  • ctxbackground — flags context.Background() inside functions that already receive a context
  • deferinloop — flags defer statements placed directly inside for or range loop bodies
  • errorfwrapv — flags fmt.Errorf calls that pass error arguments without %w wrapping
  • errormessage — flags non-actionable error message patterns in changed files
  • errortypeassertion — flags type assertions from error to concrete types and recommends errors.As
  • errstringmatch — flags brittle strings.Contains(err.Error(), "...") checks
  • excessivefuncparams — flags function declarations with too many positional parameters
  • execcommandwithoutcontext — flags exec.Command calls inside functions that already receive context.Context
  • fileclosenotdeferred — flags file Close() calls that are not deferred
  • fmterrorfnoverbs — flags fmt.Errorf calls with no format verbs, recommending errors.New
  • fprintlnsprintf — flags fmt.Fprintln(..., fmt.Sprintf(...)) patterns
  • hardcodedfilepath — flags hard-coded file path string literals that match known path constants or should be extracted as named constants
  • httpnoctx — flags HTTP calls that do not accept a context.Context
  • httprespbodyclose — flags HTTP response bodies that are not closed
  • httpstatuscode — flags HTTP status code anti-patterns
  • ioutildeprecated — reports uses of deprecated io/ioutil functions that should be replaced with io or os package equivalents
  • jsonmarshalignoredeerror — flags json.Marshal/Unmarshal calls where the error is discarded with _
  • largefunc — flags function bodies that exceed a configurable line-count threshold
  • lenstringsplit — flags len(strings.Split(s, sep)) with a non-empty separator that should use strings.Count(s, sep)+1
  • lenstringzero — flags len(s) == 0 / len(s) != 0 on string values that should use s == "" / s != ""
  • logfatallibrary — reports log.Fatal, log.Fatalf, and log.Fatalln calls inside library packages where they implicitly call os.Exit and bypass deferred cleanup
  • manualmutexunlock — flags non-deferred mutex Unlock() calls
  • mapclearloop — reports range-over-map loops that delete every entry and can be replaced with clear(m)
  • mapdeletecheck — reports redundant map membership checks before delete(m, k) calls since delete is already a no-op for missing keys
  • nilctxpassed — flags function calls where nil is passed as a context.Context argument
  • osexitinlibrary — flags os.Exit calls in library packages
  • osgetenvlibrary — flags os.Getenv calls in library packages
  • ossetenvlibrary — flags os.Setenv calls in library packages
  • panic-in-library-code — flags panic() calls in library packages
  • rawloginlib — flags direct usage of the standard log package in library packages
  • regexpcompileinfunction — flags regexp.MustCompile/Compile calls inside functions
  • seenmapbool — flags map[string]bool used as a set that should use map[string]struct{}
  • 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 _
  • stringreplaceminusone — flags strings.Replace calls with n=-1 that should use strings.ReplaceAll
  • stringscountcontains — reports strings.Count(s, sub) comparisons with 0 or 1 (e.g. > 0, >= 1, == 0, != 0, < 1, <= 0) and their yoda-order variants that should use strings.Contains(s, sub) or !strings.Contains(s, sub)
  • stringsindexcontains — flags strings.Index(s, substr) comparisons that should use strings.Contains
  • timeafterleak — flags time.After in select cases inside loops that leak timer channels
  • timesleepnocontext — flags time.Sleep calls in context-aware functions that should propagate cancellation
  • timenowsub — reports time.Now().Sub(t) calls that should be simplified to time.Since(t)
  • tolowerequalfold — flags case-insensitive comparisons via ToLower/ToUpper that should use EqualFold
  • trimleftright — flags strings.TrimLeft/TrimRight calls with a multi-character literal cutset where TrimPrefix/TrimSuffix was likely intended
  • uncheckedtypeassertion — flags unchecked single-value type assertions
  • wgdonenotdeferred — flags non-deferred sync.WaitGroup.Done() calls
  • writebytestring — flags w.Write([]byte(s)) calls where s is a string that can be replaced with io.WriteString(w, s)

The package also exposes a compatibility alias (ErrorMessageAnalyzer) that points to the errormessage subpackage analyzer.

Index

Constants

This section is empty.

Variables

View Source
var ErrorMessageAnalyzer = errormessage.Analyzer

ErrorMessageAnalyzer exposes the actionable error-message analyzer.

Functions

func All added in v0.82.15

func All() []*analysis.Analyzer

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.

Types

This section is empty.

Directories

Path Synopsis
Package appendbytestring implements a Go analysis linter that flags append(b, []byte(s)...) calls where b is []byte and s is a string, which can be simplified to append(b, s...) without the redundant conversion.
Package appendbytestring implements a Go analysis linter that flags append(b, []byte(s)...) calls where b is []byte and s is a string, which can be simplified to append(b, s...) without the redundant conversion.
Package appendoneelement implements a Go analysis linter that flags append(s, []T{x}...) calls where a single-element slice literal is spread, which can be simplified to append(s, x).
Package appendoneelement implements a Go analysis linter that flags append(s, []T{x}...) calls where a single-element slice literal is spread, which can be simplified to append(s, x).
Package bytesbufferstring implements a Go analysis linter that flags string(buf.Bytes()) calls where buf is a bytes.Buffer value receiver, suggesting buf.String() instead.
Package bytesbufferstring implements a Go analysis linter that flags string(buf.Bytes()) calls where buf is a bytes.Buffer value receiver, suggesting buf.String() instead.
Package bytescomparestring implements a Go analysis linter that flags string(a) == string(b) and string(a) != string(b) comparisons where both a and b are []byte values, which should use bytes.Equal(a, b) instead for clearer intent.
Package bytescomparestring implements a Go analysis linter that flags string(a) == string(b) and string(a) != string(b) comparisons where both a and b are []byte values, which should use bytes.Equal(a, b) instead for clearer intent.
Package contextcancelnotdeferred implements a Go analysis linter that flags context cancel functions called manually instead of deferred.
Package contextcancelnotdeferred implements a Go analysis linter that flags context cancel functions called manually instead of deferred.
Package ctxbackground implements a Go analysis linter that flags calls to context.Background() inside functions that already receive a context.Context parameter.
Package ctxbackground implements a Go analysis linter that flags calls to context.Background() inside functions that already receive a context.Context parameter.
Package deferinloop implements a Go analysis linter that flags defer statements placed directly inside for or range loop bodies.
Package deferinloop implements a Go analysis linter that flags defer statements placed directly inside for or range loop bodies.
Package errorfwrapv implements a Go analysis linter that flags calls to fmt.Errorf that either format error arguments with %v or otherwise pass error arguments without any %w, which breaks error-chain inspection via errors.Is and errors.As.
Package errorfwrapv implements a Go analysis linter that flags calls to fmt.Errorf that either format error arguments with %v or otherwise pass error arguments without any %w, which breaks error-chain inspection via errors.Is and errors.As.
Package errormessage implements a Go analysis linter that enforces actionable error-message patterns in changed files.
Package errormessage implements a Go analysis linter that enforces actionable error-message patterns in changed files.
Package errortypeassertion implements a Go analysis linter that flags type assertions on values typed as the built-in error interface when asserting to concrete types, and recommends errors.As for wrapped error traversal.
Package errortypeassertion implements a Go analysis linter that flags type assertions on values typed as the built-in error interface when asserting to concrete types, and recommends errors.As for wrapped error traversal.
Package errstringmatch implements a Go analysis linter that flags calls to strings.Contains/HasPrefix/HasSuffix/EqualFold/Index/LastIndex/Compare on err.Error() with a string literal — all perform brittle substring matching on error messages instead of using errors.Is or errors.As.
Package errstringmatch implements a Go analysis linter that flags calls to strings.Contains/HasPrefix/HasSuffix/EqualFold/Index/LastIndex/Compare on err.Error() with a string literal — all perform brittle substring matching on error messages instead of using errors.Is or errors.As.
Package excessivefuncparams implements a Go analysis linter that flags functions with too many positional parameters.
Package excessivefuncparams implements a Go analysis linter that flags functions with too many positional parameters.
Package execcommandwithoutcontext implements a Go analysis linter that flags calls to exec.Command inside functions that already receive a context.Context parameter, where exec.CommandContext should be used instead to propagate cancellation.
Package execcommandwithoutcontext implements a Go analysis linter that flags calls to exec.Command inside functions that already receive a context.Context parameter, where exec.CommandContext should be used instead to propagate cancellation.
Package fileclosenotdeferred implements a Go analysis linter that flags file operations where Close() is not immediately deferred.
Package fileclosenotdeferred implements a Go analysis linter that flags file operations where Close() is not immediately deferred.
Package fmterrorfnoverbs implements a Go analysis linter that flags calls to fmt.Errorf where the format string contains no format verbs, in which case errors.New is the idiomatic and cheaper alternative.
Package fmterrorfnoverbs implements a Go analysis linter that flags calls to fmt.Errorf where the format string contains no format verbs, in which case errors.New is the idiomatic and cheaper alternative.
Package fprintlnsprintf implements a Go analysis linter that flags fmt.Fprintln(w, fmt.Sprintf(...)) calls that should be rewritten as fmt.Fprintf(w, ...).
Package fprintlnsprintf implements a Go analysis linter that flags fmt.Fprintln(w, fmt.Sprintf(...)) calls that should be rewritten as fmt.Fprintf(w, ...).
Package hardcodedfilepath implements a Go analysis linter that flags hard-coded file path string literals and compares them against a known set of file path constants.
Package hardcodedfilepath implements a Go analysis linter that flags hard-coded file path string literals and compares them against a known set of file path constants.
Package httpnoctx implements a Go analysis linter that flags HTTP calls that do not accept a context.Context: (*http.Client).Get, .Head, .Post, .PostForm and the package-level http.Get/Head/Post/PostForm shortcuts.
Package httpnoctx implements a Go analysis linter that flags HTTP calls that do not accept a context.Context: (*http.Client).Get, .Head, .Post, .PostForm and the package-level http.Get/Head/Post/PostForm shortcuts.
Package httprespbodyclose implements a Go analysis linter that flags HTTP response Body.Close() calls that are made directly instead of deferred.
Package httprespbodyclose implements a Go analysis linter that flags HTTP response Body.Close() calls that are made directly instead of deferred.
Package httpstatuscode implements a Go analysis linter that reports integer HTTP status code literals used in comparisons that should use http.Status* named constants.
Package httpstatuscode implements a Go analysis linter that reports integer HTTP status code literals used in comparisons that should use http.Status* named constants.
internal
astutil
Package astutil provides shared AST/type helper functions used by linters.
Package astutil provides shared AST/type helper functions used by linters.
nolint
Package nolint provides shared helpers for nolint-directive detection used by linters within pkg/linters.
Package nolint provides shared helpers for nolint-directive detection used by linters within pkg/linters.
Package ioutildeprecated implements a Go analysis linter that flags calls to functions from the deprecated io/ioutil package and suggests their replacements in the io and os packages (deprecated since Go 1.16).
Package ioutildeprecated implements a Go analysis linter that flags calls to functions from the deprecated io/ioutil package and suggests their replacements in the io and os packages (deprecated since Go 1.16).
Package jsonmarshalignoredeerror implements a Go analysis linter that flags json.Marshal and json.Unmarshal calls where the error return is discarded.
Package jsonmarshalignoredeerror implements a Go analysis linter that flags json.Marshal and json.Unmarshal calls where the error return is discarded.
Package largefunc implements a Go analysis linter that flags functions whose body exceeds a configurable line threshold.
Package largefunc implements a Go analysis linter that flags functions whose body exceeds a configurable line threshold.
Package lenstringsplit implements a Go analysis linter that flags len(strings.Split(s, sep)) expressions with a provably non-empty separator that allocate a []string just to count substrings.
Package lenstringsplit implements a Go analysis linter that flags len(strings.Split(s, sep)) expressions with a provably non-empty separator that allocate a []string just to count substrings.
Package lenstringzero implements a Go analysis linter that flags len(s) == 0, len(s) != 0, and equivalent relational comparisons (len(s) > 0, len(s) >= 1, len(s) < 1, len(s) <= 0) on string values that should use == "" or != "" instead.
Package lenstringzero implements a Go analysis linter that flags len(s) == 0, len(s) != 0, and equivalent relational comparisons (len(s) > 0, len(s) >= 1, len(s) < 1, len(s) <= 0) on string values that should use == "" or != "" instead.
Package logfatallibrary implements a Go analysis linter that flags log.Fatal, log.Fatalf, and log.Fatalln calls in library (pkg/) packages.
Package logfatallibrary implements a Go analysis linter that flags log.Fatal, log.Fatalf, and log.Fatalln calls in library (pkg/) packages.
Package manualmutexunlock implements a Go analysis linter that flags mutex Unlock() calls that are not deferred, which can lead to deadlocks if a panic or early return occurs between Lock() and Unlock().
Package manualmutexunlock implements a Go analysis linter that flags mutex Unlock() calls that are not deferred, which can lead to deadlocks if a panic or early return occurs between Lock() and Unlock().
Package mapclearloop implements a Go analysis linter that flags range-over-map loops whose only body statement is delete(m, k), which should be replaced by the built-in clear(m) introduced in Go 1.21.
Package mapclearloop implements a Go analysis linter that flags range-over-map loops whose only body statement is delete(m, k), which should be replaced by the built-in clear(m) introduced in Go 1.21.
Package mapdeletecheck implements a Go analysis linter that flags redundant map membership checks before a delete call such as "if _, ok := m[k]; ok { delete(m, k) }" which can be simplified to "delete(m, k)" since delete is a no-op for missing keys.
Package mapdeletecheck implements a Go analysis linter that flags redundant map membership checks before a delete call such as "if _, ok := m[k]; ok { delete(m, k) }" which can be simplified to "delete(m, k)" since delete is a no-op for missing keys.
Package nilctxpassed implements a Go analysis linter that flags function calls where nil is passed as a context.Context argument.
Package nilctxpassed implements a Go analysis linter that flags function calls where nil is passed as a context.Context argument.
Package osexitinlibrary implements a Go analysis linter that flags os.Exit calls in library (pkg/) packages.
Package osexitinlibrary implements a Go analysis linter that flags os.Exit calls in library (pkg/) packages.
Package osgetenvlibrary implements a Go analysis linter that flags os.Getenv and os.LookupEnv calls in non-main, non-test packages.
Package osgetenvlibrary implements a Go analysis linter that flags os.Getenv and os.LookupEnv calls in non-main, non-test packages.
Package ossetenvlibrary implements a Go analysis linter that flags os.Setenv and os.Unsetenv calls in non-main, non-test packages.
Package ossetenvlibrary implements a Go analysis linter that flags os.Setenv and os.Unsetenv calls in non-main, non-test packages.
Package panicinlibrarycode implements a Go analysis linter that flags panic() calls in library (pkg/) packages.
Package panicinlibrarycode implements a Go analysis linter that flags panic() calls in library (pkg/) packages.
Package rawloginlib implements a Go analysis linter that flags standard log package calls in library (pkg/) packages.
Package rawloginlib implements a Go analysis linter that flags standard log package calls in library (pkg/) packages.
Package regexpcompileinfunction implements a Go analysis linter that flags calls to regexp.MustCompile() and regexp.Compile() inside function bodies.
Package regexpcompileinfunction implements a Go analysis linter that flags calls to regexp.MustCompile() and regexp.Compile() inside function bodies.
Package seenmapbool implements a Go analysis linter that flags "seen" maps declared as map[string]bool (using true as sentinel) that should use map[string]struct{} to avoid allocating a bool per entry.
Package seenmapbool implements a Go analysis linter that flags "seen" maps declared as map[string]bool (using true as sentinel) that should use map[string]struct{} to avoid allocating a bool per entry.
Package sortslice implements a Go analysis linter that flags sort.Slice and sort.SliceStable calls that should use the type-safe slices.SortFunc or slices.SortStableFunc from the standard library slices package.
Package sortslice implements a Go analysis linter that flags sort.Slice and sort.SliceStable calls that should use the type-safe slices.SortFunc or slices.SortStableFunc from the standard library slices package.
Package sprintfbool implements a Go analysis linter that flags fmt.Sprintf("%t", b) calls where b is a single bool value and suggests using strconv.FormatBool(b) instead.
Package sprintfbool implements a Go analysis linter that flags fmt.Sprintf("%t", b) calls where b is a single bool value and suggests using strconv.FormatBool(b) instead.
Package sprintferrdot implements a Go analysis linter that flags redundant .Error() calls on error values passed to fmt format functions.
Package sprintferrdot implements a Go analysis linter that flags redundant .Error() calls on error values passed to fmt format functions.
Package sprintferrorsnew implements a Go analysis linter that flags errors.New(fmt.Sprintf(...)) calls that should use fmt.Errorf instead.
Package sprintferrorsnew implements a Go analysis linter that flags errors.New(fmt.Sprintf(...)) calls that should use fmt.Errorf instead.
Package sprintfint implements a Go analysis linter that flags fmt.Sprintf("%d", x) calls where x is a single int value and suggests using strconv.Itoa(x) instead.
Package sprintfint implements a Go analysis linter that flags fmt.Sprintf("%d", x) calls where x is a single int value and suggests using strconv.Itoa(x) instead.
Package ssljson implements a Go analysis linter that validates .github/skills/*/ssl.json files against the SSL specification rules.
Package ssljson implements a Go analysis linter that validates .github/skills/*/ssl.json files against the SSL specification rules.
Package strconvparseignorederror implements a Go analysis linter that flags strconv parsing calls (Atoi, ParseInt, ParseFloat, ParseBool, ParseUint) where the error return is discarded with _.
Package strconvparseignorederror implements a Go analysis linter that flags strconv parsing calls (Atoi, ParseInt, ParseFloat, ParseBool, ParseUint) where the error return is discarded with _.
Package stringreplaceminusone implements a Go analysis linter that flags strings.Replace calls whose n argument is -1, which should instead use the more readable and idiomatic strings.ReplaceAll.
Package stringreplaceminusone implements a Go analysis linter that flags strings.Replace calls whose n argument is -1, which should instead use the more readable and idiomatic strings.ReplaceAll.
Package stringscountcontains implements a Go analysis linter that flags strings.Count(s, sub) comparisons with 0 or 1 (e.g.
Package stringscountcontains implements a Go analysis linter that flags strings.Count(s, sub) comparisons with 0 or 1 (e.g.
Package stringsindexcontains implements a Go analysis linter that flags strings.Index(s, substr) comparisons with -1 or 0 (e.g.
Package stringsindexcontains implements a Go analysis linter that flags strings.Index(s, substr) comparisons with -1 or 0 (e.g.
Package timeafterleak implements a Go analysis linter that flags time.After calls used as select case channel receives inside loops, which allocate a new timer on every iteration that is not garbage collected until it fires when another case is selected first.
Package timeafterleak implements a Go analysis linter that flags time.After calls used as select case channel receives inside loops, which allocate a new timer on every iteration that is not garbage collected until it fires when another case is selected first.
Package timenowsub implements a Go analysis linter that flags time.Now().Sub(t) calls that can be simplified to time.Since(t).
Package timenowsub implements a Go analysis linter that flags time.Now().Sub(t) calls that can be simplified to time.Since(t).
Package timesleepnocontext implements a Go analysis linter that flags bare time.Sleep calls inside functions that already receive a context.Context parameter, where a context-aware select should be used to propagate cancellation.
Package timesleepnocontext implements a Go analysis linter that flags bare time.Sleep calls inside functions that already receive a context.Context parameter, where a context-aware select should be used to propagate cancellation.
Package tolowerequalfold implements a Go analysis linter that flags case-insensitive string comparisons performed via strings.ToLower (or strings.ToUpper) combined with == that should instead use strings.EqualFold.
Package tolowerequalfold implements a Go analysis linter that flags case-insensitive string comparisons performed via strings.ToLower (or strings.ToUpper) combined with == that should instead use strings.EqualFold.
Package trimleftright implements a Go analysis linter that flags calls to strings.TrimLeft or strings.TrimRight with a multi-character string literal cutset, where strings.TrimPrefix or strings.TrimSuffix is almost certainly the intended function.
Package trimleftright implements a Go analysis linter that flags calls to strings.TrimLeft or strings.TrimRight with a multi-character string literal cutset, where strings.TrimPrefix or strings.TrimSuffix is almost certainly the intended function.
Package uncheckedtypeassertion implements a Go analysis linter that flags single-value type assertions x.(T) that may panic at runtime if the dynamic type does not match, and where the two-value safe form x.(T) is not used.
Package uncheckedtypeassertion implements a Go analysis linter that flags single-value type assertions x.(T) that may panic at runtime if the dynamic type does not match, and where the two-value safe form x.(T) is not used.
Package wgdonenotdeferred implements a Go analysis linter that flags sync.WaitGroup Done() calls that are not deferred, which can lead to deadlocks if the function panics or returns early before Done() is reached.
Package wgdonenotdeferred implements a Go analysis linter that flags sync.WaitGroup Done() calls that are not deferred, which can lead to deadlocks if the function panics or returns early before Done() is reached.
Package writebytestring implements a Go analysis linter that flags w.Write([]byte(s)) calls where s is a string, which can be replaced with io.WriteString(w, s) to avoid an unnecessary []byte allocation.
Package writebytestring implements a Go analysis linter that flags w.Write([]byte(s)) calls where s is a string, which can be replaced with io.WriteString(w, s) to avoid an unnecessary []byte allocation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL