Skip to content

Commit 6237e59

Browse files
authored
dev: use goprintffuncname, gomnd and rowserrcheck (#927)
Order linters in config in alphabetical order. Support gomnd configuration.
1 parent 88b6c25 commit 6237e59

File tree

18 files changed

+301
-257
lines changed

18 files changed

+301
-257
lines changed

.golangci.example.yml

Lines changed: 84 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ output:
6767

6868
# all available settings of specific linters
6969
linters-settings:
70+
dogsled:
71+
# checks assignments with too many blank identifiers; default is 2
72+
max-blank-identifiers: 2
73+
dupl:
74+
# tokens count to trigger issue, 150 by default
75+
threshold: 100
7076
errcheck:
7177
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
7278
# default is false: such cases aren't reported by default.
@@ -84,11 +90,64 @@ linters-settings:
8490
# path to a file containing a list of functions to exclude from checking
8591
# see https://github.com/kisielk/errcheck#excluding-functions for details
8692
exclude: /path/to/file.txt
87-
8893
funlen:
8994
lines: 60
9095
statements: 40
96+
gocognit:
97+
# minimal code complexity to report, 30 by default (but we recommend 10-20)
98+
min-complexity: 10
99+
goconst:
100+
# minimal length of string constant, 3 by default
101+
min-len: 3
102+
# minimal occurrences count to trigger, 3 by default
103+
min-occurrences: 3
104+
gocritic:
105+
# Which checks should be enabled; can't be combined with 'disabled-checks';
106+
# See https://go-critic.github.io/overview#checks-overview
107+
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
108+
# By default list of stable checks is used.
109+
enabled-checks:
110+
- rangeValCopy
111+
112+
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
113+
disabled-checks:
114+
- regexpMust
115+
116+
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
117+
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
118+
enabled-tags:
119+
- performance
91120

121+
settings: # settings passed to gocritic
122+
captLocal: # must be valid enabled check name
123+
paramsOnly: true
124+
rangeValCopy:
125+
sizeThreshold: 32
126+
gocyclo:
127+
# minimal code complexity to report, 30 by default (but we recommend 10-20)
128+
min-complexity: 10
129+
godox:
130+
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
131+
# might be left in the code accidentally and should be resolved before merging
132+
keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
133+
- NOTE
134+
- OPTIMIZE # marks code that should be optimized before merging
135+
- HACK # marks hack-arounds that should be removed before merging
136+
gofmt:
137+
# simplify code: gofmt with `-s` option, true by default
138+
simplify: true
139+
goimports:
140+
# put imports beginning with prefix after 3rd-party packages;
141+
# it's a comma-separated list of prefixes
142+
local-prefixes: github.com/org/project
143+
golint:
144+
# minimal confidence for issues, default is 0.8
145+
min-confidence: 0.8
146+
gomnd:
147+
settings:
148+
mnd:
149+
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
150+
checks: argument,case,condition,operation,return,assign
92151
govet:
93152
# report about shadowed variables
94153
check-shadowing: true
@@ -109,33 +168,6 @@ linters-settings:
109168
disable:
110169
- shadow
111170
disable-all: false
112-
golint:
113-
# minimal confidence for issues, default is 0.8
114-
min-confidence: 0.8
115-
gofmt:
116-
# simplify code: gofmt with `-s` option, true by default
117-
simplify: true
118-
goimports:
119-
# put imports beginning with prefix after 3rd-party packages;
120-
# it's a comma-separated list of prefixes
121-
local-prefixes: github.com/org/project
122-
gocyclo:
123-
# minimal code complexity to report, 30 by default (but we recommend 10-20)
124-
min-complexity: 10
125-
gocognit:
126-
# minimal code complexity to report, 30 by default (but we recommend 10-20)
127-
min-complexity: 10
128-
maligned:
129-
# print struct with more effective memory layout or not, false by default
130-
suggest-new: true
131-
dupl:
132-
# tokens count to trigger issue, 150 by default
133-
threshold: 100
134-
goconst:
135-
# minimal length of string constant, 3 by default
136-
min-len: 3
137-
# minimal occurrences count to trigger, 3 by default
138-
min-occurrences: 3
139171
depguard:
140172
list-type: blacklist
141173
include-go-root: false
@@ -144,34 +176,22 @@ linters-settings:
144176
packages-with-error-message:
145177
# specify an error message to output when a blacklisted package is used
146178
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
179+
lll:
180+
# max line length, lines longer will be reported. Default is 120.
181+
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
182+
line-length: 120
183+
# tab width in spaces. Default to 1.
184+
tab-width: 1
185+
maligned:
186+
# print struct with more effective memory layout or not, false by default
187+
suggest-new: true
147188
misspell:
148189
# Correct spellings using locale preferences for US or UK.
149190
# Default is to use a neutral variety of English.
150191
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
151192
locale: US
152193
ignore-words:
153194
- someword
154-
lll:
155-
# max line length, lines longer will be reported. Default is 120.
156-
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
157-
line-length: 120
158-
# tab width in spaces. Default to 1.
159-
tab-width: 1
160-
rowserrcheck:
161-
packages:
162-
- github.com/jmoiron/sqlx
163-
unused:
164-
# treat code as a program (not a library) and report unused exported identifiers; default is false.
165-
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
166-
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
167-
# with golangci-lint call it on a directory with the changed file.
168-
check-exported: false
169-
unparam:
170-
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
171-
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
172-
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
173-
# with golangci-lint call it on a directory with the changed file.
174-
check-exported: false
175195
nakedret:
176196
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
177197
max-func-lines: 30
@@ -184,39 +204,21 @@ linters-settings:
184204
simple: true
185205
range-loops: true # Report preallocation suggestions on range loops, true by default
186206
for-loops: false # Report preallocation suggestions on for loops, false by default
187-
gocritic:
188-
# Which checks should be enabled; can't be combined with 'disabled-checks';
189-
# See https://go-critic.github.io/overview#checks-overview
190-
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
191-
# By default list of stable checks is used.
192-
enabled-checks:
193-
- rangeValCopy
194-
195-
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
196-
disabled-checks:
197-
- regexpMust
198-
199-
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
200-
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
201-
enabled-tags:
202-
- performance
203-
204-
settings: # settings passed to gocritic
205-
captLocal: # must be valid enabled check name
206-
paramsOnly: true
207-
rangeValCopy:
208-
sizeThreshold: 32
209-
godox:
210-
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
211-
# might be left in the code accidentally and should be resolved before merging
212-
keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
213-
- NOTE
214-
- OPTIMIZE # marks code that should be optimized before merging
215-
- HACK # marks hack-arounds that should be removed before merging
216-
dogsled:
217-
# checks assignments with too many blank identifiers; default is 2
218-
max-blank-identifiers: 2
219-
207+
rowserrcheck:
208+
packages:
209+
- github.com/jmoiron/sqlx
210+
unparam:
211+
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
212+
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
213+
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
214+
# with golangci-lint call it on a directory with the changed file.
215+
check-exported: false
216+
unused:
217+
# treat code as a program (not a library) and report unused exported identifiers; default is false.
218+
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
219+
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
220+
# with golangci-lint call it on a directory with the changed file.
221+
check-exported: false
220222
whitespace:
221223
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
222224
multi-func: false # Enforces newlines (or comments) after every multi-line function signature

.golangci.yml

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
11
linters-settings:
2-
govet:
3-
check-shadowing: true
4-
settings:
5-
printf:
6-
funcs:
7-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
8-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
9-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
10-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
11-
golint:
12-
min-confidence: 0
13-
gocyclo:
14-
min-complexity: 15
15-
maligned:
16-
suggest-new: true
17-
dupl:
18-
threshold: 100
19-
goconst:
20-
min-len: 2
21-
min-occurrences: 2
222
depguard:
233
list-type: blacklist
244
packages:
@@ -27,12 +7,14 @@ linters-settings:
277
- github.com/sirupsen/logrus
288
packages-with-error-message:
299
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
30-
misspell:
31-
locale: US
32-
lll:
33-
line-length: 140
34-
goimports:
35-
local-prefixes: github.com/golangci/golangci-lint
10+
dupl:
11+
threshold: 100
12+
funlen:
13+
lines: 100
14+
statements: 50
15+
goconst:
16+
min-len: 2
17+
min-occurrences: 2
3618
gocritic:
3719
enabled-tags:
3820
- diagnostic
@@ -46,16 +28,38 @@ linters-settings:
4628
- octalLiteral
4729
- whyNoLint
4830
- wrapperFunc
49-
funlen:
50-
lines: 100
51-
statements: 50
31+
gocyclo:
32+
min-complexity: 15
33+
goimports:
34+
local-prefixes: github.com/golangci/golangci-lint
35+
golint:
36+
min-confidence: 0
37+
gomnd:
38+
settings:
39+
mnd:
40+
# don't include the "operation" and "assign"
41+
checks: argument,case,condition,return
42+
govet:
43+
check-shadowing: true
44+
settings:
45+
printf:
46+
funcs:
47+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
48+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
49+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
50+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
51+
lll:
52+
line-length: 140
53+
maligned:
54+
suggest-new: true
55+
misspell:
56+
locale: US
5257

5358
linters:
5459
# please, do not use `enable-all`: it's deprecated and will be removed soon.
5560
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
5661
disable-all: true
5762
enable:
58-
# - rowserrcheck
5963
- bodyclose
6064
- deadcode
6165
- depguard
@@ -70,6 +74,8 @@ linters:
7074
- gofmt
7175
- goimports
7276
- golint
77+
# - gomnd TODO: enable it with release > v1.23.0
78+
- goprintffuncname
7379
- gosec
7480
- gosimple
7581
- govet
@@ -78,6 +84,7 @@ linters:
7884
- lll
7985
- misspell
8086
- nakedret
87+
- rowserrcheck
8188
- scopelint
8289
- staticcheck
8390
- structcheck
@@ -96,6 +103,13 @@ linters:
96103
# - maligned
97104
# - prealloc
98105

106+
issues:
107+
# Excluding configuration per-path, per-linter, per-text and per-source
108+
exclude-rules:
109+
- path: _test\.go
110+
linters:
111+
- gomnd
112+
99113
run:
100114
skip-dirs:
101115
- test/testdata_etc
@@ -106,6 +120,6 @@ run:
106120
# golangci.com configuration
107121
# https://github.com/golangci/golangci/wiki/Configuration
108122
service:
109-
golangci-lint-version: 1.22.x # use the fixed version to not introduce new linters unexpectedly
123+
golangci-lint-version: 1.23.x # use the fixed version to not introduce new linters unexpectedly
110124
prepare:
111125
- echo "here I can run custom commands, but no preparation needed for this repo"

0 commit comments

Comments
 (0)