Skip to content

Commit 598de1b

Browse files
author
golangci
authored
Update README.md
1 parent 5aee21d commit 598de1b

File tree

1 file changed

+54
-11
lines changed

1 file changed

+54
-11
lines changed

README.md

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# GolangCI-Lint
22
[![Build Status](https://travis-ci.com/golangci/golangci-lint.svg?branch=master)](https://travis-ci.com/golangci/golangci-lint)
33

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.
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.
55

66
Sponsored by [GolangCI.com](https://golangci.com): SaaS service for running linters on Github pull requests. Free for Open Source.
77

@@ -35,12 +35,18 @@ Sponsored by [GolangCI.com](https://golangci.com): SaaS service for running lint
3535
go get -u gopkg.in/golangci/golangci-lint.v1/cmd/golangci-lint
3636
```
3737

38+
# Demo
39+
Example of output:
40+
![Screenshot of sample output](docs/run_screenshot.png)
41+
42+
Short 2 min video demo.
43+
[![asciicast](https://asciinema.org/a/183318.png)](https://asciinema.org/a/183318)
44+
3845
# Quick Start
3946
To run golangci-lint execute:
4047
```bash
4148
golangci-lint run
4249
```
43-
![Screenshot of sample output](docs/run_screenshot.png)
4450

4551
It's and equivalent of executing:
4652
```bash
@@ -97,22 +103,22 @@ GolangCI-Lint was created to fix next issues with `gometalinter`:
97103
1. Slow work: `gometalinter` usually works for minutes in average projects. GolangCI-Lint works [2-7x times faster](#performance) by [reusing work](#internals).
98104
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.
99105
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.
101107
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.
102108
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.
103109
6. Installation. With `gometalinter` you need to run linters installation step. It's easy to forget this step and have stale linters.
104110
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`).
105111
8. Yaml or toml config. JSON isn't convenient for configuration files.
106112

107113
## `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.
109115
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.
111117

112118
# Performance
113119
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`).
114120

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.
116122

117123
## Comparison with gometalinter
118124
We compare golangci-lint and gometalinter in default mode, but explicitly specify all linters to enable because of small differences in default configuration.
@@ -144,6 +150,8 @@ $ gometalinter --deadline=30m --vendor --cyclo-over=30 --dupl-threshold=150 \
144150
**On average golangci-lint is 4.6 times faster** than gometalinter. Maximum difference is in
145151
self repo: **7.5 times faster**, minimum difference is in terraform source code repo: 1.8 times faster.
146152

153+
On average golangci-lint consumes 1.35 times less memory.
154+
147155
# Supported Linters
148156
To see a list of supported linters and which linters are enabled/disabled by default execute command
149157
```bash
@@ -275,9 +283,40 @@ GolangCI-Lint looks for next config paths in current directory:
275283
- `.golangci.toml`
276284
- `.golangci.json`
277285

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+
```
281320

282321
# False Positives
283322
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
294333

295334
**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**
296335

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`.
298337
By doing this you won't create new issues in code and can smoothly fix existing issues (or not).
299338

300339
**Q: How to use `golangci-lint` in CI (Continuous Integration)?**
301340

302341
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).
304343
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.
305344

306345
**Q: `golangci-lint` doesn't work**
@@ -325,3 +364,7 @@ We use chains for issues and independent processors to post-process them: exclud
325364
nolint comment, diff, regexps; prettify paths etc.
326365

327366
We use `cobra` for command-line action.
367+
368+
# Thanks
369+
370+
# Future Plans

0 commit comments

Comments
 (0)