How to exclude builtin functions?
Antonboom opened this issue · 2 comments
Antonboom commented
Hello!
# .golangci.yml
linters-settings:
errcheck:
exclude-functions:
- recover
$ cat example.go
package main
func main() {
defer func() {
recover()
}()
}
$ golangci-lint run example.go
example.go:5:10: Error return value is not checked (errcheck)
recover()
dtcaciuc commented
Hello,
Right now excluding recover() is not possible. I personally think that recover() failure is something you want to handle one way or another but, if you really want to ignore it, the simplest thing right now would be to use _ =
assignment.
Antonboom commented
Sometimes it's ok to ignore recover()
without explicit _
and it doesn't matter since recover()
is just a special case of a more general case.
Some examples from std:
func() {
defer func() { recover() }()
if m.Call(nil)[0].Bool() {
name := strings.TrimSuffix(tm.Name, "_")
fmt.Fprintf(w, " %s", name)
}
}()
func interfaceEqual(a, b interface{}) bool {
defer func() {
recover()
}()
return a == b
}
t.Run(fmt.Sprintf("%T(%v)", tc, tc), func(t *testing.T) {
defer func() {
recover()
}()
if errors.As(err, tc) {
t.Errorf("As(err, %T(%v)) = true, want false", tc, tc)
return
}
t.Errorf("As(err, %T(%v)) did not panic", tc, tc)
})
If you see no reason to support specifying any functions to exclude - OK