detect

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = func() *analysis.Analyzer {
	a, err := New()
	if err != nil {
		panic(err)
	}

	return a
}()

Analyzer is a pre-configured *analysis.Analyzer for detecting error types in Go programs.

Functions

func New

func New(opts ...Option) (*analysis.Analyzer, error)

New creates a new instance of the detecttypes analyzer. It detects how error types are used (as pointers or values) to provide this information to other analyzers in the toolchain.

Types

type Heuristic

type Heuristic uint8

Heuristic represents heuristic flags used to control various passes in the analysis process.

const (
	// HeuristicOff turns off all heuristic passes.
	HeuristicOff Heuristic = iota // off

	// HeuristicVar represents a heuristic pass for variable declarations.
	HeuristicVar // var

	// HeuristicUsage represents a heuristic pass for general usage.
	HeuristicUsage // usage

	// HeuristicReceivers represents a heuristic pass for consistent method receivers.
	HeuristicReceivers // receivers
)

func (Heuristic) String

func (i Heuristic) String() string

type Option

type Option interface {
	Apply(opts *detect.Options) error
	LogAttr() slog.Attr
}

Option configures specific behavior of the detect analysis.Analyzer.

func Join added in v0.0.11

func Join(opts ...Option) Option

Join creates a new Option joining the provided Option values.

The result implements slog.LogValuer, so the following is evaluated lazily:

slog.LogAttrs(ctx, slog.LevelInfo, "settings", Join(opts...).LogAttr())

func WithHeuristics

func WithHeuristics(heuristics ...Heuristic) Option

WithHeuristics is an Option to configure heuristic passes.

func WithOverrideFile added in v0.0.9

func WithOverrideFile(file string) Option

WithOverrideFile returns an Option that configures usage overrides by reading types from the specified file.

func WithOverrides

func WithOverrides(overrides map[result.ErrorType][]string) Option

WithOverrides returns an Option that applies the provided overrides mapping, allowing specific type names to be associated with custom error types.

func WithTrace

func WithTrace(trace *regexp.Regexp) Option

WithTrace is an Option to configure result output.

func WithWrappers added in v0.0.10

func WithWrappers(wrappers map[result.WrapperType][]string) Option

WithWrappers returns an Option that applies the provided overrides mapping, allowing specific functions to be treated as a wrapper for standard function.

Directories

Path Synopsis
Package result defines the types used to represent error type usage patterns detected during static analysis.
Package result defines the types used to represent error type usage patterns detected during static analysis.

Jump to

Keyboard shortcuts

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