config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// YamlConfig is the flag for loading all packages.
	YamlConfig = "yaml-config"
	// Debug is the flag for debug logging.
	Debug = "debug"
)
View Source
const (
	DefaultMaxDepth      = 100
	DefaultIncludeVendor = true
)

Variables

View Source
var (
	DefaultWrapperFunctions = []PkgFunctions{
		{
			Pkg: "github.com/pkg/errors",
			Names: []string{
				"New", "Errorf", "Wrap", "Wrapf", "WithStack",
			},
			ReplaceWith:       "WithMessage",
			ReplaceWithFormat: "WithMessagef",
		},
	}
	DefaultCleanFunctions = []PkgFunctions{
		{Pkg: "github.com/pkg/errors", Names: []string{
			"WithMessage", "WithMessagef",
		}},
		{Pkg: "errors", Names: []string{
			"New",
		}},
		{Pkg: "fmt", Names: []string{
			"Errorf",
		}},
	}
	DefaultExcludePatterns []string
)
View Source
var Analyzer = &analysis.Analyzer{
	Name:       "errstack_config",
	Doc:        _doc,
	Run:        helpers.WrapRun(run),
	Flags:      newFlagSet(),
	ResultType: reflect.TypeOf((*helpers.Result[*Config])(nil)),
}

Functions

This section is empty.

Types

type Config

type Config struct {
	// WrapperFunctions - a list of functions that are considered to wrap errors.
	// If you're using some fancy error wrapping library like github.com/pkg/errors,
	// you may want to add it to this list.
	// If you want to ignore some functions, don't add them to the list.
	WrapperFunctions PkgsFunctions `mapstructure:"wrapperFunctions" yaml:"wrapperFunctions,omitempty"`
	// CleanFunctions - a list of functions that are considered to clean errors without stacktrace.
	CleanFunctions PkgsFunctions `mapstructure:"cleanFunctions" yaml:"cleanFunctions,omitempty"`

	// Performance tuning options
	IncludeVendor   bool     `mapstructure:"includeVendor" yaml:"includeVendor,omitempty"`
	ExcludePatterns []string `mapstructure:"excludePatterns" yaml:"excludePatterns,omitempty"`
	MaxDepth        int      `mapstructure:"maxDepth" yaml:"maxDepth,omitempty"`

	GoRoot  string `mapstructure:"-" yaml:"-"`
	WorkDir string `mapstructure:"-" yaml:"-"`
	Debug   bool   `mapstructure:"__debug" yaml:"__debug,omitempty"`
}

func NewDefaultConfig

func NewDefaultConfig() *Config

func (*Config) GetDirPkgPath

func (cfg *Config) GetDirPkgPath(dir string) string

func (*Config) GetPkgPath

func (cfg *Config) GetPkgPath(dir string) string

type PkgFunctions

type PkgFunctions struct {
	Pkg               string   `mapstructure:"pkg" yaml:"pkg"`
	Names             []string `mapstructure:"names" yaml:"names"`
	ReplaceWith       string   `mapstructure:"replaceWith" yaml:"replaceWith"`
	ReplaceWithFormat string   `mapstructure:"replaceWithFormat" yaml:"replaceWithFormat"`
}

type PkgsFunctions

type PkgsFunctions []PkgFunctions

func (PkgsFunctions) Match

func (pkgFunctions PkgsFunctions) Match(pkg, name string) bool

Match returns true if a function matches any of the package functions.

func (PkgsFunctions) ReplaceWith added in v0.3.0

func (pkgFunctions PkgsFunctions) ReplaceWith(pkg, name, text string) string

ReplaceWith returns new formatted node with replaced function name.

func (PkgsFunctions) ReplaceWithFunction added in v0.3.0

func (pkgFunctions PkgsFunctions) ReplaceWithFunction(pkg, name, text string) string

ReplaceWithFunction returns new formatted node with replaced function name.

Jump to

Keyboard shortcuts

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