Skip to content

Commit c80675b

Browse files
authored
Merge pull request #6028 from mmorel-35/golangci-lint@v2
chore: bump golangci-lint to v2
2 parents aadd787 + ef0a5eb commit c80675b

File tree

3 files changed

+150
-164
lines changed

3 files changed

+150
-164
lines changed

.golangci.yml

Lines changed: 148 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
version: "2"
2+
3+
run:
4+
# prevent golangci-lint from deducting the go version to lint for through go.mod,
5+
# which causes it to fallback to go1.17 semantics.
6+
#
7+
# TODO(thaJeztah): update "usetesting" settings to enable go1.24 features once our minimum version is go1.24
8+
go: "1.23.8"
9+
10+
timeout: 5m
11+
12+
issues:
13+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
14+
max-issues-per-linter: 0
15+
16+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
17+
max-same-issues: 0
18+
19+
formatters:
20+
enable:
21+
- gofumpt # Detects whether code was gofumpt-ed.
22+
- goimports
23+
24+
exclusions:
25+
generated: strict
26+
127
linters:
228
enable:
329
- bodyclose
@@ -6,14 +32,12 @@ linters:
632
- dogsled
733
- dupword # Detects duplicate words.
834
- durationcheck
35+
- errcheck
936
- errchkjson
1037
- forbidigo
1138
- gocritic # Metalinter; detects bugs, performance, and styling issues.
1239
- gocyclo
13-
- gofumpt # Detects whether code was gofumpt-ed.
14-
- goimports
1540
- gosec # Detects security problems.
16-
- gosimple
1741
- govet
1842
- ineffassign
1943
- misspell # Detects commonly misspelled English words in comments.
@@ -26,10 +50,8 @@ linters:
2650
- reassign
2751
- revive # Metalinter; drop-in replacement for golint.
2852
- staticcheck
29-
- stylecheck # Replacement for golint
3053
- thelper # Detects test helpers without t.Helper().
3154
- tparallel # Detects inappropriate usage of t.Parallel().
32-
- typecheck
3355
- unconvert # Detects unnecessary type conversions.
3456
- unparam
3557
- unused
@@ -40,113 +62,82 @@ linters:
4062
disable:
4163
- errcheck
4264

43-
run:
44-
# prevent golangci-lint from deducting the go version to lint for through go.mod,
45-
# which causes it to fallback to go1.17 semantics.
46-
#
47-
# TODO(thaJeztah): update "usetesting" settings to enable go1.24 features once our minimum version is go1.24
48-
go: "1.23.8"
49-
timeout: 5m
50-
51-
linters-settings:
52-
depguard:
53-
rules:
54-
main:
55-
deny:
56-
- pkg: "github.com/containerd/containerd/errdefs"
57-
desc: The containerd errdefs package was migrated to a separate module. Use github.com/containerd/errdefs instead.
58-
- pkg: "github.com/containerd/containerd/log"
59-
desc: The containerd log package was migrated to a separate module. Use github.com/containerd/log instead.
60-
- pkg: "github.com/containerd/containerd/pkg/userns"
61-
desc: Use github.com/moby/sys/userns instead.
62-
- pkg: "github.com/containerd/containerd/platforms"
63-
desc: The containerd platforms package was migrated to a separate module. Use github.com/containerd/platforms instead.
64-
- pkg: "github.com/docker/docker/pkg/system"
65-
desc: This package should not be used unless strictly necessary.
66-
- pkg: "github.com/docker/distribution/uuid"
67-
desc: Use github.com/google/uuid instead.
68-
- pkg: "io/ioutil"
69-
desc: The io/ioutil package has been deprecated, see https://go.dev/doc/go1.16#ioutil
70-
forbidigo:
71-
forbid:
72-
- pkg: ^regexp$
73-
p: ^regexp\.MustCompile
74-
msg: Use internal/lazyregexp.New instead.
75-
gocyclo:
76-
min-complexity: 16
77-
gosec:
78-
excludes:
79-
- G104 # G104: Errors unhandled; (TODO: reduce unhandled errors, or explicitly ignore)
80-
- G113 # G113: Potential uncontrolled memory consumption in Rat.SetString (CVE-2022-23772); (only affects go < 1.16.14. and go < 1.17.7)
81-
- G115 # G115: integer overflow conversion; (TODO: verify these: https://github.com/docker/cli/issues/5584)
82-
- G306 # G306: Expect WriteFile permissions to be 0600 or less (too restrictive; also flags "0o644" permissions)
83-
- G307 # G307: Deferring unsafe method "*os.File" on type "Close" (also EXC0008); (TODO: evaluate these and fix where needed: G307: Deferring unsafe method "*os.File" on type "Close")
84-
govet:
85-
enable:
86-
- shadow
87-
settings:
88-
shadow:
89-
strict: true
90-
lll:
91-
line-length: 200
92-
nakedret:
93-
# Disallow naked returns if func has more lines of code than this setting.
94-
# Default: 30
95-
max-func-lines: 0
96-
97-
revive:
98-
rules:
99-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-block
100-
- name: empty-block
101-
severity: warning
102-
disabled: false
103-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines
104-
- name: empty-lines
105-
severity: warning
106-
disabled: false
107-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-shadowing
108-
- name: import-shadowing
109-
severity: warning
110-
disabled: false
111-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#line-length-limit
112-
- name: line-length-limit
113-
severity: warning
114-
disabled: false
115-
arguments: [200]
116-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver
117-
- name: unused-receiver
118-
severity: warning
119-
disabled: false
120-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#use-any
121-
- name: use-any
122-
severity: warning
123-
disabled: false
124-
125-
usetesting:
126-
# FIXME(thaJeztah): Disable `os.Chdir()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
127-
os-chdir: false
128-
# FIXME(thaJeztah): Disable `context.Background()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
129-
context-background: false
130-
# FIXME(thaJeztah): Disable `context.TODO()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
131-
context-todo: false
132-
133-
issues:
134-
# The default exclusion rules are a bit too permissive, so copying the relevant ones below
135-
exclude-use-default: false
136-
137-
# This option has been defined when Go modules was not existed and when the
138-
# golangci-lint core was different, this is not something we still recommend.
139-
exclude-dirs-use-default: false
140-
141-
exclude:
142-
- parameter .* always receives
143-
144-
exclude-files:
145-
- cli/compose/schema/bindata.go
146-
- .*generated.*
147-
148-
exclude-rules:
149-
# We prefer to use an "exclude-list" so that new "default" exclusions are not
65+
settings:
66+
depguard:
67+
rules:
68+
main:
69+
deny:
70+
- pkg: "github.com/containerd/containerd/errdefs"
71+
desc: The containerd errdefs package was migrated to a separate module. Use github.com/containerd/errdefs instead.
72+
- pkg: "github.com/containerd/containerd/log"
73+
desc: The containerd log package was migrated to a separate module. Use github.com/containerd/log instead.
74+
- pkg: "github.com/containerd/containerd/pkg/userns"
75+
desc: Use github.com/moby/sys/userns instead.
76+
- pkg: "github.com/containerd/containerd/platforms"
77+
desc: The containerd platforms package was migrated to a separate module. Use github.com/containerd/platforms instead.
78+
- pkg: "github.com/docker/docker/pkg/system"
79+
desc: This package should not be used unless strictly necessary.
80+
- pkg: "github.com/docker/distribution/uuid"
81+
desc: Use github.com/google/uuid instead.
82+
- pkg: "io/ioutil"
83+
desc: The io/ioutil package has been deprecated, see https://go.dev/doc/go1.16#ioutil
84+
85+
forbidigo:
86+
forbid:
87+
- pkg: ^regexp$
88+
pattern: ^regexp\.MustCompile
89+
msg: Use internal/lazyregexp.New instead.
90+
91+
gocyclo:
92+
min-complexity: 16
93+
94+
gosec:
95+
excludes:
96+
- G104 # G104: Errors unhandled; (TODO: reduce unhandled errors, or explicitly ignore)
97+
- G115 # G115: integer overflow conversion; (TODO: verify these: https://github.com/docker/cli/issues/5584)
98+
- G306 # G306: Expect WriteFile permissions to be 0600 or less (too restrictive; also flags "0o644" permissions)
99+
- G307 # G307: Deferring unsafe method "*os.File" on type "Close" (also EXC0008); (TODO: evaluate these and fix where needed: G307: Deferring unsafe method "*os.File" on type "Close")
100+
101+
govet:
102+
enable:
103+
- shadow
104+
settings:
105+
shadow:
106+
strict: true
107+
108+
lll:
109+
line-length: 200
110+
111+
nakedret:
112+
# Disallow naked returns if func has more lines of code than this setting.
113+
# Default: 30
114+
max-func-lines: 0
115+
116+
staticcheck:
117+
checks:
118+
- all
119+
- -QF1003 # FIXME Convert if/else-if chain to tagged switch
120+
- -QF1008 # FIXME Omit embedded fields from selector expression
121+
- -ST1020 # FIXME The documentation of an exported function should start with the function’s name
122+
- -ST1022 # FIXME The documentation of an exported variable or constant should start with variable’s name
123+
124+
revive:
125+
rules:
126+
- name: empty-block # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-block
127+
- name: empty-lines # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines
128+
- name: import-shadowing # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-shadowing
129+
- name: line-length-limit # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#line-length-limit
130+
arguments: [200]
131+
- name: unused-receiver # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver
132+
- name: use-any # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#use-any
133+
134+
usetesting:
135+
os-chdir: false # FIXME(thaJeztah): Disable `os.Chdir()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
136+
context-background: false # FIXME(thaJeztah): Disable `context.Background()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
137+
context-todo: false # FIXME(thaJeztah): Disable `context.TODO()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
138+
139+
exclusions:
140+
# We prefer to use an "linters.exclusions.rules" so that new "default" exclusions are not
150141
# automatically inherited. We can decide whether or not to follow upstream
151142
# defaults when updating golang-ci-lint versions.
152143
# Unfortunately, this means we have to copy the whole exclusion pattern, as
@@ -158,54 +149,49 @@ issues:
158149
#
159150
# The default list of exclusions can be found at:
160151
# https://golangci-lint.run/usage/false-positives/#default-exclusions
152+
generated: strict
161153

162-
# EXC0001
163-
- text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*print(f|ln)?|os\\.(Un)?Setenv). is not checked"
164-
linters:
165-
- errcheck
166-
# EXC0003
167-
- text: "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this"
168-
linters:
169-
- revive
170-
# EXC0006
171-
- text: "Use of unsafe calls should be audited"
172-
linters:
173-
- gosec
174-
# EXC0007
175-
- text: "Subprocess launch(ed with variable|ing should be audited)"
176-
linters:
177-
- gosec
178-
# EXC0009
179-
- text: "(Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)"
180-
linters:
181-
- gosec
182-
# EXC0010
183-
- text: "Potential file inclusion via variable"
184-
linters:
185-
- gosec
186-
187-
# TODO: make sure all packages have a description. Currently, there's 67 packages without.
188-
- text: "package-comments: should have a package comment"
189-
linters:
190-
- revive
191-
192-
# Exclude some linters from running on tests files.
193-
- path: _test\.go
194-
linters:
195-
- errcheck
196-
- gosec
197-
- text: "ST1000: at least one file in a package should have a package comment"
198-
linters:
199-
- stylecheck
200-
201-
# Allow "err" and "ok" vars to shadow existing declarations, otherwise we get too many false positives.
202-
- text: '^shadow: declaration of "(err|ok)" shadows declaration'
203-
linters:
204-
- govet
205-
206-
207-
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
208-
max-issues-per-linter: 0
209-
210-
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
211-
max-same-issues: 0
154+
rules:
155+
# EXC0003
156+
- text: "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this"
157+
linters:
158+
- revive
159+
160+
# EXC0007
161+
- text: "Subprocess launch(ed with variable|ing should be audited)"
162+
linters:
163+
- gosec
164+
165+
# EXC0009
166+
- text: "(Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)"
167+
linters:
168+
- gosec
169+
170+
# EXC0010
171+
- text: "Potential file inclusion via variable"
172+
linters:
173+
- gosec
174+
175+
# TODO: make sure all packages have a description. Currently, there's 67 packages without.
176+
- text: "package-comments: should have a package comment"
177+
linters:
178+
- revive
179+
180+
# Exclude some linters from running on tests files.
181+
- path: _test\.go
182+
linters:
183+
- errcheck
184+
- gosec
185+
186+
- text: "ST1000: at least one file in a package should have a package comment"
187+
linters:
188+
- staticcheck
189+
190+
# Allow "err" and "ok" vars to shadow existing declarations, otherwise we get too many false positives.
191+
- text: '^shadow: declaration of "(err|ok)" shadows declaration'
192+
linters:
193+
- govet
194+
195+
# Log a warning if an exclusion rule is unused.
196+
# Default: false
197+
warn-unused: true

cli/command/formatter/tabwriter/tabwriter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
// based on https://github.com/golang/go/blob/master/src/text/tabwriter/tabwriter.go Last modified 690ac40 on 31 Jan
1414

15-
//nolint:gocyclo,nakedret,stylecheck,unused // ignore linting errors, so that we can stick close to upstream
15+
//nolint:gocyclo,nakedret,unused // ignore linting errors, so that we can stick close to upstream
1616
package tabwriter
1717

1818
import (

dockerfiles/Dockerfile.lint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
ARG GO_VERSION=1.23.8
44
ARG ALPINE_VERSION=3.21
5-
ARG GOLANGCI_LINT_VERSION=v1.64.5
5+
ARG GOLANGCI_LINT_VERSION=v2.1.2
66

77
FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint
88

0 commit comments

Comments
 (0)