errcheck alternatives and similar packages
Based on the "Code Analysis" category.
Alternatively, view errcheck alternatives based on common mentions on social networks and blogs.
-
Go Metalinter
Metalinter is a tool to automatically apply all static analysis tool and report their output in normalized form. -
go-cleanarch
Clean architecture validator for go, like a The Dependency Rule and interaction between packages in your Go projects. -
go-mod-outdated
Find outdated dependencies of your Go projects. go-mod-outdated provides a table view of the go list -u -m -json all command which lists all dependencies of a Go project and their available minor and patch updates. It also provides a way to filter indirect dependencies and dependencies without updates. -
goreturns
A gofmt/goimports-like tool for Go programmers that fills in Go return statements with zero values to match the func return types -
tickgit
Manage your repository's TODOs, tickets and checklists as config in your codebase. -
GoCover.io
GoCover.io offers the code coverage of any golang package as a service. -
apicompat
apicompat checks recent changes to a Go project for backwards incompatible changes -
ChainJacking
Find which of your direct GitHub dependencies is susceptible to RepoJacking attacks -
usestdlibvars
A linter that detect the possibility to use variables/constants from the Go standard library. -
tarp
tarp finds functions and methods without direct unit tests in Go source code. -
staticcheck
staticcheck is go vet on steroids, applying a ton of static analysis checks you might be used to from tools like ReSharper for C#. -
gosimple
gosimple is a linter for Go source code that specialises on simplifying code. -
Golint online
Lints online Go source files on GitHub, Bitbucket and Google Project Hosting using the golint package. -
unused
unused checks Go code for unused constants, variables, functions and types.
Access the most powerful time series database as a service
Do you think we are missing an alternative of errcheck or a related project?
README
errcheck
errcheck is a program for checking for unchecked errors in go programs.
Install
go install github.com/kisielk/[email protected]
errcheck requires Go 1.12 or newer, and depends on the package go/packages from the golang.org/x/tools repository.
Use
For basic usage, just give the package path of interest as the first argument:
errcheck github.com/kisielk/errcheck/testdata
To check all packages beneath the current directory:
errcheck ./...
Or check all packages in your $GOPATH and $GOROOT:
errcheck all
errcheck also recognizes the following command-line options:
The -tags
flag takes a space-separated list of build tags, just like go
build
. If you are using any custom build tags in your code base, you may need
to specify the relevant tags here.
The -asserts
flag enables checking for ignored type assertion results. It
takes no arguments.
The -blank
flag enables checking for assignments of errors to the
blank identifier. It takes no arguments.
go/analysis
The package provides Analyzer
instance that can be used with
go/analysis API.
Currently supported flags are blank
, assert
, exclude
, and excludeonly
.
Just as the API itself, the analyzer is exprimental and may change in the
future.
Excluding functions
Use the -exclude
flag to specify a path to a file containing a list of functions to
be excluded.
errcheck -exclude errcheck_excludes.txt path/to/package
The file should contain one function signature per line. The format for function signatures is
package.FunctionName
while for methods it's (package.Receiver).MethodName
for value receivers
and (*package.Receiver).MethodName
for pointer receivers. If the function name is followed by string of form (TYPE)
, then
the the function call is excluded only if the type of the first argument is TYPE
. It also accepts a special suffix
(os.Stdout)
and (os.Stderr)
, which excludes the function only when the first argument is a literal os.Stdout
or os.Stderr
.
An example of an exclude file is:
io/ioutil.ReadFile
io.Copy(*bytes.Buffer)
io.Copy(os.Stdout)
// Sometimes we don't care if a HTTP request fails.
(*net/http.Client).Do
By default, the exclude list is combined with an internal list for functions in
the Go standard library that have an error return type but are documented to never
return an error. To disable the built-in exclude list, pass the -excludeonly
flag.
Run errcheck in -verbose
mode to see the resulting list of added excludes.
When using vendored dependencies, specify the full import path. For example:
- Your project's import path is
example.com/yourpkg
- You've vendored
example.net/fmt2
asvendor/example.net/fmt2
- You want to exclude
fmt2.Println
from error checking
In this case, add this line to your exclude file:
example.com/yourpkg/vendor/example.net/fmt2.Println
Empty lines and lines starting with //
are ignored.
The deprecated method
The -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 print
variants in fmt
:
errcheck -ignore 'fmt:[FS]?[Pp]rint*' path/to/package
The -ignorepkg
flag takes a comma-separated list of package import paths
to ignore:
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
via -ignore
, and 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
The -ignoretests
flag disables checking of _test.go
files. It takes
no arguments.
Exit Codes
errcheck returns 1 if any problems were found in the checked files. It returns 2 if there were any other failures.
Editor Integration
Emacs
go-errcheck.el
integrates errcheck with Emacs by providing a go-errcheck
command
and customizable variables to automatically pass flags to errcheck.
Vim
vim-go can run errcheck via both its :GoErrCheck
and :GoMetaLinter
commands.