Git Product home page Git Product logo

errcheck's Introduction

errcheck

========

errcheck is a program for checking for unchecked errors in go programs.

Build Status

Install

go get -u github.com/kisielk/errcheck

errcheck requires Go 1.5 and depends on the package go/loader 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

Additionally, the following flags are available.

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.

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.

Cgo

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 kisielk#16 for more details.

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

go-errcheck-vim integrates errcheck with Vim's quickfix.

errcheck's People

Contributors

amerine avatar autarch avatar bdarnell avatar benbjohnson avatar cookieo9 avatar cskr avatar dmitshur avatar dominikh avatar eapache avatar foubarre avatar isbadawi avatar kisielk avatar mattn avatar museun avatar oalders avatar robfig avatar zimmski avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.