-
Notifications
You must be signed in to change notification settings - Fork 0
/
.golangci.yaml
195 lines (184 loc) · 6.3 KB
/
.golangci.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# Comments started with [!] are explanations of my workflow with golangci-lint.
# Another comments are real comments in my config.
# [!] Examine the https://golangci-lint.run/usage/configuration/ to know all possibilities.
run:
timeout: 5m
modules-download-mode: vendor # [!] if you are using vendoring
build-tags:
- integration # [!] If you disable code for integration tests to run all unit tests, enable it to lint all the same.
# [!] Linters are enabled manually. Disabled linters are commented and have comment about reason of disabling.
# [!] Linters disabled inside source code by //nolint should be specific and comments like this
# [!] //nolint:gocyclo // This legacy function is complex but the team too busy to simplify it.
# [!] (see also nolintlint settings).
#
# [!] During update version of golangci-lint do the following:
# [!] - add new linters to enable-list
# [!] - enable previously disabled linters if needed
# [!] - configure (see below) or disable new linters to be appropriate for your project
linters:
disable-all: true
enable:
- asciicheck
- bidichk
- bodyclose
- contextcheck
# - cyclop
# Measuring code complexity is hard. Cyclomatic complexity is doubtfully
# a reliable metric for this purpose. Some problems are complex by nature
# and therefore more cyclomatically complex code might actually be
# simpler.
- deadcode
- depguard
- dogsled
- dupl
- durationcheck
- errname
- errcheck
- errorlint
- exhaustive
# - exhaustivestruct
# We frequently make use of zero-values and partial initialization.
- exportloopref
- forbidigo
- forcetypeassert
- funlen
- gci
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godot
# - godox
# TODOs and FIXMEs function as a big warning sign: "Beware! This code has
# bugs and other problems. Be careful not to make things worse when
# editing. Or better fix the issues before implementing a new feature on
# top.". The idea of [`godox` comment
# extractor](https://github.com/766b/godox) seems to be different from
# the idea of [`godox` linter](https://github.com/matoous/godox). The
# first one lets you quickly browse through the code problems, while the
# second one asks you to remove that big warning sign in favor of tasks.
# Though tasks are great, they will not help you while editing.
- goerr113
- gofmt
- gofumpt
- goheader
- goimports
# - golint # Replaced by `revive`.
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
- ifshort
- importas
# - ireturn # See: https://github.com/go-proverbs/go-proverbs.github.io/issues/37.
- ineffassign
# - interfacer # Is prone to bad suggestions (officialy deprecated).
- lll
# - maligned # Replaced by `govet`'s `fieldalignment`
- makezero
- misspell
- nakedret
- nestif
- nilnil # Zero-value of maps, slices and channels is `nil` but useful.
- nilerr
# - nlreturn # Too subjective.
- noctx
- nolintlint
- paralleltest
- prealloc
- predeclared
- promlinter
- revive
- rowserrcheck
# - scopelint # Replaced by `exportloopref`.
- sqlclosecheck
- staticcheck
- structcheck
- stylecheck
- tagliatelle
- tenv
- testpackage
- thelper
- tparallel
- typecheck
- unconvert
- unparam
# - varnamelen
# Though the idea is idiomatic, the length is not the only thing that
# determines whether a variable is "easy to use".
- unused
- varcheck
- wastedassign
- whitespace
# - wrapcheck # Is prone to bad suggestions (especially see issue #1).
# - wsl # Too aggressive. Might be useful if it could do auto fix.
# [!] Linters has a lot of settings and can be flexible configured.
linters-settings:
lll:
line-length: 110
gci:
local-prefixes: <your go module>
forbidigo: # [!] Useful to check some code writing rules. E.g. this config contains example of using own logger instead of gloabl zap.
forbid:
- os.Exit # it's not safe to exit in random places, because defer will not work.
- log.Fatal.* # it calls os.Exit (see above)
# - c.viper # forbid it after full migrate to new declarative configs (see PLFM-616).
nilnil:
checked-types: # [!] choose only types relative to your code base or disable this linter.
- ptr
- func
- iface
nolintlint:
require-explanation: true # [!] it forces you to write explantion of //nolint comments.
require-specific: true
tagliatelle: # [!] configure it accordingly to your project rules.
case:
use-field-name: false
rules:
json: snake
yaml: snake
# [!] Extremly useful section to disable some linters.
issues:
exclude-rules:
- path: (_test\.go|apitest)
linters:
- forcetypeassert # it's ok to have some type risks in tests
- gosec # security is not make sense in tests
- noctx # it's ok to do simple http request without context in tests
# Exclude lll issues for long lines with go:generate
- linters:
- lll
source: "^//go:generate "
# They are using same environment
- path: tests/integration
linters:
- paralleltest
# Init and New functions is a glue for service. They can be long, but simple.
- linters:
- funlen
path: service\.go
source: "Init|New"
# We allow to log.Fatal in main, tests, scripts and generators.
- path: main.go|main_test.go|tests|scripts|internal/blueprint/generator/generator.go|build/dockergen.go
linters:
- forbidigo
text: "forbidden by pattern `log.Fatal.*`"
# We allow to os.Exit in main, tests, scripts and generators.
- path: main.go|main_test.go|tests|scripts|internal/blueprint/generator/generator.go|build/dockergen.go
linters:
- forbidigo
text: "forbidden by pattern `os.Exit`"
# We have a lot of nil-tolerant types here.
- path: <package with a lot of nil-tolerant types>
linters:
- nilnil
# Should be fixed after full migration to generated config PLFM-616.
- path: config.go
linters:
- unparam
text: "newConfig - result 1 \\(error\\) is always nil"