github.com/bdarnell/errcheck@v0.0.0-20150224205548-d278a1ad0695/README.md (about) 1 # errcheck 2 ======== 3 4 errcheck is a program for checking for unchecked errors in go programs. 5 6 [![Build Status](https://travis-ci.org/kisielk/errcheck.png?branch=master)](https://travis-ci.org/kisielk/errcheck) 7 8 ## Install 9 10 go get github.com/kisielk/errcheck 11 12 errcheck requires Go 1.4 and depends on the go/types package from the golang.org/x/tools repository. 13 14 ## Use 15 16 For basic usage, just give the package path of interest as the first 17 argument: 18 19 errcheck github.com/kisielk/errcheck/testdata 20 21 There are currently three flags: `-ignore`, `-ignorepkg` and `-blank` 22 23 The `-ignore` flag takes a comma-separated list of pairs of the form package:regex. 24 For each package, the regex describes which functions to ignore within that package. 25 The package may be omitted to have the regex apply to all packages. 26 27 For example, you may wish to ignore common operations like Read and Write: 28 29 errcheck -ignore '[rR]ead|[wW]rite' path/to/package 30 31 or you may wish to ignore common functions like the `print` variants in `fmt`: 32 33 errcheck -ignore 'fmt:[FS]?[Pp]rint*' path/to/package 34 35 The `-ignorepkg` flag takes a comma-separated list of package import paths 36 to ignore: 37 38 errcheck -ignorepkg 'fmt,encoding/binary' path/to/package 39 40 Note that this is equivalent to: 41 42 errcheck -ignore 'fmt:.*,encoding/binary:.*' path/to/package 43 44 If a regex is provided for a package `pkg` via `-ignore`, and `pkg` also appears 45 in the list of packages passed to `-ignorepkg`, the latter takes precedence; 46 that is, all functions within `pkg` will be ignored. 47 48 Note that by default the `fmt` package is ignored entirely, unless a regex is 49 specified for it. To disable this, specify a regex that matches nothing: 50 51 errcheck -ignore 'fmt:a^' path/to/package 52 53 The `-blank` flag enables checking for assignments of errors to the 54 blank identifier. It takes no arguments. 55 56 An example of using errcheck to check the go standard library packages: 57 58 errcheck -ignore 'Close|[wW]rite.*|Flush|Seek|[rR]ead.*' std > stdlibcheck 59 60 Or check all packages in your $GOPATH and $GOROOT: 61 62 errcheck all > allcheck 63 64 To check all packages beneath the current directory: 65 66 errcheck ./... 67 68 ## Cgo 69 70 Currently errcheck is unable to check packages that `import "C"` due to limitations 71 in the importer. 72 73 However, you can use errcheck on packages that depend on those which use cgo. In 74 order for this to work you need to `go install` the cgo dependencies before running 75 errcheck on the dependant packages. 76 77 See https://github.com/kisielk/errcheck/issues/16 for more details. 78 79 ## Exit Codes 80 81 errcheck returns 1 if any problems were found in the checked files. 82 It returns 2 if there were any other failures. 83 84 # Editor Integration 85 86 ## Emacs 87 88 [go-errcheck.el](https://github.com/dominikh/go-errcheck.el) 89 integrates errcheck with Emacs by providing a `go-errcheck` command 90 and customizable variables to automatically pass flags to errcheck. 91 92 ## Vim 93 94 [go-errcheck-vim](https://github.com/mattn/go-errcheck-vim) 95 integrates errcheck with Vim's quickfix.