-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ignore signatures via regex (#21)
* Ignore error signatures via regexp * Update docs with new ignoreSigRegexps configuration * Fix docs typo
- Loading branch information
Showing
5 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ignoreSigRegexps: | ||
- json\.[a-zA-Z0-9_-]+\( | ||
- ^func[\s]+\(.+wrapcheck.+\.error.*\) | ||
- \.NewMod[\d]+Error\( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
type errorer interface { | ||
Decode(v interface{}) error | ||
} | ||
|
||
func main() { | ||
do1() | ||
|
||
d := json.NewDecoder(strings.NewReader("hello world")) | ||
do2(d) | ||
|
||
do3(5) | ||
do4(5) | ||
} | ||
|
||
func do1() error { | ||
_, err := json.Marshal(struct{}{}) // external package ignored by package+method-name regexp | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func do2(fn errorer) error { | ||
var str string | ||
err := fn.Decode(&str) // interface ignored by regexp | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func do3(i int) error { | ||
if i%2 == 0 { | ||
return errors.NewMod2Error(fmt.Sprintf("%d is an even number", i)) // external package ignored by method-name regexp | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func do4(i int) error { | ||
if i%3 == 0 { | ||
return errors.NewMod3Error(fmt.Sprintf("%d is divisible by 3", i)) // external package ignored by method-name regexp | ||
} | ||
|
||
return nil | ||
} |
25 changes: 25 additions & 0 deletions
25
wrapcheck/testdata/config_ignoreSigRegexps/src/github.com/pkg/errors/errors.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package errors | ||
|
||
type Mod2Error struct { | ||
msg string | ||
} | ||
|
||
func NewMod2Error(msg string) error { | ||
return &Mod2Error{msg} | ||
} | ||
|
||
func (e Mod2Error) Error() string { | ||
return e.msg | ||
} | ||
|
||
type Mod3Error struct { | ||
msg string | ||
} | ||
|
||
func NewMod3Error(msg string) error { | ||
return &Mod3Error{msg} | ||
} | ||
|
||
func (e Mod3Error) Error() string { | ||
return e.msg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters