nilerr

package module
v0.0.0-...-015671e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2025 License: MIT Imports: 9 Imported by: 0

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 ./...

Documentation

Index

Constants

View Source
const Doc = "nilerr checks returning nil when err is not nil"

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "nilerr",
	Doc:  Doc,
	Run:  run,
	Requires: []*analysis.Analyzer{
		buildssa.Analyzer,
		commentmap.Analyzer,
	},
}

Functions

This section is empty.

Types

type ReferrersHolder

type ReferrersHolder interface {
	Referrers() *[]ssa.Instruction
}

Directories

Path Synopsis
cmd
nilerr command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL