github.com/be-b10g/golangci-lint@v1.17.2/README.md (about) 1 # GolangCI-Lint 2 3 [![Build Status](https://travis-ci.com/golangci/golangci-lint.svg?branch=master)](https://travis-ci.com/golangci/golangci-lint) 4 [![GolangCI](https://golangci.com/badges/github.com/golangci/golangci-lint.svg)](https://golangci.com) 5 6 GolangCI-Lint is a linters aggregator. It's fast: on average [5 times faster](#performance) than gometalinter. 7 It's [easy to integrate and use](#command-line-options), has [nice output](#quick-start) and has a minimum number of false positives. It supports go modules. 8 9 GolangCI-Lint has [integrations](#editor-integration) with VS Code, GNU Emacs, Sublime Text. 10 11 Follow the news and releases on our [twitter](https://twitter.com/golangci) and our [blog](https://medium.com/golangci). 12 13 Sponsored by [GolangCI.com](https://golangci.com): SaaS service for running linters on Github pull requests. Free for Open Source. 14 15 <a href="https://golangci.com/"><img src="docs/go.png" width="250px"></a> 16 17 * [Demo](#demo) 18 * [Install](#install) 19 * [Trusted By](#trusted-by) 20 * [Quick Start](#quick-start) 21 * [Editor Integration](#editor-integration) 22 * [Comparison](#comparison) 23 * [Performance](#performance) 24 * [Internals](#internals) 25 * [Supported Linters](#supported-linters) 26 * [Configuration](#configuration) 27 * [False Positives](#false-positives) 28 * [FAQ](#faq) 29 * [Thanks](#thanks) 30 * [Changelog](#changelog) 31 * [Future Plans](#future-plans) 32 * [Contact Information](#contact-information) 33 34 ## Demo 35 36 <p align="center"> 37 <img src="./docs/demo.svg" width="100%"> 38 </p> 39 40 Short 1.5 min video demo of analyzing [beego](https://github.com/astaxie/beego). 41 [![asciicast](https://asciinema.org/a/183662.png)](https://asciinema.org/a/183662) 42 43 ## Install 44 45 ### CI Installation 46 47 Most installations are done for CI (travis, circleci etc). It's important to have reproducible CI: 48 don't start to fail all builds at the same time. With golangci-lint this can happen if you 49 use `--enable-all` and a new linter is added or even without `--enable-all`: when one upstream linter is upgraded. 50 51 It's highly recommended to install a fixed version of golangci-lint. 52 Releases are available on the [releases page](https://github.com/golangci/golangci-lint/releases). 53 54 The recommended way to install golangci-lint (replace `vX.Y.Z` with the latest 55 version from the [releases page](https://github.com/golangci/golangci-lint/releases)): 56 57 ```bash 58 # binary will be $(go env GOPATH)/bin/golangci-lint 59 curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin vX.Y.Z 60 61 # or install it into ./bin/ 62 curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s vX.Y.Z 63 64 # In alpine linux (as it does not come with curl by default) 65 wget -O - -q https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s vX.Y.Z 66 67 golangci-lint --version 68 ``` 69 70 As a fallback you can also use `raw.githubusercontent.com` 71 72 ```bash 73 # binary will be $(go env GOPATH)/bin/golangci-lint 74 curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin vX.Y.Z 75 76 # or install it into ./bin/ 77 curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s vX.Y.Z 78 79 # In alpine linux (as it does not come with curl by default) 80 wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s vX.Y.Z 81 82 golangci-lint --version 83 ``` 84 85 Periodically update version of golangci-lint: the project is under active development 86 and is constantly being improved. But please always check for newly found issues and 87 update if needed. 88 89 ### Local Installation 90 91 Local installation is not recommended for your CI pipeline. Only install the linter this way in a local development environment. 92 93 #### Windows, MacOS and Linux 94 95 ```bash 96 go get -u github.com/golangci/golangci-lint/cmd/golangci-lint 97 ``` 98 99 With `go1.11` or later you can get a particular version 100 101 ```bash 102 GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.17.1 103 ``` 104 105 #### MacOS 106 107 You can also install it on MacOS using [brew](https://brew.sh/): 108 109 ```bash 110 brew install golangci/tap/golangci-lint 111 brew upgrade golangci/tap/golangci-lint 112 ``` 113 114 #### `--version` 115 116 If you need your local `golangci-lint --version` to show proper version additionally run: 117 118 ```bash 119 cd $(go env GOPATH)/src/github.com/golangci/golangci-lint/cmd/golangci-lint 120 go install -ldflags "-X 'main.version=$(git describe --tags)' -X 'main.commit=$(git rev-parse --short HEAD)' -X 'main.date=$(date)'" 121 ``` 122 123 On Windows, you can run the above commands with Git Bash, which comes with [Git for Windows](https://git-scm.com/download/win). 124 125 ## Trusted By 126 127 The following companies/products use golangci-lint: 128 129 * [Google](https://github.com/GoogleContainerTools/skaffold) 130 * [Facebook](https://github.com/facebookincubator/fbender) 131 * [Red Hat OpenShift](https://github.com/openshift/telemeter) 132 * [Yahoo](https://github.com/yahoo/yfuzz) 133 * [IBM](https://github.com/ibm-developer/ibm-cloud-env-golang) 134 * [Xiaomi](https://github.com/XiaoMi/soar) 135 * [Samsung](https://github.com/samsung-cnct/cluster-api-provider-ssh) 136 * [Arduino](https://github.com/arduino/arduino-cli) 137 * [Eclipse Foundation](https://github.com/eclipse/che-go-jsonrpc) 138 * [WooCart](https://github.com/woocart/gsutil) 139 * [Percona](https://github.com/percona/pmm-managed) 140 * [Serverless](https://github.com/serverless/event-gateway) 141 * [ScyllaDB](https://github.com/scylladb/gocqlx) 142 * [NixOS](https://github.com/NixOS/nixpkgs-channels) 143 * [The New York Times](https://github.com/NYTimes/encoding-wrapper) 144 * [Istio](https://github.com/istio/istio) 145 146 The following great projects use golangci-lint: 147 148 * [goreleaser/goreleaser](https://github.com/goreleaser/goreleaser) 149 * [tsuru/tsuru](https://github.com/tsuru/tsuru) 150 * [xenolf/lego](https://github.com/xenolf/lego) 151 * [go-swagger/go-swagger](https://github.com/go-swagger/go-swagger) 152 * [kubernetes-sigs/kustomize](https://github.com/kubernetes-sigs/kustomize) 153 * [virtual-kubelet/virtual-kubelet](https://github.com/virtual-kubelet/virtual-kubelet) 154 * [alecthomas/participle](https://github.com/alecthomas/participle) 155 * [asobti/kube-monkey](https://github.com/asobti/kube-monkey) 156 * [getantibody/antibody](https://github.com/getantibody/antibody) 157 * [banzaicloud/pipeline](https://github.com/banzaicloud/pipeline) 158 * [posener/complete](https://github.com/posener/complete) 159 * [y0ssar1an/q](https://github.com/y0ssar1an/q) 160 * [segmentio/terraform-docs](https://github.com/segmentio/terraform-docs) 161 162 ## Quick Start 163 164 To run golangci-lint execute: 165 166 ```bash 167 golangci-lint run 168 ``` 169 170 It's an equivalent of executing: 171 172 ```bash 173 golangci-lint run ./... 174 ``` 175 176 You can choose which directories and files to analyze: 177 178 ```bash 179 golangci-lint run dir1 dir2/... dir3/file1.go 180 ``` 181 182 Directories are NOT analyzed recursively. To analyze them recursively append `/...` to their path. 183 184 GolangCI-Lint can be used with zero configuration. By default the following linters are enabled: 185 186 ```bash 187 $ golangci-lint help linters 188 Enabled by default linters: 189 deadcode: Finds unused code [fast: true, auto-fix: false] 190 errcheck: Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: true, auto-fix: false] 191 gosimple: Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false] 192 govet (vet, vetshadow): Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false] 193 ineffassign: Detects when assignments to existing variables are not used [fast: true, auto-fix: false] 194 staticcheck: Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false] 195 structcheck: Finds unused struct fields [fast: true, auto-fix: false] 196 typecheck: Like the front-end of a Go compiler, parses and type-checks Go code [fast: true, auto-fix: false] 197 unused: Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false] 198 varcheck: Finds unused global variables and constants [fast: true, auto-fix: false] 199 ``` 200 201 and the following linters are disabled by default: 202 203 ```bash 204 $ golangci-lint help linters 205 ... 206 Disabled by default linters: 207 bodyclose: checks whether HTTP response body is closed successfully [fast: false, auto-fix: false] 208 depguard: Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false] 209 dupl: Tool for code clone detection [fast: true, auto-fix: false] 210 gochecknoglobals: Checks that no globals are present in Go code [fast: true, auto-fix: false] 211 gochecknoinits: Checks that no init functions are present in Go code [fast: true, auto-fix: false] 212 goconst: Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false] 213 gocritic: The most opinionated Go source code linter [fast: true, auto-fix: false] 214 gocyclo: Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false] 215 gofmt: Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true] 216 goimports: Goimports does everything that gofmt does. Additionally it checks unused imports [fast: true, auto-fix: true] 217 golint: Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes [fast: true, auto-fix: false] 218 gosec (gas): Inspects source code for security problems [fast: true, auto-fix: false] 219 interfacer: Linter that suggests narrower interface types [fast: false, auto-fix: false] 220 lll: Reports long lines [fast: true, auto-fix: false] 221 maligned: Tool to detect Go structs that would take less memory if their fields were sorted [fast: true, auto-fix: false] 222 misspell: Finds commonly misspelled English words in comments [fast: true, auto-fix: true] 223 nakedret: Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false] 224 prealloc: Finds slice declarations that could potentially be preallocated [fast: true, auto-fix: false] 225 scopelint: Scopelint checks for unpinned variables in go programs [fast: true, auto-fix: false] 226 stylecheck: Stylecheck is a replacement for golint [fast: false, auto-fix: false] 227 unconvert: Remove unnecessary type conversions [fast: true, auto-fix: false] 228 unparam: Reports unused function parameters [fast: false, auto-fix: false] 229 ``` 230 231 Pass `-E/--enable` to enable linter and `-D/--disable` to disable: 232 233 ```bash 234 golangci-lint run --disable-all -E errcheck 235 ``` 236 237 ## Editor Integration 238 239 1. [Go for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-vscode.Go). 240 Recommended settings for VS Code are: 241 242 ```json 243 "go.lintTool":"golangci-lint", 244 "go.lintFlags": [ 245 "--fast" 246 ] 247 ``` 248 249 Using it in an editor without `--fast` can freeze your editor. 250 Golangci-lint automatically discovers `.golangci.yml` config for edited file: you don't need to configure it in VS Code settings. 251 2. Sublime Text - [plugin](https://github.com/alecthomas/SublimeLinter-contrib-golang-cilint) for SublimeLinter. 252 3. GoLand 253 * Configure [File Watcher](https://www.jetbrains.com/help/go/settings-tools-file-watchers.html) with arguments `run --print-issued-lines=false $FileDir$`. 254 * Predefined File Watcher will be added in [issue](https://youtrack.jetbrains.com/issue/GO-4574). 255 4. GNU Emacs 256 * [Spacemacs](https://github.com/syl20bnr/spacemacs/blob/develop/layers/+lang/go/README.org#pre-requisites) 257 * [flycheck checker](https://github.com/weijiangan/flycheck-golangci-lint). 258 5. Vim 259 * [vim-go](https://github.com/fatih/vim-go) 260 * syntastic [merged pull request](https://github.com/vim-syntastic/syntastic/pull/2190) with golangci-lint support 261 * ale [merged pull request](https://github.com/w0rp/ale/pull/1890) with golangci-lint support 262 6. Atom - [go-plus](https://atom.io/packages/go-plus) supports golangci-lint. 263 264 ## Comparison 265 266 ### `golangci-lint` vs `gometalinter` 267 268 GolangCI-Lint was created to fix the following issues with `gometalinter`: 269 270 1. Slow work: `gometalinter` usually works for minutes in average projects. 271 **GolangCI-Lint works [2-7x times faster](#performance)** by [reusing work](#internals). 272 2. Huge memory consumption: parallel linters don't share the same program representation and can consume 273 `n` times more memory (`n` - concurrency). GolangCI-Lint fixes it by sharing representation and **consumes 26% less memory**. 274 3. Doesn't use real bounded concurrency: if you set it to `n` it can take up to `n*n` threads because of 275 forced threads in specific linters. `gometalinter` can't do anything about it because it runs linters as 276 black boxes in forked processes. In GolangCI-Lint we run all linters in one process and completely control 277 them. Configured concurrency will be correctly bounded. 278 This issue is important because you often want to set concurrency to the CPUs count minus one to 279 ensure you **do not freeze your PC** and be able to work on it while analyzing code. 280 4. Lack of nice output. We like how the `gcc` and `clang` compilers format their warnings: **using colors, 281 printing warning lines and showing the position in line**. 282 5. Too many issues. GolangCI-Lint cuts a lot of issues by using default exclude list of common false-positives. 283 By default, it has enabled **smart issues processing**: merge multiple issues for one line, merge issues with the 284 same text or from the same linter. All of these smart processors can be configured by the user. 285 6. Integration into large codebases. A good way to start using linters in a large project is not to fix a plethora 286 of existing issues, but to set up CI and **fix only issues in new commits**. You can use `revgrep` for it, but it's 287 yet another utility to install and configure. With `golangci-lint` it's much easier: `revgrep` is already built into 288 `golangci-lint` and you can use it with one option (`-n, --new` or `--new-from-rev`). 289 7. Installation. With `gometalinter`, you need to run a linters installation step. It's easy to forget this step and 290 end up with stale linters. It also complicates CI setup. GolangCI-Lint requires **no installation of linters**. 291 8. **Yaml or toml config**. Gometalinter's JSON isn't convenient for config files. 292 293 ### `golangci-lint` vs Running Linters Manually 294 295 1. It will be much slower because `golangci-lint` runs all linters in parallel and shares 50-80% of linters work. 296 2. It will have less control and more false-positives: some linters can't be properly configured without hacks. 297 3. It will take more time because of different usages and need of tracking of versions of `n` linters. 298 299 ## Performance 300 301 Benchmarks were executed on MacBook Pro (Retina, 13-inch, Late 2013), 2,4 GHz Intel Core i5, 8 GB 1600 MHz DDR3. 302 It has 4 cores and concurrent linting as a default consuming all cores. 303 Benchmark was run (and measured) automatically, see the code 304 [here](https://github.com/golangci/golangci-lint/blob/master/test/bench_test.go) (`BenchmarkWithGometalinter`). 305 306 We measure peak memory usage (RSS) by tracking of processes RSS every 5 ms. 307 308 ### Comparison with gometalinter 309 310 We compare golangci-lint and gometalinter in default mode, but explicitly enable all linters because of small differences in the default configuration. 311 312 ```bash 313 $ golangci-lint run --no-config --issues-exit-code=0 --deadline=30m \ 314 --disable-all --enable=deadcode --enable=gocyclo --enable=golint --enable=varcheck \ 315 --enable=structcheck --enable=maligned --enable=errcheck --enable=dupl --enable=ineffassign \ 316 --enable=interfacer --enable=unconvert --enable=goconst --enable=gosec --enable=megacheck 317 $ gometalinter --deadline=30m --vendor --cyclo-over=30 --dupl-threshold=150 \ 318 --exclude=<default golangci-lint excludes> --skip=testdata --skip=builtin \ 319 --disable-all --enable=deadcode --enable=gocyclo --enable=golint --enable=varcheck \ 320 --enable=structcheck --enable=maligned --enable=errcheck --enable=dupl --enable=ineffassign \ 321 --enable=interfacer --enable=unconvert --enable=goconst --enable=gosec --enable=megacheck 322 ./... 323 ``` 324 325 | Repository | GolangCI Time | GolangCI Is Faster than Gometalinter | GolangCI Memory | GolangCI eats less memory than Gometalinter | 326 | ---------- | ------------- | ------------------------------------ | --------------- | ------------------------------------------- | 327 | gometalinter repo, 4 kLoC | 6s | **6.4x** | 0.7GB | 33% | 328 | self-repo, 4 kLoC | 12s | **7.5x** | 1.2GB | 41% | 329 | beego, 50 kLoC | 10s | **4.2x** | 1.4GB | 9% | 330 | hugo, 70 kLoC | 15s | **6.1x** | 1.6GB | 44% | 331 | consul, 127 kLoC | 58s | **4x** | 2.7GB | 41% | 332 | terraform, 190 kLoC | 2m13s | **1.6x** | 4.8GB | 0% | 333 | go-ethereum, 250 kLoC | 33s | **5x** | 3.6GB | 0% | 334 | go source (`$GOROOT/src`), 1300 kLoC | 2m45s | **2x** | 4.7GB | 0% | 335 336 **On average golangci-lint is 4.6 times faster** than gometalinter. Maximum difference is in the 337 self-repo: **7.5 times faster**, minimum difference is in terraform source code repo: 1.8 times faster. 338 339 On average golangci-lint consumes 26% less memory. 340 341 ### Why golangci-lint is faster 342 343 Golangci-lint directly calls linters (no forking) and reuses 80% of work by parsing program only once. 344 Read [this section](#internals) for details. 345 346 ### Memory Usage of Golangci-lint 347 348 A trade-off between memory usage and execution time can be controlled by [`GOGC`](https://golang.org/pkg/runtime/#hdr-Environment_Variables) environment variable. 349 Less `GOGC` values trigger garbage collection more frequently and golangci-lint consumes less memory and more CPU. Below is the trade-off table for running on this repo: 350 351 |`GOGC`|Peak Memory, GB|Executon Time, s| 352 |------|---------------|----------------| 353 |`5` |1.1 |60 | 354 |`10` |1.1 |34 | 355 |`20` |1.3 |25 | 356 |`30` |1.6 |20.2 | 357 |`50` |2.0 |17.1 | 358 |`80` |2.2 |14.1 | 359 |`100` (default)|2.2 |13.8 | 360 |`off` |3.2 |9.3 | 361 362 ## Internals 363 364 1. Work sharing 365 The key difference with gometalinter is that golangci-lint shares work between specific linters (golint, govet, ...). 366 We don't fork to call specific linter but use its API. 367 For small and medium projects 50-90% of work between linters can be reused. 368 369 * load `[]*packages.Package` by `go/packages` once 370 371 We load program (parsing all files and type-checking) only once for all linters. For the most of linters 372 it's the most heavy operation: it takes 5 seconds on 8 kLoC repo and 11 seconds on `$GOROOT/src`. 373 * build `ssa.Program` once 374 375 Some linters (megacheck, interfacer, unparam) work on SSA representation. 376 Building of this representation takes 1.5 seconds on 8 kLoC repo and 6 seconds on `$GOROOT/src`. 377 378 * parse source code and build AST once 379 380 Parsing one source file takes 200 us on average. Parsing of all files in `$GOROOT/src` takes 2 seconds. 381 Currently we parse each file more than once because it's not the bottleneck. But we already save a lot of 382 extra parsing. We're planning to parse each file only once. 383 384 * walk files and directories once 385 386 It takes 300-1000 ms for `$GOROOT/src`. 387 2. Smart linters scheduling 388 389 We schedule linters by a special algorithm which takes estimated execution time into account. It allows 390 to save 10-30% of time when one of heavy linters (megacheck etc) is enabled. 391 392 3. Don't fork to run shell commands 393 394 All linters are vendored in the `/vendor` folder: their version is fixed, they are builtin 395 and you don't need to install them separately. 396 397 ## Supported Linters 398 399 To see a list of supported linters and which linters are enabled/disabled: 400 401 ```bash 402 golangci-lint help linters 403 ``` 404 405 ### Enabled By Default Linters 406 407 - [govet](https://golang.org/cmd/vet/) - Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string 408 - [errcheck](https://github.com/kisielk/errcheck) - Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases 409 - [staticcheck](https://staticcheck.io/) - Staticcheck is a go vet on steroids, applying a ton of static analysis checks 410 - [unused](https://github.com/dominikh/go-tools/tree/master/cmd/unused) - Checks Go code for unused constants, variables, functions and types 411 - [gosimple](https://github.com/dominikh/go-tools/tree/master/cmd/gosimple) - Linter for Go source code that specializes in simplifying a code 412 - [structcheck](https://github.com/opennota/check) - Finds unused struct fields 413 - [varcheck](https://github.com/opennota/check) - Finds unused global variables and constants 414 - [ineffassign](https://github.com/gordonklaus/ineffassign) - Detects when assignments to existing variables are not used 415 - [deadcode](https://github.com/remyoudompheng/go-misc/tree/master/deadcode) - Finds unused code 416 - typecheck - Like the front-end of a Go compiler, parses and type-checks Go code 417 418 ### Disabled By Default Linters (`-E/--enable`) 419 420 - [bodyclose](https://github.com/timakin/bodyclose) - checks whether HTTP response body is closed successfully 421 - [golint](https://github.com/golang/lint) - Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes 422 - [stylecheck](https://github.com/dominikh/go-tools/tree/master/stylecheck) - Stylecheck is a replacement for golint 423 - [gosec](https://github.com/securego/gosec) - Inspects source code for security problems 424 - [interfacer](https://github.com/mvdan/interfacer) - Linter that suggests narrower interface types 425 - [unconvert](https://github.com/mdempsky/unconvert) - Remove unnecessary type conversions 426 - [dupl](https://github.com/mibk/dupl) - Tool for code clone detection 427 - [goconst](https://github.com/jgautheron/goconst) - Finds repeated strings that could be replaced by a constant 428 - [gocyclo](https://github.com/alecthomas/gocyclo) - Computes and checks the cyclomatic complexity of functions 429 - [gofmt](https://golang.org/cmd/gofmt/) - Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification 430 - [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports) - Goimports does everything that gofmt does. Additionally it checks unused imports 431 - [maligned](https://github.com/mdempsky/maligned) - Tool to detect Go structs that would take less memory if their fields were sorted 432 - [depguard](https://github.com/OpenPeeDeeP/depguard) - Go linter that checks if package imports are in a list of acceptable packages 433 - [misspell](https://github.com/client9/misspell) - Finds commonly misspelled English words in comments 434 - [lll](https://github.com/walle/lll) - Reports long lines 435 - [unparam](https://github.com/mvdan/unparam) - Reports unused function parameters 436 - [nakedret](https://github.com/alexkohler/nakedret) - Finds naked returns in functions greater than a specified function length 437 - [prealloc](https://github.com/alexkohler/prealloc) - Finds slice declarations that could potentially be preallocated 438 - [scopelint](https://github.com/kyoh86/scopelint) - Scopelint checks for unpinned variables in go programs 439 - [gocritic](https://github.com/go-critic/go-critic) - The most opinionated Go source code linter 440 - [gochecknoinits](https://github.com/leighmcculloch/gochecknoinits) - Checks that no init functions are present in Go code 441 - [gochecknoglobals](https://github.com/leighmcculloch/gochecknoglobals) - Checks that no globals are present in Go code 442 443 ## Configuration 444 445 The config file has lower priority than command-line options. If the same bool/string/int option is provided on the command-line 446 and in the config file, the option from command-line will be used. 447 Slice options (e.g. list of enabled/disabled linters) are combined from the command-line and config file. 448 449 To see a list of enabled by your configuration linters: 450 451 ```bash 452 golangci-lint linters 453 ``` 454 455 ### Command-Line Options 456 457 ```bash 458 golangci-lint run -h 459 Usage: 460 golangci-lint run [flags] 461 462 Flags: 463 --out-format string Format of output: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml (default "colored-line-number") 464 --print-issued-lines Print lines of code with issue (default true) 465 --print-linter-name Print linter name in issue line (default true) 466 --issues-exit-code int Exit code when issues were found (default 1) 467 --build-tags strings Build tags 468 --deadline duration Deadline for total work (default 1m0s) 469 --tests Analyze tests (*_test.go) (default true) 470 --print-resources-usage Print avg and max memory usage of golangci-lint and total time 471 -c, --config PATH Read config from file path PATH 472 --no-config Don't read config 473 --skip-dirs strings Regexps of directories to skip 474 --skip-files strings Regexps of files to skip 475 -E, --enable strings Enable specific linter 476 -D, --disable strings Disable specific linter 477 --enable-all Enable all linters 478 --disable-all Disable all linters 479 -p, --presets strings Enable presets (bugs|complexity|format|performance|style|unused) of linters. Run 'golangci-lint linters' to see them. This option implies option --disable-all 480 --fast Run only fast linters from enabled linters set (first run won't be fast) 481 -e, --exclude strings Exclude issue by regexp 482 --exclude-use-default Use or not use default excludes: 483 # errcheck: Almost all programs ignore errors on these functions and in most cases it's ok 484 - Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked 485 486 # golint: Annoying issue about not having a comment. The rare codebase has such comments 487 - (comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form) 488 489 # golint: False positive when tests are defined in package 'test' 490 - func name will be used as test\.Test.* by other packages, and that stutters; consider calling this 491 492 # govet: Common false positives 493 - (possible misuse of unsafe.Pointer|should have signature) 494 495 # staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore 496 - ineffective break statement. Did you mean to break out of the outer loop 497 498 # gosec: Too many false-positives on 'unsafe' usage 499 - Use of unsafe calls should be audited 500 501 # gosec: Too many false-positives for parametrized shell calls 502 - Subprocess launch(ed with variable|ing should be audited) 503 504 # gosec: Duplicated errcheck checks 505 - G104 506 507 # gosec: Too many issues in popular repos 508 - (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less) 509 510 # gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)' 511 - Potential file inclusion via variable 512 (default true) 513 --max-issues-per-linter int Maximum issues count per one linter. Set to 0 to disable (default 50) 514 --max-same-issues int Maximum count of issues with the same text. Set to 0 to disable (default 3) 515 -n, --new Show only new issues: if there are unstaged changes or untracked files, only those changes are analyzed, else only changes in HEAD~ are analyzed. 516 It's a super-useful option for integration of golangci-lint into existing large codebase. 517 It's not practical to fix all existing issues at the moment of integration: much better to not allow issues in new code. 518 For CI setups, prefer --new-from-rev=HEAD~, as --new can skip linting the current patch if any scripts generate unstaged files before golangci-lint runs. 519 --new-from-rev REV Show only new issues created after git revision REV 520 --new-from-patch PATH Show only new issues created in git patch with file path PATH 521 --fix Fix found issues (if it's supported by the linter) 522 -h, --help help for run 523 524 Global Flags: 525 --color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto") 526 -j, --concurrency int Concurrency (default NumCPU) (default 8) 527 --cpu-profile-path string Path to CPU profile output file 528 --mem-profile-path string Path to memory profile output file 529 -v, --verbose verbose output 530 531 ``` 532 533 ### Config File 534 535 GolangCI-Lint looks for config files in the following paths from the current working directory: 536 537 * `.golangci.yml` 538 * `.golangci.toml` 539 * `.golangci.json` 540 541 GolangCI-Lint also searches for config files in all directories from the directory of the first analyzed path up to the root. 542 To see which config file is being used and where it was sourced from run golangci-lint with `-v` option. 543 544 Config options inside the file are identical to command-line options. 545 You can configure specific linters' options only within the config file (not the command-line). 546 547 There is a [`.golangci.example.yml`](https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml) example 548 config file with all supported options, their description and default value: 549 550 ```yaml 551 # This file contains all available configuration options 552 # with their default values. 553 554 # options for analysis running 555 run: 556 # default concurrency is a available CPU number 557 concurrency: 4 558 559 # timeout for analysis, e.g. 30s, 5m, default is 1m 560 deadline: 1m 561 562 # exit code when at least one issue was found, default is 1 563 issues-exit-code: 1 564 565 # include test files or not, default is true 566 tests: true 567 568 # list of build tags, all linters use it. Default is empty list. 569 build-tags: 570 - mytag 571 572 # which dirs to skip: they won't be analyzed; 573 # can use regexp here: generated.*, regexp is applied on full path; 574 # default value is empty list, but next dirs are always skipped independently 575 # from this option's value: 576 # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ 577 skip-dirs: 578 - src/external_libs 579 - autogenerated_by_my_lib 580 581 # which files to skip: they will be analyzed, but issues from them 582 # won't be reported. Default value is empty list, but there is 583 # no need to include all autogenerated files, we confidently recognize 584 # autogenerated files. If it's not please let us know. 585 skip-files: 586 - ".*\\.my\\.go$" 587 - lib/bad.go 588 589 # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules": 590 # If invoked with -mod=readonly, the go command is disallowed from the implicit 591 # automatic updating of go.mod described above. Instead, it fails when any changes 592 # to go.mod are needed. This setting is most useful to check that go.mod does 593 # not need updates, such as in a continuous integration and testing system. 594 # If invoked with -mod=vendor, the go command assumes that the vendor 595 # directory holds the correct copies of dependencies and ignores 596 # the dependency descriptions in go.mod. 597 modules-download-mode: readonly|release|vendor 598 599 600 # output configuration options 601 output: 602 # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" 603 format: colored-line-number 604 605 # print lines of code with issue, default is true 606 print-issued-lines: true 607 608 # print linter name in the end of issue text, default is true 609 print-linter-name: true 610 611 612 # all available settings of specific linters 613 linters-settings: 614 errcheck: 615 # report about not checking of errors in type assetions: `a := b.(MyStruct)`; 616 # default is false: such cases aren't reported by default. 617 check-type-assertions: false 618 619 # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; 620 # default is false: such cases aren't reported by default. 621 check-blank: false 622 623 # [deprecated] comma-separated list of pairs of the form pkg:regex 624 # the regex is used to ignore names within pkg. (default "fmt:.*"). 625 # see https://github.com/kisielk/errcheck#the-deprecated-method for details 626 ignore: fmt:.*,io/ioutil:^Read.* 627 628 # path to a file containing a list of functions to exclude from checking 629 # see https://github.com/kisielk/errcheck#excluding-functions for details 630 exclude: /path/to/file.txt 631 govet: 632 # report about shadowed variables 633 check-shadowing: true 634 635 # settings per analyzer 636 settings: 637 printf: # analyzer name, run `go tool vet help` to see all analyzers 638 funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer 639 - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof 640 - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf 641 - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf 642 - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf 643 golint: 644 # minimal confidence for issues, default is 0.8 645 min-confidence: 0.8 646 gofmt: 647 # simplify code: gofmt with `-s` option, true by default 648 simplify: true 649 goimports: 650 # put imports beginning with prefix after 3rd-party packages; 651 # it's a comma-separated list of prefixes 652 local-prefixes: github.com/org/project 653 gocyclo: 654 # minimal code complexity to report, 30 by default (but we recommend 10-20) 655 min-complexity: 10 656 maligned: 657 # print struct with more effective memory layout or not, false by default 658 suggest-new: true 659 dupl: 660 # tokens count to trigger issue, 150 by default 661 threshold: 100 662 goconst: 663 # minimal length of string constant, 3 by default 664 min-len: 3 665 # minimal occurrences count to trigger, 3 by default 666 min-occurrences: 3 667 depguard: 668 list-type: blacklist 669 include-go-root: false 670 packages: 671 - github.com/davecgh/go-spew/spew 672 misspell: 673 # Correct spellings using locale preferences for US or UK. 674 # Default is to use a neutral variety of English. 675 # Setting locale to US will correct the British spelling of 'colour' to 'color'. 676 locale: US 677 ignore-words: 678 - someword 679 lll: 680 # max line length, lines longer will be reported. Default is 120. 681 # '\t' is counted as 1 character by default, and can be changed with the tab-width option 682 line-length: 120 683 # tab width in spaces. Default to 1. 684 tab-width: 1 685 unused: 686 # treat code as a program (not a library) and report unused exported identifiers; default is false. 687 # XXX: if you enable this setting, unused will report a lot of false-positives in text editors: 688 # if it's called for subdir of a project it can't find funcs usages. All text editor integrations 689 # with golangci-lint call it on a directory with the changed file. 690 check-exported: false 691 unparam: 692 # Inspect exported functions, default is false. Set to true if no external program/library imports your code. 693 # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: 694 # if it's called for subdir of a project it can't find external interfaces. All text editor integrations 695 # with golangci-lint call it on a directory with the changed file. 696 check-exported: false 697 nakedret: 698 # make an issue if func has more lines of code than this setting and it has naked returns; default is 30 699 max-func-lines: 30 700 prealloc: 701 # XXX: we don't recommend using this linter before doing performance profiling. 702 # For most programs usage of prealloc will be a premature optimization. 703 704 # Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them. 705 # True by default. 706 simple: true 707 range-loops: true # Report preallocation suggestions on range loops, true by default 708 for-loops: false # Report preallocation suggestions on for loops, false by default 709 gocritic: 710 # Which checks should be enabled; can't be combined with 'disabled-checks'; 711 # See https://go-critic.github.io/overview#checks-overview 712 # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run` 713 # By default list of stable checks is used. 714 enabled-checks: 715 - rangeValCopy 716 717 # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty 718 disabled-checks: 719 - regexpMust 720 721 # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint` run to see all tags and checks. 722 # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". 723 enabled-tags: 724 - performance 725 726 settings: # settings passed to gocritic 727 captLocal: # must be valid enabled check name 728 paramsOnly: true 729 rangeValCopy: 730 sizeThreshold: 32 731 732 linters: 733 enable: 734 - megacheck 735 - govet 736 enable-all: false 737 disable: 738 - maligned 739 - prealloc 740 disable-all: false 741 presets: 742 - bugs 743 - unused 744 fast: false 745 746 747 issues: 748 # List of regexps of issue texts to exclude, empty list by default. 749 # But independently from this option we use default exclude patterns, 750 # it can be disabled by `exclude-use-default: false`. To list all 751 # excluded by default patterns execute `golangci-lint run --help` 752 exclude: 753 - abcdef 754 755 # Excluding configuration per-path, per-linter, per-text and per-source 756 exclude-rules: 757 # Exclude some linters from running on tests files. 758 - path: _test\.go 759 linters: 760 - gocyclo 761 - errcheck 762 - dupl 763 - gosec 764 765 # Exclude known linters from partially hard-vendored code, 766 # which is impossible to exclude via "nolint" comments. 767 - path: internal/hmac/ 768 text: "weak cryptographic primitive" 769 linters: 770 - gosec 771 772 # Exclude some staticcheck messages 773 - linters: 774 - staticcheck 775 text: "SA9003:" 776 777 # Exclude lll issues for long lines with go:generate 778 - linters: 779 - lll 780 source: "^//go:generate " 781 782 # Independently from option `exclude` we use default exclude patterns, 783 # it can be disabled by this option. To list all 784 # excluded by default patterns execute `golangci-lint run --help`. 785 # Default value for this option is true. 786 exclude-use-default: false 787 788 # Maximum issues count per one linter. Set to 0 to disable. Default is 50. 789 max-issues-per-linter: 0 790 791 # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. 792 max-same-issues: 0 793 794 # Show only new issues: if there are unstaged changes or untracked files, 795 # only those changes are analyzed, else only changes in HEAD~ are analyzed. 796 # It's a super-useful option for integration of golangci-lint into existing 797 # large codebase. It's not practical to fix all existing issues at the moment 798 # of integration: much better don't allow issues in new code. 799 # Default is false. 800 new: false 801 802 # Show only new issues created after git revision `REV` 803 new-from-rev: REV 804 805 # Show only new issues created in git patch with set file path. 806 new-from-patch: path/to/patch/file 807 ``` 808 809 It's a [.golangci.yml](https://github.com/golangci/golangci-lint/blob/master/.golangci.yml) config file of this repo: we enable more linters 810 than the default and have more strict settings: 811 812 ```yaml 813 linters-settings: 814 govet: 815 check-shadowing: true 816 settings: 817 printf: 818 funcs: 819 - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof 820 - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf 821 - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf 822 - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf 823 golint: 824 min-confidence: 0 825 gocyclo: 826 min-complexity: 10 827 maligned: 828 suggest-new: true 829 dupl: 830 threshold: 100 831 goconst: 832 min-len: 2 833 min-occurrences: 2 834 depguard: 835 list-type: blacklist 836 packages: 837 # logging is allowed only by logutils.Log, logrus 838 # is allowed to use only in logutils package 839 - github.com/sirupsen/logrus 840 misspell: 841 locale: US 842 lll: 843 line-length: 140 844 goimports: 845 local-prefixes: github.com/golangci/golangci-lint 846 gocritic: 847 enabled-tags: 848 - performance 849 - style 850 - experimental 851 disabled-checks: 852 - wrapperFunc 853 - dupImport # https://github.com/go-critic/go-critic/issues/845 854 855 linters: 856 enable-all: true 857 disable: 858 - maligned 859 - prealloc 860 - gochecknoglobals 861 862 run: 863 skip-dirs: 864 - test/testdata_etc 865 - pkg/golinters/goanalysis/(checker|passes) 866 867 issues: 868 exclude-rules: 869 - text: "weak cryptographic primitive" 870 linters: 871 - gosec 872 873 # golangci.com configuration 874 # https://github.com/golangci/golangci/wiki/Configuration 875 service: 876 golangci-lint-version: 1.17.x # use the fixed version to not introduce new linters unexpectedly 877 prepare: 878 - echo "here I can run custom commands, but no preparation needed for this repo" 879 ``` 880 881 ## False Positives 882 883 False positives are inevitable, but we did our best to reduce their count. For example, we have a default enabled set of [exclude patterns](#command-line-options). If a false positive occurred you have the following choices: 884 885 1. Exclude issue by text using command-line option `-e` or config option `issues.exclude`. It's helpful when you decided to ignore all issues of this type. Also, you can use `issues.exclude-rules` config option for per-path or per-linter configuration. 886 2. Exclude this one issue by using special comment `//nolint` (see [the section](#nolint) below). 887 3. Exclude issues in path by `run.skip-dirs`, `run.skip-files` or `issues.exclude-rules` config options. 888 889 Please create [GitHub Issues here](https://github.com/golangci/golangci-lint/issues/new) if you find any false positives. We will add it to the default exclude list if it's common or we will fix underlying linter. 890 891 ### Nolint 892 893 To exclude issues from all linters use `//nolint`. For example, if it's used inline (not from the beginning of the line) it excludes issues only for this line. 894 895 ```go 896 var bad_name int //nolint 897 ``` 898 899 To exclude issues from specific linters only: 900 901 ```go 902 var bad_name int //nolint:golint,unused 903 ``` 904 905 To exclude issues for the block of code use this directive on the beginning of a line: 906 907 ```go 908 //nolint 909 func allIssuesInThisFunctionAreExcluded() *string { 910 // ... 911 } 912 913 //nolint:govet 914 var ( 915 a int 916 b int 917 ) 918 ``` 919 920 Also, you can exclude all issues in a file by: 921 922 ```go 923 //nolint:unparam 924 package pkg 925 ``` 926 927 You can see more examples of using `//nolint` in [our tests](https://github.com/golangci/golangci-lint/tree/master/pkg/result/processors/testdata) for it. 928 929 Use `//nolint` instead of `// nolint` because machine-readable comments should have no space by Go convention. 930 931 ## FAQ 932 933 **How do you add a custom linter?** 934 935 You can integrate it yourself, see this [wiki page](https://github.com/golangci/golangci-lint/wiki/How-to-add-a-custom-linter) with documentation. Or you can create a [GitHub Issue](https://github.com/golangci/golangci-lint/issues/new) and we will integrate when time permits. 936 937 **It's cool to use `golangci-lint` when starting a project, but what about existing projects with large codebase? It will take days to fix all found issues** 938 939 We are sure that every project can easily integrate `golangci-lint`, even the large one. The idea is to not fix all existing issues. Fix only newly added issue: issues in new code. To do this setup CI (or better use [GolangCI](https://golangci.com)) to run `golangci-lint` with option `--new-from-rev=HEAD~1`. Also, take a look at option `--new`, but consider that CI scripts that generate unstaged files will make `--new` only point out issues in those files and not in the last commit. In that regard `--new-from-rev=HEAD~1` is safer. 940 By doing this you won't create new issues in your code and can choose fix existing issues (or not). 941 942 **How to use `golangci-lint` in CI (Continuous Integration)?** 943 944 You have 2 choices: 945 946 1. Use [GolangCI](https://golangci.com): this service is highly integrated with GitHub (issues are commented in the pull request) and uses a `golangci-lint` tool. For configuration use `.golangci.yml` (or toml/json). 947 2. Use custom CI: just run `golangci-lint` in CI and check the exit code. If it's non-zero - fail the build. The main disadvantage is that you can't see issues in pull request code and would need to view the build log, then open the referenced source file to see the context. 948 949 We don't recommend vendoring `golangci-lint` in your repo: you will get troubles updating `golangci-lint`. Please, use recommended way to install with the shell script: it's very fast. 950 951 **Do I need to run `go install`?** 952 953 No, you don't need to do it anymore. 954 955 **Which go versions are supported** 956 Short answer: go 1.11 and newer are oficially supported. 957 958 Long answer: 959 1. go < 1.9 isn't supported 960 2. go 1.9 is supported by golangci-lint <= v1.10.2 961 3. go 1.10 is officially supported by golangci-lint <= 1.15.0. 962 4. go1.11 and go1.12 are officially supported by the latest version of golangci-lint. 963 964 **`golangci-lint` doesn't work** 965 966 1. Update it: `go get -u github.com/golangci/golangci-lint/cmd/golangci-lint` 967 2. Run it with `-v` option and check the output. 968 3. If it doesn't help create a [GitHub issue](https://github.com/golangci/golangci-lint/issues/new) with the output from the error and #2 above. 969 970 **Why running with `--fast` is slow on the first run?** 971 Because the first run caches type information. All subsequent runs will be fast. 972 Usually this options is used during development on local machine and compilation was already performed. 973 974 ## Thanks 975 976 Thanks to all [contributors](https://github.com/golangci/golangci-lint/graphs/contributors)! 977 Thanks to [alecthomas/gometalinter](https://github.com/alecthomas/gometalinter) for inspiration and amazing work. 978 Thanks to [bradleyfalzon/revgrep](https://github.com/bradleyfalzon/revgrep) for cool diff tool. 979 980 Thanks to developers and authors of used linters: 981 - [timakin](https://github.com/timakin) 982 - [kisielk](https://github.com/kisielk) 983 - [golang](https://github.com/golang) 984 - [dominikh](https://github.com/dominikh) 985 - [securego](https://github.com/securego) 986 - [opennota](https://github.com/opennota) 987 - [mvdan](https://github.com/mvdan) 988 - [mdempsky](https://github.com/mdempsky) 989 - [gordonklaus](https://github.com/gordonklaus) 990 - [mibk](https://github.com/mibk) 991 - [jgautheron](https://github.com/jgautheron) 992 - [remyoudompheng](https://github.com/remyoudompheng) 993 - [alecthomas](https://github.com/alecthomas) 994 - [OpenPeeDeeP](https://github.com/OpenPeeDeeP) 995 - [client9](https://github.com/client9) 996 - [walle](https://github.com/walle) 997 - [alexkohler](https://github.com/alexkohler) 998 - [kyoh86](https://github.com/kyoh86) 999 - [go-critic](https://github.com/go-critic) 1000 - [leighmcculloch](https://github.com/leighmcculloch) 1001 1002 ## Changelog 1003 1004 Follow the news and releases on our [twitter](https://twitter.com/golangci) and our [blog](https://medium.com/golangci). 1005 There is the most valuable changes log: 1006 1007 ### June 2019 1008 1009 1. treat Go source files as a plain text by `misspell`: it allows detecting issues in strings, variable names, etc. 1010 2. implement richer and more stable auto-fix of `misspell` issues. 1011 1012 ### May 2019 1013 1014 1. Add [bodyclose](https://github.com/timakin/bodyclose) linter. 1015 2. Support junit-xml output. 1016 1017 ### April 2019 1018 1019 1. Update go-critic, new checkers were added: badCall, dupImports, evalOrder, newDeref 1020 2. Fix staticcheck panic on packages that do not compile 1021 3. Make install script work on Windows 1022 4. Fix compatibility with the latest x/tools version and update golang.org/x/tools 1023 5. Correct import path of module sourcegraph/go-diff 1024 6. Fix `max-issues-per-linter` name 1025 7. Fix linting of preprocessed files (e.g. `*.qtpl.go`, goyacc) 1026 8. Enable auto-fixing when running via pre-commit 1027 1028 ### March 2019 1029 1030 1. Support the newest `go vet` (with `go/analysis`) 1031 2. Support configuration of `go vet`: e.g. you can set print functions by `linters-settings.govet.settings.printf.funcs` 1032 3. Update megacheck (staticcheck) to 2019.1.1 1033 4. Add [information](https://github.com/golangci/golangci-lint#memory-usage-of-golangci-lint) about controlling space-time trade-off into README 1034 5. Exclude issues by source code line regexp by `issues.exclude-rules[i].source` 1035 6. Build and test on go 1.12 1036 7. Support `--color` option 1037 8. Update x/tools to fix c++ issues 1038 9. Include support for log level 1039 10. Sort linters list in help commands 1040 1041 ### February 2019 1042 1043 1. Implement auto-fixing for `gofmt`, `goimports` and `misspell` 1044 2. Update `unparam`, `goimports`, `gosec` and `go-critic` 1045 3. Support `issues.exclude-rules` config option 1046 4. Add more `identifier` marking patterns 1047 5. Add code-climate output format 1048 6. Fix diff parsing on windows 1049 7. Add version information to built artifact for go1.12 1050 8. Dockerfile: copy the binary to `/usr/bin/` instead of `$GOPATH/bin/` 1051 9. Support `ignore-words` config option for `misspell` 1052 10. Include `staticcheck` check name into a message 1053 11. Fix working with symbolic links 1054 1055 ### January 2019 1056 1057 1. Update `megacheck` (`staticcheck`), `unparam` and `go-critic` to the latest versions. 1058 2. Support the new `stylecheck` linter. 1059 3. Support of `enabled-tags` options for `go-critic`. 1060 4. Make rich debugging for `go-critic` and meticulously validate `go-critic` checks config. 1061 5. Update and use upstream versions of `unparam` and `interfacer` instead of forked ones. 1062 6. Improve handling of unknown linter names in `//nolint` directives. 1063 7. Speedup `typecheck` on large project with compilation errors. 1064 8. Add support for searching for `errcheck` exclude file. 1065 9. Fix `go-misc` checksum. 1066 10. Don't crash when staticcheck panics 1067 1068 ### December 2018 1069 1070 1. Update `goimports`: the new version creates named imports for name/path mismatches. 1071 2. Update `go-critic` to the latest version. 1072 3. Sync default `go-critic` checks list with the `go-critic`. 1073 4. Support `pre-commit.com` hooks. 1074 5. Rework and simplify `--skip-dirs` for some edge cases. 1075 6. Add `modules-download-mode` option: it's useful in CI. 1076 7. Better validate commands. 1077 8. Fix working with absolute paths. 1078 9. Fix `errcheck.ignore` option. 1079 1080 ### November 2018 1081 1082 1. Support new linters: 1083 * gocritic 1084 * scopelint 1085 * gochecknointis 1086 * gochecknoglobals 1087 2. Update CLA 1088 1089 ### October 2018 1090 1091 1. Update goimports formatting 1092 2. Use go/packages 1093 * A lot of linters became "fast": they are enabled by --fast now and 1094 work in 1-2 seconds. Only unparam, interfacer and megacheck 1095 are "slow" linters now. 1096 1097 * Average project is analyzed 20-40% faster than before if all linters are 1098 enabled! If we enable all linters except unparam, interfacer and 1099 megacheck analysis is 10-20x faster! 1100 3. Support goimports.local-prefix option for goimports 1101 4. Change license from AGPL to GPL 1102 1103 ### September 2018 1104 1105 1. Rename GAS to gosec 1106 2. Drop go1.9 support 1107 3. Support installation of golangci-lint via go modules 1108 4. Update dockerfile to use golang 1.11 1109 5. Add support for ignore/exclude flags in errcheck 1110 1111 ### August 2018 1112 1113 1. Improve lll parsing for very long lines 1114 2. Update Depguard with a Glob support 1115 3. Silent output by default 1116 4. Disable GAS (gosec) by default 1117 5. Build golangci-lint on go1.11 1118 1119 ### July 2018 1120 1121 1. Add `golangci-lint linters` command 1122 2. Fix work with symlinks 1123 1124 ### June 2018 1125 1126 1. Add support of the next linters: 1127 * unparam 1128 * misspell 1129 * prealloc 1130 * nakedret 1131 * lll 1132 * depguard 1133 2. Smart generated files detector 1134 3. Full `//nolint` support 1135 4. Implement `--skip-files` and `--skip-dirs` options 1136 5. Checkstyle output format support 1137 1138 ### May 2018 1139 1140 1. Support GitHub Releases 1141 2. Installation via Homebrew and Docker 1142 1143 ## Future Plans 1144 1145 1. Upstream all changes of forked linters. 1146 2. Make it easy to write own linter/checker: it should take a minimum code, have perfect documentation, debugging and testing tooling. 1147 3. Speed up SSA loading: on-disk cache and existing code profiling-optimizing. 1148 4. Analyze (don't only filter) only new code: analyze only changed files and dependencies, make incremental analysis, caches. 1149 5. Smart new issues detector: don't print existing issues on changed lines. 1150 6. Minimize false-positives by fixing linters and improving testing tooling. 1151 7. Automatic issues fixing (code rewrite, refactoring) where it's possible. 1152 8. Documentation for every issue type. 1153 1154 ## Contact Information 1155 1156 You can contact the [author](https://github.com/jirfag) of GolangCI-Lint 1157 by [denis@golangci.com](mailto:denis@golangci.com). Follow the news and releases on our [twitter](https://twitter.com/golangci) and our [blog](https://medium.com/golangci). 1158 1159 ## License Scan 1160 1161 [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fgolangci%2Fgolangci-lint.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fgolangci%2Fgolangci-lint?ref=badge_large)