You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GolangCI-Lint is a linters aggregator. It is [fast](#performance) (2-7 times faster than gometalinter), [easy to integrate and use](#issues-options), has [nice output](quick-start) and has minimum count of false positives.
4
+
GolangCI-Lint is a linters aggregator. It is [fast](#performance) (2-7 times faster than gometalinter), [easy to integrate and use](#issues-options), has [nice output](#quick-start) and has minimum count of false positives.
5
5
6
6
Sponsored by [GolangCI.com](https://golangci.com): SaaS service for running linters on Github pull requests. Free for Open Source.
7
7
@@ -35,12 +35,18 @@ Sponsored by [GolangCI.com](https://golangci.com): SaaS service for running lint
35
35
go get -u gopkg.in/golangci/golangci-lint.v1/cmd/golangci-lint
36
36
```
37
37
38
+
# Demo
39
+
Example of output:
40
+


44
50
45
51
It's and equivalent of executing:
46
52
```bash
@@ -97,22 +103,22 @@ GolangCI-Lint was created to fix next issues with `gometalinter`:
97
103
1. Slow work: `gometalinter` usually works for minutes in average projects. GolangCI-Lint works [2-7x times faster](#performance) by [reusing work](#internals).
98
104
2. Huge memory consumption: parallel linters don't share the same program representation and can eat `n` times more memory (`n` - concurrency). GolangCI-Lint fixes it by sharing representation.
99
105
3. Can't set honest concurrency: if you set it to `n` it can take `n+x` threads because of forced threads in specific linters. `gometalinter` can't do anything about it, because it runs linters as black-boxes in forked processes. In GolangCI-Lint we run all linters in one process and fully control them. Configured concurrency will be honest.
100
-
This issue is important because often you'd like to set concurrency to CPUs count minus one to save one CPU for example for IDE. It concurrency isn't correct you will have troubles using IDE while analyzing code.
106
+
This issue is important because often you'd like to set concurrency to CPUs count minus one to save one CPU for example for IDE. If concurrency isn't correct you will have troubles using IDE while analyzing code.
101
107
4. Lack of nice output. We like how compilers `gcc` and `clang` format their warnings: using colors, printing of warned line and showing position in line.
102
108
5. Too many issues. GolangCI-Lint cuts a lot of issues by using default exclude list of common false-positives. Also it has enabled by default smart issues processing: merge multiple issues for one line, merge issues with the same text or from the same linter. All of these smart processors can be configured by user.
103
109
6. Installation. With `gometalinter` you need to run linters installation step. It's easy to forget this step and have stale linters.
104
110
7. Integration to large codebases. You can use `revgrep`, but it's yet another utility to install. With `golangci-lint` it's much easier: `revgrep` is already built into `golangci-lint` and you use it with one option (`-n, --new` or `--new-from-rev`).
105
111
8. Yaml or toml config. JSON isn't convenient for configuration files.
106
112
107
113
## `golangci-lint` vs Run Needed Linters Manually
108
-
1. It will be slower because `golangci-lint` shares 50-80% of linters work.
114
+
1. It will be much slower because `golangci-lint` runs all linters in parallel and shares 50-80% of linters work.
109
115
2. It will have fewer control and more false-positives: some linters can't be properly configured without hacks.
110
-
3. It will take more time because of different usages and need of tracking of version of `n` linters.
116
+
3. It will take more time because of different usages and need of tracking of versions of `n` linters.
111
117
112
118
# Performance
113
119
Benchmarks were executed on MacBook Pro (Retina, 13-inch, Late 2013), 2,4 GHz Intel Core i5, 8 GB 1600 MHz DDR3. It has 4 cores and concurrency for linters was default: number of cores. Benchmark runs and measures timings automatically, it's code is [here](https://github.com/golangci/golangci-lint/blob/master/pkg/enabled_linters_test.go) (`BenchmarkWithGometalinter`).
114
120
115
-
We measure peak memory usage (RSS) by measurement of processes RSS every 5 ms.
121
+
We measure peak memory usage (RSS) by tracking of processes RSS every 5 ms.
116
122
117
123
## Comparison with gometalinter
118
124
We compare golangci-lint and gometalinter in default mode, but explicitly specify all linters to enable because of small differences in default configuration.
**On average golangci-lint is 4.6 times faster** than gometalinter. Maximum difference is in
145
151
self repo: **7.5 times faster**, minimum difference is in terraform source code repo: 1.8 times faster.
146
152
153
+
On average golangci-lint consumes 1.35 times less memory.
154
+
147
155
# Supported Linters
148
156
To see a list of supported linters and which linters are enabled/disabled by default execute command
149
157
```bash
@@ -275,9 +283,40 @@ GolangCI-Lint looks for next config paths in current directory:
275
283
-`.golangci.toml`
276
284
-`.golangci.json`
277
285
278
-
Configuration options inside file are identical to command-line options:
279
-
-[Example `.golangci.yml`](https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml) with all supported options.
280
-
-[.golangci.yml](https://github.com/golangci/golangci-lint/blob/master/.golangci.yml) of this repo: we enable more linters than by default and make their settings more strict.
286
+
Configuration options inside file are identical to command-line options.
287
+
There is a [`.golangci.yml`](https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml) with all supported options.
288
+
289
+
It's a [.golangci.yml](https://github.com/golangci/golangci-lint/blob/master/.golangci.yml) of this repo: we enable more linters than by default and make their settings more strict:
290
+
```yaml
291
+
run:
292
+
deadline: 30s
293
+
tests: true
294
+
295
+
linters-settings:
296
+
govet:
297
+
check-shadowing: true
298
+
golint:
299
+
min-confidence: 0
300
+
gocyclo:
301
+
min-complexity: 10
302
+
maligned:
303
+
suggest-new: true
304
+
dupl:
305
+
threshold: 100
306
+
goconst:
307
+
min-len: 2
308
+
min-occurrences: 2
309
+
310
+
linters:
311
+
enable-all: true
312
+
disable:
313
+
- maligned
314
+
315
+
issues:
316
+
exclude:
317
+
- should have a package comment
318
+
319
+
```
281
320
282
321
# False Positives
283
322
False positives are inevitable, but we did our best to reduce their count. For example, we have a enabled by default set of [exclude patterns](#issues-options). If false postive occured you have next choices:
@@ -294,13 +333,13 @@ A: You can integrate it yourself, take a look at [existings linters integrations
294
333
295
334
**Q: It's cool to use `golangci-lint` when starting project, but what about existing projects with large codebase? It will take days to fix all found issues**
296
335
297
-
A: We are sure that every project can easily integrate `golangci-lint`, event 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=origin/master`. Also take a look at option `-n`.
336
+
A: 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=origin/master`. Also take a look at option `-n`.
298
337
By doing this you won't create new issues in code and can smoothly fix existing issues (or not).
299
338
300
339
**Q: How to use `golangci-lint` in CI (Continuous Integration)?**
301
340
302
341
A: You have 2 choices:
303
-
1. Use [GolangCI](https://golangci.com): this service is highly integrated with GitHub (found issues are commented in pull request) and uses `golangci-lint` tool. For configuration use `.golangci.yml` (or toml/json).
342
+
1. Use [GolangCI](https://golangci.com): this service is highly integrated with GitHub (issues are commented in pull request) and uses `golangci-lint` tool. For configuration use `.golangci.yml` (or toml/json).
304
343
2. Use custom CI: just run `golangci-lint` in CI and check exit code. If it's non-zero - fail build. The main disadvantage is that you can't see found issues in pull request code and should view build log, then open needed source file to see a context.
305
344
306
345
**Q: `golangci-lint` doesn't work**
@@ -325,3 +364,7 @@ We use chains for issues and independent processors to post-process them: exclud
325
364
nolint comment, diff, regexps; prettify paths etc.
0 commit comments