https://github.com/gostaticanalysis/nilerr
Analyzer: nilerr checks returning nil when err is not nil
https://github.com/gostaticanalysis/nilerr
analyzer golang staticanalysis
Last synced: 25 days ago
JSON representation
Analyzer: nilerr checks returning nil when err is not nil
- Host: GitHub
- URL: https://github.com/gostaticanalysis/nilerr
- Owner: gostaticanalysis
- License: mit
- Created: 2019-03-08T08:22:48.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-09-28T16:14:43.000Z (5 months ago)
- Last Synced: 2025-09-28T18:19:02.361Z (5 months ago)
- Topics: analyzer, golang, staticanalysis
- Language: Go
- Homepage:
- Size: 30.3 KB
- Stars: 63
- Watchers: 3
- Forks: 12
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nilerr
[![pkg.go.dev][gopkg-badge]][gopkg]
`nilerr` finds code which returns nil even though it checks that error is not nil.
```go
func f() error {
err := do()
if err != nil {
return nil // miss
}
}
```
`nilerr` also finds code which returns error even though it checks that error is nil.
```go
func f() error {
err := do()
if err == nil {
return err // miss
}
}
```
`nilerr` ignores code which has a miss with ignore comment.
```go
func f() error {
err := do()
if err != nil {
//lint:ignore nilerr reason
return nil // ignore
}
}
```
## How to use
```
$ go install github.com/gostaticanalysis/nilerr/cmd/nilerr@latest
$ nilerr ./...
```
[gopkg]: https://pkg.go.dev/github.com/gostaticanalysis/nilerr
[gopkg-badge]: https://pkg.go.dev/badge/github.com/gostaticanalysis/nilerr?status.svg