Skip to content

Commit e6da4be

Browse files
committed
Fix #17, #87: govet becomes SLOW linter by default
1. Allow govet to work in 2 modes: fast and slow. Default is slow. In fast mode golangci-lint runs `go install -i` and `go test -i` for analyzed packages. But it's fast only when: - go >= 1.10 - it's repeated run or $GOPATH/pkg or `go env GOCACHE` is cached between CI builds In slow mode we load program from source code like for another linters and do it only once for all linters. 3. Patch govet code to warn about any troubles with the type information. Default behaviour of govet was to hide such warnings. Fail analysis if there are any troubles with type loading: it will prevent false-positives and false-negatives from govet. 4. Describe almost all options in .golangci.example.yml and include it into README. Describe when to use slow or fast mode of govet. 5. Speed up govet: reuse AST parsing: it's already parsed once by golangci-lint. For "slow" runs (when we run at least one slow linter) speedup by not loading type information second time. 6. Improve logging, debug logging
1 parent 2de1f87 commit e6da4be

File tree

19 files changed

+657
-142
lines changed

19 files changed

+657
-142
lines changed

Diff for: .golangci.example.yml

+88-6
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,98 @@
1+
# This file contains all available configuration options
2+
# with their default values.
3+
4+
# options for analysis running
15
run:
6+
# default concurrency is a available CPU number
27
concurrency: 4
8+
9+
# timeout for analysis, e.g. 30s, 5m, default is 1m
310
deadline: 1m
11+
12+
# exit code when at least one issue was found, default is 1
413
issues-exit-code: 1
14+
15+
# include test files or not, default is true
516
tests: true
17+
18+
# list of build tags, all linters use it. Default is empty list.
619
build-tags:
720
- mytag
21+
22+
# which dirs to skip: they won't be analyzed;
23+
# can use regexp here: generated.*, regexp is applied on full path;
24+
# default value is empty list, but next dirs are always skipped independently
25+
# from this option's value:
26+
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
827
skip-dirs:
928
- src/external_libs
1029
- autogenerated_by_my_lib
30+
31+
# which files to skip: they will be analyzed, but issues from them
32+
# won't be reported. Default value is empty list, but there is
33+
# no need to include all autogenerated files, we confidently recognize
34+
# autogenerated files. If it's not please let us know.
1135
skip-files:
12-
- ".*\\.pb\\.go$"
36+
- ".*\\.my\\.go$"
1337
- lib/bad.go
1438

39+
# output configuration options
1540
output:
41+
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
1642
format: colored-line-number
43+
44+
# print lines of code with issue, default is true
1745
print-issued-lines: true
46+
47+
# print linter name in the end of issue text, default is true
1848
print-linter-name: true
1949

50+
# all available settings of specific linters
2051
linters-settings:
2152
errcheck:
53+
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
54+
# default is false: such cases aren't reported by default.
2255
check-type-assertions: false
56+
57+
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
58+
# default is false: such cases aren't reported by default.
2359
check-blank: false
2460
govet:
61+
# report about shadowed variables
2562
check-shadowing: true
63+
64+
# Obtain type information from installed (to $GOPATH/pkg) package files:
65+
# golangci-lint will execute `go install -i` and `go test -i` for analyzed packages
66+
# before analyzing them.
67+
# By default this option is disabled and govet gets type information by loader from source code.
68+
# Loading from source code is slow, but it's done only once for all linters.
69+
# Go-installing of packages first time is much slower than loading them from source code,
70+
# therefore this option is disabled by default.
71+
# But repeated installation is fast in go >= 1.10 because of build caching.
72+
# Enable this option only if all conditions are met:
73+
# 1. you use only "fast" linters (--fast e.g.): no program loading occurs
74+
# 2. you use go >= 1.10
75+
# 3. you do repeated runs (false for CI) or cache $GOPATH/pkg or `go env GOCACHE` dir in CI.
76+
use-installed-packages: false
2677
golint:
78+
# minimal confidence for issues, default is 0.8
2779
min-confidence: 0.8
2880
gofmt:
81+
# simplify code: gofmt with `-s` option, true by default
2982
simplify: true
3083
gocyclo:
84+
# minimal code complexity to report, 30 by default (but we recommend 10-20)
3185
min-complexity: 10
3286
maligned:
87+
# print struct with more effective memory layout or not, false by default
3388
suggest-new: true
3489
dupl:
35-
threshold: 50
90+
# tokens count to trigger issue, 150 by default
91+
threshold: 100
3692
goconst:
93+
# minimal length of string constant, 3 by default
3794
min-len: 3
95+
# minimal occurrences count to trigger, 3 by default
3896
min-occurrences: 3
3997
depguard:
4098
list-type: blacklist
@@ -45,8 +103,8 @@ linters-settings:
45103
linters:
46104
enable:
47105
- megacheck
48-
- vet
49-
enable-all: true
106+
- govet
107+
enable-all: false
50108
disable:
51109
maligned
52110
disable-all: false
@@ -56,11 +114,35 @@ linters:
56114
fast: false
57115

58116
issues:
117+
# List of regexps of issue texts to exclude, empty list by default.
118+
# But independently from this option we use default exclude patterns,
119+
# it can be disabled by `exclude-use-default: false`. To list all
120+
# excluded by default patterns execute `golangci-lint run --help`
59121
exclude:
60122
- abcdef
123+
124+
# Independently from option `exclude` we use default exclude patterns,
125+
# it can be disabled by this option. To list all
126+
# excluded by default patterns execute `golangci-lint run --help`.
127+
# Default value for this option is false.
61128
exclude-use-default: true
129+
130+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
62131
max-per-linter: 0
132+
133+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
63134
max-same: 0
135+
136+
# Show only new issues: if there are unstaged changes or untracked files,
137+
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
138+
# It's a super-useful option for integration of golangci-lint into existing
139+
# large codebase. It's not practical to fix all existing issues at the moment
140+
# of integration: much better don't allow issues in new code.
141+
# Default is false.
64142
new: false
65-
new-from-rev: ""
66-
new-from-patch: ""
143+
144+
# Show only new issues created after git revision `REV`
145+
new-from-rev: REV
146+
147+
# Show only new issues created in git patch with set file path.
148+
new-from-patch: path/to/patch/file

Diff for: Gopkg.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: README.md

+154-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ GolangCI-Lint can be used with zero configuration. By default the following lint
8484
```
8585
$ golangci-lint linters
8686
Enabled by default linters:
87-
govet: Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: true]
87+
govet: Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false]
8888
errcheck: Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false]
8989
staticcheck: Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false]
9090
unused: Checks Go code for unused constants, variables, functions and types [fast: false]
@@ -310,10 +310,161 @@ To see which config file is being used and where it was sourced from run golangc
310310
Config options inside the file are identical to command-line options.
311311
You can configure specific linters' options only within the config file (not the command-line).
312312

313-
There is a [`.golangci.yml`](https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml) example config file with all supported options.
313+
There is a [`.golangci.yml`](https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml) example
314+
config file with all supported options, their description and default value:
315+
```yaml
316+
# This file contains all available configuration options
317+
# with their default values.
318+
319+
# options for analysis running
320+
run:
321+
# default concurrency is a available CPU number
322+
concurrency: 4
323+
324+
# timeout for analysis, e.g. 30s, 5m, default is 1m
325+
deadline: 1m
326+
327+
# exit code when at least one issue was found, default is 1
328+
issues-exit-code: 1
329+
330+
# include test files or not, default is true
331+
tests: true
332+
333+
# list of build tags, all linters use it. Default is empty list.
334+
build-tags:
335+
- mytag
336+
337+
# which dirs to skip: they won't be analyzed;
338+
# can use regexp here: generated.*, regexp is applied on full path;
339+
# default value is empty list, but next dirs are always skipped independently
340+
# from this option's value:
341+
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
342+
skip-dirs:
343+
- src/external_libs
344+
- autogenerated_by_my_lib
345+
346+
# which files to skip: they will be analyzed, but issues from them
347+
# won't be reported. Default value is empty list, but there is
348+
# no need to include all autogenerated files, we confidently recognize
349+
# autogenerated files. If it's not please let us know.
350+
skip-files:
351+
- ".*\\.my\\.go$"
352+
- lib/bad.go
353+
354+
# output configuration options
355+
output:
356+
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
357+
format: colored-line-number
358+
359+
# print lines of code with issue, default is true
360+
print-issued-lines: true
361+
362+
# print linter name in the end of issue text, default is true
363+
print-linter-name: true
364+
365+
# all available settings of specific linters
366+
linters-settings:
367+
errcheck:
368+
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
369+
# default is false: such cases aren't reported by default.
370+
check-type-assertions: false
371+
372+
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
373+
# default is false: such cases aren't reported by default.
374+
check-blank: false
375+
govet:
376+
# report about shadowed variables
377+
check-shadowing: true
378+
379+
# Obtain type information from installed (to $GOPATH/pkg) package files:
380+
# golangci-lint will execute `go install -i` and `go test -i` for analyzed packages
381+
# before analyzing them.
382+
# By default this option is disabled and govet gets type information by loader from source code.
383+
# Loading from source code is slow, but it's done only once for all linters.
384+
# Go-installing of packages first time is much slower than loading them from source code,
385+
# therefore this option is disabled by default.
386+
# But repeated installation is fast in go >= 1.10 because of build caching.
387+
# Enable this option only if all conditions are met:
388+
# 1. you use only "fast" linters (--fast e.g.): no program loading occurs
389+
# 2. you use go >= 1.10
390+
# 3. you do repeated runs (false for CI) or cache $GOPATH/pkg or `go env GOCACHE` dir in CI.
391+
use-installed-packages: false
392+
golint:
393+
# minimal confidence for issues, default is 0.8
394+
min-confidence: 0.8
395+
gofmt:
396+
# simplify code: gofmt with `-s` option, true by default
397+
simplify: true
398+
gocyclo:
399+
# minimal code complexity to report, 30 by default (but we recommend 10-20)
400+
min-complexity: 10
401+
maligned:
402+
# print struct with more effective memory layout or not, false by default
403+
suggest-new: true
404+
dupl:
405+
# tokens count to trigger issue, 150 by default
406+
threshold: 100
407+
goconst:
408+
# minimal length of string constant, 3 by default
409+
min-len: 3
410+
# minimal occurrences count to trigger, 3 by default
411+
min-occurrences: 3
412+
depguard:
413+
list-type: blacklist
414+
include-go-root: false
415+
packages:
416+
- github.com/davecgh/go-spew/spew
417+
418+
linters:
419+
enable:
420+
- megacheck
421+
- govet
422+
enable-all: false
423+
disable:
424+
maligned
425+
disable-all: false
426+
presets:
427+
- bugs
428+
- unused
429+
fast: false
430+
431+
issues:
432+
# List of regexps of issue texts to exclude, empty list by default.
433+
# But independently from this option we use default exclude patterns,
434+
# it can be disabled by `exclude-use-default: false`. To list all
435+
# excluded by default patterns execute `golangci-lint run --help`
436+
exclude:
437+
- abcdef
438+
439+
# Independently from option `exclude` we use default exclude patterns,
440+
# it can be disabled by this option. To list all
441+
# excluded by default patterns execute `golangci-lint run --help`.
442+
# Default value for this option is false.
443+
exclude-use-default: true
444+
445+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
446+
max-per-linter: 0
447+
448+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
449+
max-same: 0
450+
451+
# Show only new issues: if there are unstaged changes or untracked files,
452+
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
453+
# It's a super-useful option for integration of golangci-lint into existing
454+
# large codebase. It's not practical to fix all existing issues at the moment
455+
# of integration: much better don't allow issues in new code.
456+
# Default is false.
457+
new: false
458+
459+
# Show only new issues created after git revision `REV`
460+
new-from-rev: REV
461+
462+
# Show only new issues created in git patch with set file path.
463+
new-from-patch: path/to/patch/file
464+
```
314465
315466
It's a [.golangci.yml](https://github.com/golangci/golangci-lint/blob/master/.golangci.yml) config file of this repo: we enable more linters
316-
than the default and more strict settings:
467+
than the default and have more strict settings:
317468
```yaml
318469
linters-settings:
319470
govet:

Diff for: README.md.tmpl

+6-2
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,14 @@ To see which config file is being used and where it was sourced from run golangc
200200
Config options inside the file are identical to command-line options.
201201
You can configure specific linters' options only within the config file (not the command-line).
202202

203-
There is a [`.golangci.yml`](https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml) example config file with all supported options.
203+
There is a [`.golangci.yml`](https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml) example
204+
config file with all supported options, their description and default value:
205+
```yaml
206+
{{.GolangciYamlExample}}
207+
```
204208

205209
It's a [.golangci.yml](https://github.com/golangci/golangci-lint/blob/master/.golangci.yml) config file of this repo: we enable more linters
206-
than the default and more strict settings:
210+
than the default and have more strict settings:
207211
```yaml
208212
{{.GolangciYaml}}
209213
```

Diff for: pkg/config/config.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ type LintersSettings struct {
119119
CheckAssignToBlank bool `mapstructure:"check-blank"`
120120
}
121121
Govet struct {
122-
CheckShadowing bool `mapstructure:"check-shadowing"`
122+
CheckShadowing bool `mapstructure:"check-shadowing"`
123+
UseInstalledPackages bool `mapstructure:"use-installed-packages"`
123124
}
124125
Golint struct {
125126
MinConfidence float64 `mapstructure:"min-confidence"`

0 commit comments

Comments
 (0)