Skip to content

Commit 76f6c53

Browse files
authored
Merge pull request #106 from oschwald/greg/fix-golangci-lint
Update golangci-lint config and rearrange structs to improve alignment
2 parents 1a23527 + 0a1d18f commit 76f6c53

File tree

4 files changed

+151
-127
lines changed

4 files changed

+151
-127
lines changed

.golangci.toml

Lines changed: 69 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
[run]
22
deadline = "10m"
3-
43
tests = true
54

65
[linters]
76
disable-all = true
87
enable = [
8+
"asasalint",
99
"asciicheck",
1010
"bidichk",
1111
"bodyclose",
1212
"containedctx",
1313
"contextcheck",
1414
"depguard",
15+
"dupword",
1516
"durationcheck",
1617
"errcheck",
1718
"errchkjson",
1819
"errname",
1920
"errorlint",
21+
# "exhaustive",
2022
"exportloopref",
2123
"forbidigo",
22-
#"forcetypeassert",
2324
"goconst",
2425
"gocyclo",
2526
"gocritic",
@@ -42,6 +43,7 @@
4243
"nosprintfhostport",
4344
"predeclared",
4445
"revive",
46+
"rowserrcheck",
4547
"sqlclosecheck",
4648
"staticcheck",
4749
"stylecheck",
@@ -51,10 +53,17 @@
5153
"unconvert",
5254
"unparam",
5355
"unused",
56+
"usestdlibvars",
5457
"vetshadow",
58+
"wastedassign",
5559
]
5660

61+
[[linters-settings.depguard.rules.main.deny]]
62+
pkg = "io/ioutil"
63+
desc = "Deprecated. Functions have been moved elsewhere."
64+
5765
[linters-settings.errcheck]
66+
check-blank = true
5867
# Ignoring Close so that we don't have to have a bunch of
5968
# `defer func() { _ = r.Close() }()` constructs when we
6069
# don't actually care about the error.
@@ -68,6 +77,15 @@
6877
[linters-settings.exhaustive]
6978
default-signifies-exhaustive = true
7079

80+
[linters-settings.forbidigo]
81+
# Forbid the following identifiers
82+
forbid = [
83+
"Geoip", # use "GeoIP"
84+
"^geoIP", # use "geoip"
85+
"Maxmind", # use "MaxMind"
86+
"^maxMind", # use "maxmind"
87+
]
88+
7189
[linters-settings.gocritic]
7290
enabled-checks = [
7391
"appendAssign",
@@ -89,8 +107,7 @@
89107
"commentedOutImport",
90108
"commentFormatting",
91109
"defaultCaseOrder",
92-
# Revive's defer rule already captures this. This caught no extra cases.
93-
# "deferInLoop",
110+
"deferInLoop",
94111
"deferUnlambda",
95112
"deprecatedComment",
96113
"docStub",
@@ -109,12 +126,12 @@
109126
"exitAfterDefer",
110127
"exposedSyncMutex",
111128
"externalErrorReassign",
112-
# Given that all of our code runs on Linux and the / separate should
113-
# work fine, this seems less important.
114-
# "filepathJoin",
129+
"filepathJoin",
115130
"flagDeref",
116131
"flagName",
117132
"hexLiteral",
133+
"httpNoBody",
134+
"hugeParam",
118135
"ifElseChain",
119136
"importShadow",
120137
"indexAlloc",
@@ -138,22 +155,20 @@
138155
"redundantSprint",
139156
"regexpMust",
140157
"regexpPattern",
141-
# This might be good, but I don't think we want to encourage
142-
# significant changes to regexes as we port stuff from Perl.
143-
# "regexpSimplify",
158+
"regexpSimplify",
159+
"returnAfterHttpError",
144160
"ruleguard",
145161
"singleCaseSwitch",
146162
"sliceClear",
147163
"sloppyLen",
148-
# This seems like it might also be good, but a lot of existing code
149-
# fails.
150-
# "sloppyReassign",
151-
"returnAfterHttpError",
164+
"sloppyReassign",
165+
"sloppyTestFuncName",
152166
"sloppyTypeAssert",
153167
"sortSlice",
154168
"sprintfQuotedString",
155169
"sqlQuery",
156170
"stringsCompare",
171+
"stringConcatSimplify",
157172
"stringXbytes",
158173
"switchTrue",
159174
"syncMapLoadAndDelete",
@@ -168,28 +183,40 @@
168183
"underef",
169184
"unlabelStmt",
170185
"unlambda",
171-
# I am not sure we would want this linter and a lot of existing
172-
# code fails.
173186
# "unnamedResult",
174187
"unnecessaryBlock",
175188
"unnecessaryDefer",
176189
"unslice",
177190
"valSwap",
178191
"weakCond",
192+
# Covered by nolintlint
193+
# "whyNoLint"
179194
"wrapperFunc",
180195
"yodaStyleExpr",
181-
# This requires explanations for "nolint" directives. This would be
182-
# nice for gosec ones, but I am not sure we want it generally unless
183-
# we can get the false positive rate lower.
184-
# "whyNoLint"
185196
]
186197

187198
[linters-settings.gofumpt]
188199
extra-rules = true
189200
lang-version = "1.19"
190201

202+
[linters-settings.gosec]
203+
excludes = [
204+
# G104 - "Audit errors not checked." We use errcheck for this.
205+
"G104",
206+
207+
# G304 - "Potential file inclusion via variable"
208+
"G304",
209+
210+
# G306 - "Expect WriteFile permissions to be 0600 or less".
211+
"G306",
212+
213+
# Prohibits defer (*os.File).Close, which we allow when reading from file.
214+
"G307",
215+
]
216+
191217
[linters-settings.govet]
192218
"enable-all" = true
219+
disable = ["shadow"]
193220

194221
[linters-settings.lll]
195222
line-length = 120
@@ -206,8 +233,6 @@
206233
ignore-generated-header = true
207234
severity = "warning"
208235

209-
# This might be nice but it is so common that it is hard
210-
# to enable.
211236
# [[linters-settings.revive.rules]]
212237
# name = "add-constant"
213238

@@ -232,8 +257,10 @@
232257
# [[linters-settings.revive.rules]]
233258
# name = "cognitive-complexity"
234259

235-
# Probably a good rule, but we have a lot of names that
236-
# only have case differences.
260+
[[linters-settings.revive.rules]]
261+
name = "comment-spacings"
262+
arguments = ["easyjson", "nolint"]
263+
237264
# [[linters-settings.revive.rules]]
238265
# name = "confusing-naming"
239266

@@ -252,6 +279,12 @@
252279
# [[linters-settings.revive.rules]]
253280
# name = "cyclomatic"
254281

282+
[[linters-settings.revive.rules]]
283+
name = "datarace"
284+
285+
# [[linters-settings.revive.rules]]
286+
# name = "deep-exit"
287+
255288
[[linters-settings.revive.rules]]
256289
name = "defer"
257290

@@ -288,8 +321,6 @@
288321
# [[linters-settings.revive.rules]]
289322
# name = "file-header"
290323

291-
# We have a lot of flag parameters. This linter probably makes
292-
# a good point, but we would need some cleanup or a lot of nolints.
293324
# [[linters-settings.revive.rules]]
294325
# name = "flag-parameter"
295326

@@ -329,7 +360,6 @@
329360
[[linters-settings.revive.rules]]
330361
name = "modifies-value-receiver"
331362

332-
# We frequently use nested structs, particularly in tests.
333363
# [[linters-settings.revive.rules]]
334364
# name = "nested-structs"
335365

@@ -363,6 +393,9 @@
363393
[[linters-settings.revive.rules]]
364394
name = "superfluous-else"
365395

396+
[[linters-settings.revive.rules]]
397+
name = "time-equal"
398+
366399
[[linters-settings.revive.rules]]
367400
name = "time-naming"
368401

@@ -375,8 +408,6 @@
375408
[[linters-settings.revive.rules]]
376409
name = "unexported-return"
377410

378-
# This is covered elsewhere and we want to ignore some
379-
# functions such as fmt.Fprintf.
380411
# [[linters-settings.revive.rules]]
381412
# name = "unhandled-error"
382413

@@ -389,14 +420,11 @@
389420
[[linters-settings.revive.rules]]
390421
name = "unused-parameter"
391422

392-
# We generally have unused receivers in tests for meeting the
393-
# requirements of an interface.
394-
# [[linters-settings.revive.rules]]
395-
# name = "unused-receiver"
423+
[[linters-settings.revive.rules]]
424+
name = "unused-receiver"
396425

397-
# This probably makes sense after we upgrade to 1.18
398-
# [[linters-settings.revive.rules]]
399-
# name = "use-any"
426+
[[linters-settings.revive.rules]]
427+
name = "use-any"
400428

401429
[[linters-settings.revive.rules]]
402430
name = "useless-break"
@@ -413,16 +441,12 @@
413441
[linters-settings.unparam]
414442
check-exported = true
415443

444+
[issues]
445+
exclude-use-default = false
446+
416447
[[issues.exclude-rules]]
417448
linters = [
418449
"govet"
419450
]
420-
# we want to enable almost all govet rules. It is easier to just filter out
421-
# the ones we don't want:
422-
#
423-
# * fieldalignment - way too noisy. Although it is very useful in particular
424-
# cases where we are trying to use as little memory as possible, having
425-
# it go off on every struct isn't helpful.
426-
# * shadow - although often useful, it complains about _many_ err
427-
# shadowing assignments and some others where shadowing is clear.
428-
text = "^(fieldalignment|shadow)"
451+
path = "_test.go"
452+
text = "^fieldalignment"

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module github.com/oschwald/geoip2-golang
33
go 1.19
44

55
require (
6-
github.com/oschwald/maxminddb-golang v1.10.0
6+
github.com/oschwald/maxminddb-golang v1.11.0
77
github.com/stretchr/testify v1.8.4
88
)
99

1010
require (
1111
github.com/davecgh/go-spew v1.1.1 // indirect
1212
github.com/pmezard/go-difflib v1.0.0 // indirect
13-
golang.org/x/sys v0.5.0 // indirect
13+
golang.org/x/sys v0.9.0 // indirect
1414
gopkg.in/yaml.v3 v3.0.1 // indirect
1515
)

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/oschwald/maxminddb-golang v1.10.0 h1:Xp1u0ZhqkSuopaKmk1WwHtjF0H9Hd9181uj2MQ5Vndg=
4-
github.com/oschwald/maxminddb-golang v1.10.0/go.mod h1:Y2ELenReaLAZ0b400URyGwvYxHV1dLIxBuyOsyYjHK0=
3+
github.com/oschwald/maxminddb-golang v1.11.0 h1:aSXMqYR/EPNjGE8epgqwDay+P30hCBZIveY0WZbAWh0=
4+
github.com/oschwald/maxminddb-golang v1.11.0/go.mod h1:YmVI+H0zh3ySFR3w+oz8PCfglAFj3PuCmui13+P9zDg=
55
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
66
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
77
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
88
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
9-
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
10-
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9+
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
10+
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1111
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1212
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1313
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

0 commit comments

Comments
 (0)