gostaticanalysis/nilerr

Analyzer: nilerr checks returning nil when err is not nil

Go

63

34 commits

updated Sep 28, 2025

See the code

README

nilerr

pkg.go.dev

nilerr finds code which returns nil even though it checks that error is not nil.

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.

func f() error {
	err := do()
	if err == nil {
		return err // miss
	}
}

nilerr ignores code which has a miss with ignore comment.

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 ./...
analyzer
golang
staticanalysis

Significant stargazers

Dustin Decker

146 followers · starred Feb 2022

Marat Reimers

38 followers · starred Jun 2022

Karim ElDeeb

20 followers · starred Apr 2021

gostaticanalysis/nilerr

Analyzer: nilerr checks returning nil when err is not nil

Go

63

34 commits

updated Sep 28, 2025

See the code

README

nilerr

pkg.go.dev

nilerr finds code which returns nil even though it checks that error is not nil.

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.

func f() error {
	err := do()
	if err == nil {
		return err // miss
	}
}

nilerr ignores code which has a miss with ignore comment.

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 ./...
analyzer
golang
staticanalysis

Significant stargazers

Dustin Decker

146 followers · starred Feb 2022

Marat Reimers

38 followers · starred Jun 2022

Karim ElDeeb

20 followers · starred Apr 2021

Languages

Go

100.0%