errcheck is a program for checking for unchecked errors in go programs.
go get -u github.com/kisielk/errcheck
errcheck requires Go 1.5 or newer and depends on the package go/loader from the golang.org/x/tools repository.
For basic usage, just give the package path of interest as the first argument:
To check all packages beneath the current directory:
Or check all packages in your $GOPATH and $GOROOT:
Additionally, the following flags are available.
-ignore flag takes a comma-separated list of pairs of the form package:regex.
For each package, the regex describes which functions to ignore within that package.
The package may be omitted to have the regex apply to all packages.
For example, you may wish to ignore common operations like Read and Write:
errcheck -ignore '[rR]ead|[wW]rite' path/to/package
or you may wish to ignore common functions like the
errcheck -ignore 'fmt:[FS]?[Pp]rint*' path/to/package
-ignorepkg flag takes a comma-separated list of package import paths
errcheck -ignorepkg 'fmt,encoding/binary' path/to/package
Note that this is equivalent to:
errcheck -ignore 'fmt:.*,encoding/binary:.*' path/to/package
If a regex is provided for a package
pkg also appears
in the list of packages passed to
-ignorepkg, the latter takes precedence;
that is, all functions within
pkg will be ignored.
Note that by default the
fmt package is ignored entirely, unless a regex is
specified for it. To disable this, specify a regex that matches nothing:
errcheck -ignore 'fmt:a^' path/to/package
-ignoretests flag disables checking of
_test.go files. It takes
-tags flag takes a space-separated list of build tags, just like
build. If you are using any custom build tags in your code base, you may need
to specify the relevant tags here.
-asserts flag enables checking for ignored type assertion results. It
takes no arguments.
-blank flag enables checking for assignments of errors to the
blank identifier. It takes no arguments.
Currently errcheck is unable to check packages that
import "C" due to limitations
in the importer.
However, you can use errcheck on packages that depend on those which use cgo. In
order for this to work you need to
go install the cgo dependencies before running
errcheck on the dependant packages.
See https://github.com/kisielk/errcheck/issues/16 for more details.
errcheck returns 1 if any problems were found in the checked files. It returns 2 if there were any other failures.
integrates errcheck with Emacs by providing a
and customizable variables to automatically pass flags to errcheck.
vim-go can run errcheck via both its