analyzer

package
v5.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAnalyzer

func NewAnalyzer() *analysis.Analyzer

NewAnalyzer returns an analyzer configured exclusively through command-line flags, intended for CLI drivers (singlechecker, go vet -vettool). The processor is built lazily on the first run, after the driver has parsed the flags.

func NewAnalyzerWithConfig added in v5.0.2

func NewAnalyzerWithConfig(config Config) (*analysis.Analyzer, error)

NewAnalyzerWithConfig returns an analyzer configured programmatically, intended for library consumers such as golangci-lint. The configuration is copied and validated immediately; it exposes no flags, and later mutations of the passed Config have no effect.

Types

type Config

type Config struct {
	// EnforcePatterns is a list of regular expressions to match type names that
	// should be checked. Anonymous structs can be matched by '<anonymous>' alias.
	//
	// Each regular expression must match the full type name, including package path.
	// For example, to match type `net/http.Cookie` regular expression should be
	// `.*/http\.Cookie`, but not `http\.Cookie`.
	EnforcePatterns Patterns `exhaustruct:"optional"`

	// IgnorePatterns is a list of regular expressions to match type names that
	// should be skipped from checking. Anonymous structs can be matched by
	// '<anonymous>' alias.
	//
	// Has precedence over EnforcePatterns.
	//
	// Each regular expression must match the full type name, including package path.
	// For example, to match type `net/http.Cookie` regular expression should be
	// `.*/http\.Cookie`, but not `http\.Cookie`.
	IgnorePatterns Patterns `exhaustruct:"optional"`

	// OptionalPatterns is a list of regular expressions to match type names where
	// all fields are treated as optional. Anonymous structs can be matched by
	// '<anonymous>' alias.
	//
	// Each regular expression must match the full type name, including package path.
	// For example, to match type `net/http.Cookie` regular expression should be
	// `.*/http\.Cookie`, but not `http\.Cookie`.
	OptionalPatterns Patterns `exhaustruct:"optional"`

	// AllowEmpty allows empty structures, effectively excluding them from the check.
	AllowEmpty bool `exhaustruct:"optional"`

	// AllowEmptyPatterns is a list of regular expressions to match type names that
	// should be allowed to be empty. Anonymous structs can be matched by
	// '<anonymous>' alias.
	//
	// Each regular expression must match the full type name, including package path.
	// For example, to match type `net/http.Cookie` regular expression should be
	// `.*/http\.Cookie`, but not `http\.Cookie`.
	AllowEmptyPatterns Patterns `exhaustruct:"optional"`

	// AllowEmptyReturns allows empty structures in return statements.
	AllowEmptyReturns bool `exhaustruct:"optional"`

	// AllowEmptyDeclarations allows empty structures in variable declarations.
	AllowEmptyDeclarations bool `exhaustruct:"optional"`

	// ReportFullTypePath enables full package path in error messages instead of
	// short package name. This helps when configuring include/exclude patterns,
	// as import aliases can make short names ambiguous.
	ReportFullTypePath bool `exhaustruct:"optional"`

	// ExplicitMode enables opt-in checking. When true, only types marked with
	// //exhaustruct:enforce directive or matching enforce-rx patterns are checked.
	ExplicitMode bool `exhaustruct:"optional"`
}

type Patterns added in v5.0.2

type Patterns []string

Patterns is a list of regular expression patterns. It implements flag.Value, validating each value as a regular expression at flag-parse time so invalid patterns fail early.

func (*Patterns) Set added in v5.0.2

func (p *Patterns) Set(value string) error

Set validates and appends a pattern (flag.Value interface).

func (*Patterns) String added in v5.0.2

func (p *Patterns) String() string

String returns the patterns joined with commas (flag.Value interface).

Jump to

Keyboard shortcuts

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