dependabot[bot] 24bcca2ebd
build(deps): bump github.com/polyfloyd/go-errorlint from 1.4.8 to 1.5.1 (#4690)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-05-02 22:43:02 +02:00

55 lines
1.3 KiB
Go

package errorlint
import (
"github.com/polyfloyd/go-errorlint/errorlint"
"golang.org/x/tools/go/analysis"
"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/goanalysis"
)
func New(cfg *config.ErrorLintSettings) *goanalysis.Linter {
var opts []errorlint.Option
if cfg != nil {
ae := toAllowPairs(cfg.AllowedErrors)
if len(ae) > 0 {
opts = append(opts, errorlint.WithAllowedErrors(ae))
}
aew := toAllowPairs(cfg.AllowedErrorsWildcard)
if len(aew) > 0 {
opts = append(opts, errorlint.WithAllowedWildcard(aew))
}
}
a := errorlint.NewAnalyzer(opts...)
cfgMap := map[string]map[string]any{}
if cfg != nil {
cfgMap[a.Name] = map[string]any{
"errorf": cfg.Errorf,
"errorf-multi": cfg.ErrorfMulti,
"asserts": cfg.Asserts,
"comparison": cfg.Comparison,
}
}
return goanalysis.NewLinter(
a.Name,
"errorlint is a linter for that can be used to find code "+
"that will cause problems with the error wrapping scheme introduced in Go 1.13.",
[]*analysis.Analyzer{a},
cfgMap,
).WithLoadMode(goanalysis.LoadModeTypesInfo)
}
func toAllowPairs(data []config.ErrorLintAllowPair) []errorlint.AllowPair {
var pairs []errorlint.AllowPair
for _, allowedError := range data {
pairs = append(pairs, errorlint.AllowPair(allowedError))
}
return pairs
}