Help us shape the future of Go! Take the 2026 Go Developer Survey

linters

package
v0.76.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 1 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:

  • ctxbackground — reports context.Background() calls inside functions that already receive a context.Context parameter.
  • excessivefuncparams — reports function declarations that exceed a configurable parameter-count threshold.
  • errormessage — reports non-actionable error-message patterns in changed files.
  • errstringmatch — reports strings.Contains(err.Error(), "...") patterns and recommends errors.Is / errors.As.
  • fileclosenotdeferred — reports non-deferred file Close() calls that can leak resources.
  • largefunc — reports function bodies that exceed a configurable line-count threshold.
  • 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.
  • 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.
  • ssljson — validates ssl.json skill artifacts found in .github/skills/ against the SSL spec (enum membership, graph integrity, transition targets, entry pointer validity).

Public API

Subpackages
Subpackage Description
ctxbackground Custom go/analysis analyzer that flags context.Background() calls inside functions that already receive a context parameter
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
errstringmatch Custom go/analysis analyzer that flags brittle strings.Contains(err.Error(), "...") checks
fileclosenotdeferred Custom go/analysis analyzer that flags file Close() calls that are not deferred immediately
largefunc Custom go/analysis analyzer that flags large functions with actionable diagnostics
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
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
ssljson Custom go/analysis analyzer that validates SSL JSON skill artifacts in .github/skills/
Namespace exports
Symbol Description
ErrorMessageAnalyzer Compatibility alias to pkg/linters/errormessage.Analyzer

Usage Examples

import (
	"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/fileclosenotdeferred"
	"github.com/github/gh-aw/pkg/linters/largefunc"
	"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"
	"github.com/github/gh-aw/pkg/linters/rawloginlib"
	"github.com/github/gh-aw/pkg/linters/regexpcompileinfunction"
	"github.com/github/gh-aw/pkg/linters/ssljson"
)

// Use with multichecker, singlechecker, or custom go/analysis driver.
_ = ctxbackground.Analyzer
_ = excessivefuncparams.Analyzer
_ = errormessage.Analyzer
_ = errstringmatch.Analyzer
_ = fileclosenotdeferred.Analyzer
_ = largefunc.Analyzer
_ = manualmutexunlock.Analyzer
_ = osexitinlibrary.Analyzer
_ = panicinlibrarycode.Analyzer
_ = rawloginlib.Analyzer
_ = regexpcompileinfunction.Analyzer
_ = ssljson.Analyzer

Dependencies

Internal:

  • pkg/linters/errormessage (via namespace compatibility export ErrorMessageAnalyzer).

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.
  • excessivefuncparams exposes a -max-params analyzer flag and defaults to 8 parameters (DefaultMaxParams).
  • largefunc exposes a -max-lines analyzer flag and defaults to 60 lines (DefaultMaxLines).
  • osexitinlibrary helps enforce separation between library logic and process-level termination.

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.

The actual analyzers are implemented in subpackages — see the excessivefuncparams, errormessage, largefunc, and osexitinlibrary subdirectories for analyzer entry points. 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

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
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 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 errstringmatch implements a Go analysis linter that flags calls to strings.Contains(err.Error(), "literal") that 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(err.Error(), "literal") that 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 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 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, ...).
internal
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 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 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 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 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 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 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.

Jump to

Keyboard shortcuts

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