/go-critic

The most opinionated Go source code linter

Primary LanguageGoMIT LicenseMIT

go-critic

Build Status Go Report Card

Go source code linter that brings checks that are currently not implemented in other linters.

Logo

Project goals:

  • Provide as much useful checks as possible. We're prototyping and experimenting here

  • When specific check implementation is mature and proven useful, propose it's integration into other linter

  • If good checker can't find a better home, it stays here

We say yes! to most checks that feel right and can help someone.

You can use this tool to make whole codebase checks from time to time.

There is never too much static code analysis. Try it out.

Documentation

Latest documentation is available at go-critic.github.io.

Installation

go get -u github.com/go-critic/go-critic/...

Usage

Be sure gocritic executable is under your $PATH.

Usage of gocritic: gocritic [sub-command] [sub-command args...] Run gocritic without arguments to get help output.

Examples:

Command Description
gocritic check-package fmt Runs all stable checkers on fmt package
gocritic check-package pkg1 pkg2 Run all stable checkers on pkg1 and pkg2
gocritic check-package -enable elseif,param-name fmt Runs specified checkers on fmt package
gocritic check-project $GOROOT/src Run all stable checkers on entire GOROOT
gocritic check-project $GOPATH/src Run all stable checkers on entire GOPATH
gocritic check-project $GOPATH/src/foo Run all stable checkers on all packages under GOPATH/src/foo

Note: check-project $GOPATH/xyz won't work it you're using multiple paths under GOPATH.

Contributing

This project aims to be contributing-friendly.

We're using optimistic merging strategy most of the time. In short, this means that if your contribution has some flaws, we can still merge it and then fix them by ourselves. Experimental and work-in-progress checkers are isolated, so nothing bad will happen.

Code style is the same as in Go project, see CodeReviewComments.

See CONTRIBUTING.md for more details. It also describes how to develop a new checker for the linter.