Skip to content

Commit 332c159

Browse files
authored
Migrate golangci-lint to v2 (#940)
* Migrate golangci-lint to v2 Signed-off-by: egibs <20933572+egibs@users.noreply.github.com> * Apply modernize fixes Signed-off-by: egibs <20933572+egibs@users.noreply.github.com> --------- Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
1 parent b205a9d commit 332c159

9 files changed

Lines changed: 140 additions & 172 deletions

File tree

.golangci.yml

Lines changed: 128 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,6 @@
1-
run:
2-
# The default runtime timeout is 1m, which doesn't work well on Github Actions.
3-
timeout: 10m
4-
5-
# NOTE: This file is populated by the lint-install tool. Local adjustments may be overwritten.
6-
linters-settings:
7-
cyclop:
8-
# NOTE: This is a very high transitional threshold
9-
max-complexity: 37
10-
package-average: 34.0
11-
skip-tests: true
12-
13-
gocognit:
14-
# NOTE: This is a very high transitional threshold
15-
min-complexity: 98
16-
17-
dupl:
18-
threshold: 200
19-
20-
goconst:
21-
min-len: 4
22-
min-occurrences: 5
23-
ignore-tests: true
24-
25-
gosec:
26-
excludes:
27-
- G107 # Potential HTTP request made with variable url
28-
- G204 # Subprocess launched with function call as argument or cmd arguments
29-
- G404 # Use of weak random number generator (math/rand instead of crypto/rand
30-
31-
errorlint:
32-
# these are still common in Go: for instance, exit errors.
33-
asserts: false
34-
# Forcing %w in error wrapping forces authors to make errors part of their package APIs. The decision to make
35-
# an error part of a package API should be a concious decision by the author.
36-
# Also see Hyrums Law.
37-
errorf: false
38-
39-
exhaustive:
40-
default-signifies-exhaustive: true
41-
42-
nestif:
43-
min-complexity: 8
44-
45-
nolintlint:
46-
require-explanation: true
47-
allow-unused: false
48-
require-specific: true
49-
50-
revive:
51-
ignore-generated-header: true
52-
severity: warning
53-
rules:
54-
- name: atomic
55-
- name: blank-imports
56-
- name: bool-literal-in-expr
57-
- name: confusing-naming
58-
- name: constant-logical-expr
59-
- name: context-as-argument
60-
- name: context-keys-type
61-
- name: deep-exit
62-
- name: defer
63-
- name: range-val-in-closure
64-
- name: range-val-address
65-
- name: dot-imports
66-
- name: error-naming
67-
- name: error-return
68-
- name: error-strings
69-
- name: errorf
70-
- name: exported
71-
- name: identical-branches
72-
- name: if-return
73-
- name: import-shadowing
74-
- name: increment-decrement
75-
- name: indent-error-flow
76-
- name: indent-error-flow
77-
- name: package-comments
78-
- name: range
79-
- name: receiver-naming
80-
- name: redefines-builtin-id
81-
- name: superfluous-else
82-
- name: struct-tag
83-
- name: time-naming
84-
- name: unexported-naming
85-
- name: unexported-return
86-
- name: unnecessary-stmt
87-
- name: unreachable-code
88-
- name: unused-parameter
89-
- name: var-declaration
90-
- name: var-naming
91-
- name: unconditional-recursion
92-
- name: waitgroup-by-value
93-
94-
output:
95-
sort-results: true
96-
1+
version: "2"
972
linters:
98-
disable-all: true
3+
default: none
994
enable:
1005
- asciicheck
1016
- bodyclose
@@ -113,13 +18,9 @@ linters:
11318
- goconst
11419
- gocritic
11520
- godot
116-
- gofmt
117-
- gofumpt
118-
- gosec
11921
- goheader
120-
- goimports
12122
- goprintffuncname
122-
- gosimple
23+
- gosec
12324
- govet
12425
- importas
12526
- ineffassign
@@ -132,72 +33,139 @@ linters:
13233
- nolintlint
13334
- prealloc
13435
- predeclared
135-
# disabling for the initial iteration of the linting tool
136-
# - promlinter
13736
- revive
138-
# - rowserrcheck - disabled because of generics, https://github.com/golangci/golangci-lint/issues/2649
139-
# - sqlclosecheck - disabled because of generics, https://github.com/golangci/golangci-lint/issues/2649
14037
- staticcheck
141-
# - structcheck - disabled because of generics, https://github.com/golangci/golangci-lint/issues/2649
142-
- stylecheck
14338
- thelper
14439
- tparallel
145-
- typecheck
14640
- unconvert
14741
- unparam
14842
- unused
149-
# - wastedassign - disabled because of generics, https://github.com/golangci/golangci-lint/issues/2649
15043
- whitespace
151-
152-
# Disabled linters, due to being misaligned with Go practices
153-
# - exhaustivestruct
154-
# - gochecknoglobals
155-
# - gochecknoinits
156-
# - goconst
157-
# - godox
158-
# - goerr113
159-
# - gomnd
160-
# - lll
161-
# - nlreturn
162-
# - testpackage
163-
# - wsl
164-
# Disabled linters, due to not being relevant to our code base:
165-
# - maligned
166-
# - prealloc "For most programs usage of prealloc will be a premature optimization."
167-
# Disabled linters due to bad error messages or bugs
168-
# - tagliatelle
169-
44+
settings:
45+
cyclop:
46+
# NOTE: This is a very high transitional threshold
47+
max-complexity: 37
48+
package-average: 34
49+
dupl:
50+
threshold: 200
51+
errorlint:
52+
# Forcing %w in error wrapping forces authors to make errors part of their package APIs. The decision to make
53+
# an error part of a package API should be a concious decision by the author.
54+
# Also see Hyrums Law.
55+
errorf: false
56+
# these are still common in Go: for instance, exit errors.
57+
asserts: false
58+
exhaustive:
59+
default-signifies-exhaustive: true
60+
gocognit:
61+
# NOTE: This is a very high transitional threshold
62+
min-complexity: 98
63+
goconst:
64+
min-len: 4
65+
min-occurrences: 5
66+
gosec:
67+
excludes:
68+
- G107 # Potential HTTP request made with variable url
69+
- G204 # Subprocess launched with function call as argument or cmd arguments
70+
- G404 # Use of weak random number generator (math/rand instead of crypto/rand
71+
nestif:
72+
min-complexity: 8
73+
nolintlint:
74+
require-explanation: true
75+
require-specific: true
76+
allow-unused: false
77+
revive:
78+
severity: warning
79+
rules:
80+
- name: atomic
81+
- name: blank-imports
82+
- name: bool-literal-in-expr
83+
- name: confusing-naming
84+
- name: constant-logical-expr
85+
- name: context-as-argument
86+
- name: context-keys-type
87+
- name: deep-exit
88+
- name: defer
89+
- name: range-val-in-closure
90+
- name: range-val-address
91+
- name: dot-imports
92+
- name: error-naming
93+
- name: error-return
94+
- name: error-strings
95+
- name: errorf
96+
- name: exported
97+
- name: identical-branches
98+
- name: if-return
99+
- name: import-shadowing
100+
- name: increment-decrement
101+
- name: indent-error-flow
102+
- name: indent-error-flow
103+
- name: package-comments
104+
- name: range
105+
- name: receiver-naming
106+
- name: redefines-builtin-id
107+
- name: superfluous-else
108+
- name: struct-tag
109+
- name: time-naming
110+
- name: unexported-naming
111+
- name: unexported-return
112+
- name: unnecessary-stmt
113+
- name: unreachable-code
114+
- name: unused-parameter
115+
- name: var-declaration
116+
- name: var-naming
117+
- name: unconditional-recursion
118+
- name: waitgroup-by-value
119+
exclusions:
120+
generated: lax
121+
presets:
122+
- comments
123+
- common-false-positives
124+
- legacy
125+
- std-error-handling
126+
rules:
127+
- linters:
128+
- dupl
129+
- errcheck
130+
- forcetypeassert
131+
- gocyclo
132+
- gosec
133+
- noctx
134+
path: _test\.go
135+
- linters:
136+
- noctx
137+
path: .*cmd.*
138+
- linters:
139+
- noctx
140+
path: main\.go
141+
- path: .*cmd.*
142+
text: deep-exit
143+
- path: main\.go
144+
text: deep-exit
145+
- linters:
146+
# This check is of questionable value
147+
- tparallel
148+
text: call t.Parallel on the top level as well as its subtests
149+
- linters:
150+
- cyclop
151+
- goconst
152+
path: (.+)_test\.go
153+
paths:
154+
- third_party$
155+
- builtin$
156+
- examples$
170157
issues:
171-
# Excluding configuration per-path, per-linter, per-text and per-source
172-
exclude-rules:
173-
- path: _test\.go
174-
linters:
175-
- dupl
176-
- errcheck
177-
- forcetypeassert
178-
- gocyclo
179-
- gosec
180-
- noctx
181-
182-
- path: .*cmd.*
183-
linters:
184-
- noctx
185-
186-
- path: main\.go
187-
linters:
188-
- noctx
189-
190-
- path: .*cmd.*
191-
text: "deep-exit"
192-
193-
- path: main\.go
194-
text: "deep-exit"
195-
196-
# This check is of questionable value
197-
- linters:
198-
- tparallel
199-
text: "call t.Parallel on the top level as well as its subtests"
200-
201158
# Don't hide lint issues just because there are many of them
202-
max-same-issues: 0
203159
max-issues-per-linter: 0
160+
max-same-issues: 0
161+
formatters:
162+
enable:
163+
- gofmt
164+
- gofumpt
165+
- goimports
166+
exclusions:
167+
generated: lax
168+
paths:
169+
- third_party$
170+
- builtin$
171+
- examples$

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ LINTERS :=
4444
FIXERS :=
4545

4646
GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml
47-
GOLANGCI_LINT_VERSION ?= v1.64.8
47+
GOLANGCI_LINT_VERSION ?= v2.1.6
4848
GOLANGCI_LINT_BIN := $(LINT_ROOT)/out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH)
4949
$(GOLANGCI_LINT_BIN):
5050
mkdir -p $(LINT_ROOT)/out/linters

pkg/compile/compile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func findRoot(start string) string {
190190
func replaceGlobal(data []byte, path string) []byte {
191191
modified := data
192192
if bytes.Contains(data, []byte(globalInclude)) {
193-
modified = bytes.Replace(data, []byte(globalInclude), []byte(fmt.Sprintf(`include "%s"`, path)), 1)
193+
modified = bytes.Replace(data, []byte(globalInclude), fmt.Appendf(nil, `include "%s"`, path), 1)
194194
}
195195
return modified
196196
}

pkg/malcontent/malcontent.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ type DiffReport struct {
116116
}
117117

118118
type Report struct {
119-
Files sync.Map `json:",omitempty" yaml:",omitempty"`
120-
Diff *DiffReport `json:",omitempty" yaml:",omitempty"`
121-
Filter string `json:",omitempty" yaml:",omitempty"`
119+
Files sync.Map
120+
Diff *DiffReport
121+
Filter string
122122
}
123123

124124
type IntMetric struct {

pkg/refresh/refresh.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ func prepareRefresh(ctx context.Context, rc Config) ([]TestData, error) {
117117

118118
ext := filepath.Ext(data)
119119
format := strings.TrimPrefix(ext, ".")
120-
switch {
121-
case format == "sdiff":
120+
switch format {
121+
case "sdiff":
122122
format = "simple"
123-
case format == "mdiff" || format == "md":
123+
case "mdiff", "md":
124124
format = "markdown"
125125
}
126126

pkg/render/markdown.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func markdownTable(ctx context.Context, fr *malcontent.FileReport, w io.Writer,
216216

217217
risk := k.Behavior.RiskLevel
218218

219-
if rc.SkipExisting && !(k.Behavior.DiffAdded || k.Behavior.DiffRemoved) {
219+
if rc.SkipExisting && !k.Behavior.DiffAdded && !k.Behavior.DiffRemoved {
220220
continue
221221
}
222222

pkg/report/report_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func BenchmarkLongestUnique(b *testing.B) {
6060
"cherrybanana",
6161
"upload_content",
6262
}
63-
for i := 0; i < b.N; i++ {
63+
for b.Loop() {
6464
longestUnique(raw)
6565
}
6666
}

pkg/report/strings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func newMatchProcessor(fc []byte, matches []yarax.Match, mp []yarax.Pattern) *ma
6464
}
6565

6666
var matchResultPool = sync.Pool{
67-
New: func() interface{} {
67+
New: func() any {
6868
s := make([]string, 0, 32)
6969
return &s
7070
},

tests/samples_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ func Benchmarks(b *testing.B, p string) {
646646
if p != "" {
647647
paths = strings.Split(p, ",")
648648
}
649-
for i := 0; i < b.N; i++ {
649+
for b.Loop() {
650650
bench := Template(b, paths)
651651
bench()
652652
}

0 commit comments

Comments
 (0)