Skip to content

Commit e8cc4d2

Browse files
feat: add config option to extend ignoreSigs (#56)
The use case for this is I would like to add another signature to ignore, but still being able to rely on the default list is convenient, since I don't have to manually sync my list with any future changes to the defaults. closes #54
1 parent 4a8f079 commit e8cc4d2

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ ignoreSigs:
4040
- .WithMessagef(
4141
- .WithStack(
4242

43+
44+
# An array of strings specifying additional substrings of signatures to ignore.
45+
# Unlike ignoreSigs, this option extends the default set (or the set specified
46+
# in ignoreSigs) without replacing it entirely. This allows you to add specific
47+
# signatures to the ignore list while retaining the defaults or any items in
48+
# ignoreSigs.
49+
extraIgnoreSigs:
50+
- .CustomError(
51+
- .SpecificWrap(
52+
4353
# An array of strings which specify regular expressions of signatures to ignore.
4454
# This is similar to the ignoreSigs configuration above, but gives slightly more
4555
# flexibility.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extraIgnoreSigs:
2+
- json.Marshal(
3+
4+
ignoreSigs:
5+
- errors.New(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"errors"
6+
)
7+
8+
func main() {
9+
do()
10+
}
11+
12+
func do() error {
13+
// no issue with function in 'extraIgnoreSigs'
14+
_, err := json.Marshal(struct{}{})
15+
if err != nil {
16+
return err
17+
}
18+
19+
// expect issue for function that is not ignored
20+
res := struct{}{}
21+
if err := json.Unmarshal([]byte("{}"), &res); err != nil {
22+
return err // want `error returned from external package is unwrapped`
23+
}
24+
25+
// no issue with function in 'ignoreSigs'
26+
return errors.New("Some error")
27+
}

wrapcheck/wrapcheck.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ type WrapcheckConfig struct {
4444
// list to your config.
4545
IgnoreSigs []string `mapstructure:"ignoreSigs" yaml:"ignoreSigs"`
4646

47+
// ExtraIgnoreSigs defines an additional list of signatures to ignore, on
48+
// top of IgnoreSigs.
49+
ExtraIgnoreSigs []string `mapstructure:"extraIgnoreSigs" yaml:"extraIgnoreSigs"`
50+
4751
// IgnoreSigRegexps defines a list of regular expressions which if matched
4852
// to the signature of the function call returning the error, will be ignored. This
4953
// allows you to specify functions that wrapcheck will not report as
@@ -276,7 +280,7 @@ func reportUnwrapped(
276280

277281
// Check for ignored signatures
278282
fnSig := pass.TypesInfo.ObjectOf(sel.Sel).String()
279-
if contains(cfg.IgnoreSigs, fnSig) {
283+
if contains(cfg.IgnoreSigs, fnSig) || contains(cfg.ExtraIgnoreSigs, fnSig) {
280284
return
281285
} else if containsMatch(regexpsSig, fnSig) {
282286
return

0 commit comments

Comments
 (0)