Skip to content

Commit fe161a0

Browse files
committed
Ignore pkg/errors sigs
1 parent 148861c commit fe161a0

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

wrapcheck/wrapcheck.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import (
44
"go/ast"
55
"go/token"
66
"go/types"
7+
"strings"
78

89
"golang.org/x/tools/go/analysis"
910
)
1011

11-
var ignoredIDs = []string{
12-
"func fmt.Errorf(format string, a ...interface{}) error",
13-
"func errors.New(text string) error",
14-
"func errors.Unwrap(err error) error",
12+
var ignoredSigs = []string{
13+
"fmt.Errorf(",
14+
"errors.New(",
15+
"errors.Unwrap(",
16+
".Wrap(",
17+
".Wrapf(",
18+
".WithMessage(",
1519
}
1620

1721
var Analyzer = &analysis.Analyzer{
@@ -177,7 +181,7 @@ func isFromOtherPkg(pass *analysis.Pass, sel *ast.SelectorExpr) bool {
177181
// that it's an identifier from the same package
178182
if pass.Pkg.Path() == fn.Pkg().Path() {
179183
return false
180-
} else if contains(ignoredIDs, fn.String()) {
184+
} else if contains(ignoredSigs, fn.String()) {
181185
return false
182186
}
183187

@@ -237,7 +241,7 @@ func prevErrAssign(pass *analysis.Pass, file *ast.File, returnIdent *ast.Ident)
237241

238242
func contains(slice []string, el string) bool {
239243
for _, s := range slice {
240-
if s == el {
244+
if strings.Contains(el, s) {
241245
return true
242246
}
243247
}

0 commit comments

Comments
 (0)