README.md
1# go-critic
2
3![Build Status](https://github.com/go-critic/go-critic/workflows/Go/badge.svg)
4[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/avelino/awesome-go#code-analysis)
5[![Go Report Card][go-report-image]][go-report-url]
6[![coverage][coverage-image]][coverage-url]
7[![PRs Welcome][pr-welcome-image]][pr-welcome-url]
8
9[go-report-image]: https://goreportcard.com/badge/github.com/go-critic/go-critic
10[go-report-url]: https://goreportcard.com/report/github.com/go-critic/go-critic
11[coverage-image]: https://coveralls.io/repos/github/go-critic/go-critic/badge.svg?branch=master
12[coverage-url]: https://coveralls.io/github/go-critic/go-critic?branch=master
13[pr-welcome-image]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
14[pr-welcome-url]: https://github.com/go-critic/go-critic/blob/master/CONTRIBUTING.md
15
16Highly extensible Go source code linter providing checks currently missing from other linters.
17
18![Logo](https://avatars1.githubusercontent.com/u/40007520?s=300&u=b44287d8845a63fb0102d5259710c11ea367bb13&v=4)
19
20There is never too much static code analysis. Try it out.
21
22## Features
23
24* Almost 100 diagnostics that check for [bugs](https://go-critic.github.io/overview#checkers-from-the-diagnostic-group), [performance](https://go-critic.github.io/overview#checkers-from-the-performance-group) and [style](https://go-critic.github.io/overview#checkers-from-the-style-group) issues
25* Extensible without re-compilation with [dynamic rules](https://quasilyte.dev/blog/post/ruleguard/)
26* Includes `#opinionated` checks with very strict and specific requirements
27* Self-documented: `gocritic doc <checkname>` gives a checker description
28
29## Documentation
30
31The latest documentation is available at [go-critic.github.io](https://go-critic.github.io/overview).
32
33## Installation
34
35For most users, using `go-critic` under [golangci-lint](https://github.com/golangci/golangci-lint) is enough.
36
37Precompiled `go-critic` binaries can be found at [releases](https://github.com/go-critic/go-critic/releases) page.
38
39Instructions below show how to build `go-critic` from sources.
40
41```bash
42GO111MODULE=on go get -v -u github.com/go-critic/go-critic/cmd/gocritic
43```
44
45If the command above does not work, you can try cloning this repository
46under your `GOPATH` and run `make gocritic`.
47
48## Usage
49
50Be sure `gocritic` executable is under your `$PATH`.
51
52Usage of **gocritic**: `gocritic [sub-command] [sub-command args...]`
53Run `gocritic` without arguments to get help output.
54
55```
56Supported sub-commands:
57 check - run linter over specified targets
58 $ gocritic check -help
59 $ gocritic check -v -enable='paramTypeCombine,unslice' strings bytes
60 $ gocritic check -v -enable='#diagnostic' -disable='#experimental,#opinionated' ./...
61 version - print linter version
62 $ gocritic version
63 doc - get installed checkers documentation
64 $ gocritic doc -help
65 $ gocritic doc
66 $ gocritic doc checkerName
67```
68
69`check` sub-command examples:
70
71```bash
72# Runs all stable checkers on `fmt` package:
73gocritic check fmt
74
75# Run all stable checkers on `pkg1` and `pkg2`
76gocritic check pkg1 pkg2
77
78# Run all stable checkers on `fmt` package and configure rangeExprCopy checker
79gocritic check -@rangeExprCopy.sizeThreshold 128 fmt
80
81# Runs specified checkers on `fmt` package:
82gocritic check -enable elseif,paramName fmt
83
84# Run all stable checkers on current dir and all its children recursively:
85gocritic check ./...
86
87# Like above, but without `appendAssign` check:
88gocritic check -disable=appendAssign ./...
89
90# Run all stable checkers on `foo.go` file:
91gocritic check foo.go
92
93# Run stable diagnostics over `strings` package:
94gocritic check -enable='#diagnostic' -disable='#experimental' strings
95
96# Run all stable and non-opinionated checks:
97gocritic check -enableAll -disable='#experimental,#opinionated' ./src/...
98```
99
100> To get a list of available checker parameters, run `gocritic doc <checkerName>`.
101
102In place of a single name, **tag** can be used. Tag is a named checkers group.
103
104Tags:
105* `#diagnostic` - kind of checks that detect various errors in code
106* `#style` - kind of checks that find style issues in code
107* `#performance` - kind of checks that detect potential performance issues in code
108* `#experimental` - check is under testing and development. Disabled by default
109* `#opinionated` - check can be unwanted for some people. Disabled by default
110* `#security` - kind of checks that find security issues in code
111
112## Contributing
113
114This project aims to be contribution-friendly.
115
116Our chats: [English](https://t.me/go_critic_eng) or
117[Russian](https://t.me/go_critic_ru)
118([Telegram website](https://telegram.org/))
119
120We're using an optimistic merging strategy most of the time.
121In short, this means that if your contribution has some flaws, we can still merge it and then
122fix them by ourselves. Experimental and work-in-progress checkers are isolated, so nothing bad will happen.
123
124Code style is the same as in Go project, see [CodeReviewComments](https://github.com/golang/go/wiki/codereviewcomments).
125
126See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.
127It also describes how to develop a new checker for the linter.
128