wrapcheck

package
v2.8.3 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 8 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultIgnoreSigs = []string{
	".Errorf(",
	"errors.New(",
	"errors.Unwrap(",
	"errors.Join(",
	".Wrap(",
	".Wrapf(",
	".WithMessage(",
	".WithMessagef(",
	".WithStack(",
}

Functions

func NewAnalyzer

func NewAnalyzer(cfg WrapcheckConfig) *analysis.Analyzer

Types

type WrapcheckConfig

type WrapcheckConfig struct {
	// IgnoreSigs defines a list of substrings which if contained within the
	// signature of the function call returning the error, will be ignored. This
	// allows you to specify functions that wrapcheck will not report as
	// unwrapped.
	//
	// For example, an ignoreSig of `[]string{"errors.New("}` will ignore errors
	// returned from the stdlib package error's function:
	//
	//   `func errors.New(message string) error`
	//
	// Due to the signature containing the substring `errors.New(`.
	//
	// Note: Setting this value will intentionally override the default ignored
	// sigs. To achieve the same behaviour as default, you should add the default
	// list to your config.
	IgnoreSigs []string `mapstructure:"ignoreSigs" yaml:"ignoreSigs"`

	// IgnoreSigRegexps defines a list of regular expressions which if matched
	// to the signature of the function call returning the error, will be ignored. This
	// allows you to specify functions that wrapcheck will not report as
	// unwrapped.
	//
	// For example, an ignoreSigRegexp of `[]string{"\.New.*Err\("}“ will ignore errors
	// returned from any signature whose method name starts with "New" and ends with "Err"
	// due to the signature matching the regular expression `\.New.*Err\(`.
	//
	// Note that this is similar to the ignoreSigs configuration, but provides
	// slightly more flexibility in defining rules by which signatures will be
	// ignored.
	IgnoreSigRegexps []string `mapstructure:"ignoreSigRegexps" yaml:"ignoreSigRegexps"`

	// IgnorePackageGlobs defines a list of globs which, if matching the package
	// of the function returning the error, will ignore the error when doing
	// wrapcheck analysis.
	//
	// This is useful for broadly ignoring packages and subpackages from wrapcheck
	// analysis. For example, to ignore all errors from all packages and
	// subpackages of "encoding" you may include the configuration:
	//
	// -- .wrapcheck.yaml
	// ignorePackageGlobs:
	// - encoding/*
	IgnorePackageGlobs []string `mapstructure:"ignorePackageGlobs" yaml:"ignorePackageGlobs"`

	// IgnoreInterfaceRegexps defines a list of regular expressions which, if matched
	// to a underlying interface name, will ignore unwrapped errors returned from a
	// function whose call is defined on the given interface.
	//
	// For example, an ignoreInterfaceRegexps of `[]string{"Transac(tor|tion)"}` will ignore errors
	// returned from any function whose call is defined on a interface named 'Transactor'
	// or 'Transaction' due to the name matching the regular expression `Transac(tor|tion)`.
	IgnoreInterfaceRegexps []string `mapstructure:"ignoreInterfaceRegexps" yaml:"ignoreInterfaceRegexps"`
}

WrapcheckConfig is the set of configuration values which configure the behaviour of the linter.

func NewDefaultConfig

func NewDefaultConfig() WrapcheckConfig

Jump to

Keyboard shortcuts

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