Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( DefaultWrapperFunctions = []PkgFuncs{ {Pkg: "github.com/pkg/errors", Funcs: []string{"New", "Errorf", "Wrap", "Wrapf", "WithStack"}}, } DefaultCleanFunctions = []PkgFuncs{ {Pkg: "github.com/pkg/errors", Funcs: []string{"WithMessage", "WithMessagef"}}, } DefaultThreshold = .5 DefaultMaxStackDepth = 5 )
View Source
var False = false
View Source
var True = true
Functions ¶
func NewAnalyzer ¶
Types ¶
type Assignment ¶
type Assignment struct {
Stmt *ast.AssignStmt
LPos int
RPos int
}
type Config ¶ added in v0.0.3
type Config struct {
// WrapperFunctions - 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, simply don't add them to the list.
WrapperFunctions []PkgFuncs `mapstructure:"wrapperFunctions" yaml:"wrapperFunctions"`
// CleanFunctions - list of functions that are considered to clean errors without stacktrace.
CleanFunctions []PkgFuncs `mapstructure:"cleanFunctions" yaml:"cleanFunctions"`
// Threshold in percentage for the number of branches returning wrapped errors to be considered a violation.
// Default value is 50%. Max is 100%.
// That means that if there are 3 sources of error that are non-wrapped and one that is wrapped, ErrStack will report an error.
// On the other hand, if there are 4 wrapped sources and only one non-wrapped source, ErrStack will not report an error.
Threshold float64 `mapstructure:"threshold" yaml:"threshold"`
// MaxStackDepth - how many stack frames to check for before giving up.
// May impact performance on large codebases and high value.
// Default value is 5. Max is 50.
MaxStackDepth int `mapstructure:"maxStackDepth" yaml:"maxStackDepth"`
}
func NewDefaultConfig ¶
func NewDefaultConfig() Config
type ErrStack ¶
type ErrStack struct {
// contains filtered or unexported fields
}
func NewErrStack ¶
type Func ¶
type FunctionInfo ¶
func (FunctionInfo) Contains ¶
func (f FunctionInfo) Contains(fn *Func) bool
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
func (*Plugin) GetLoadMode ¶
type Settings ¶
type Settings struct {
WrappedFunctions FunctionInfo
CleanFunctions FunctionInfo
Threshold float64
MaxStackDepth int
}
Click to show internal directories.
Click to hide internal directories.