Skip to content

Commit 03f9877

Browse files
authored
Merge pull request #3181 from crazy-max/golangci-lint-v2
update golangci-lint to v2.1.5
2 parents a9ab809 + b606e2f commit 03f9877

34 files changed

+352
-332
lines changed

.golangci.yml

Lines changed: 93 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1+
version: "2"
2+
13
run:
2-
timeout: 30m
34
modules-download-mode: vendor
45

56
linters:
7+
default: none
68
enable:
79
- bodyclose
810
- depguard
911
- forbidigo
1012
- gocritic
11-
- gofmt
12-
- goimports
1313
- gosec
14-
- gosimple
1514
- govet
1615
- ineffassign
1716
- makezero
@@ -21,99 +20,101 @@ linters:
2120
- revive
2221
- staticcheck
2322
- testifylint
24-
- typecheck
2523
- unused
2624
- whitespace
27-
disable-all: true
28-
29-
linters-settings:
30-
gocritic:
31-
disabled-checks:
32-
- "ifElseChain"
33-
- "assignOp"
34-
- "appendAssign"
35-
- "singleCaseSwitch"
36-
- "exitAfterDefer" # FIXME
37-
importas:
38-
alias:
39-
# Enforce alias to prevent it accidentally being used instead of
40-
# buildkit errdefs package (or vice-versa).
41-
- pkg: "github.com/containerd/errdefs"
42-
alias: "cerrdefs"
43-
# Use a consistent alias to prevent confusion with "github.com/moby/buildkit/client"
44-
- pkg: "github.com/docker/docker/client"
45-
alias: "dockerclient"
46-
- pkg: "github.com/opencontainers/image-spec/specs-go/v1"
47-
alias: "ocispecs"
48-
- pkg: "github.com/opencontainers/go-digest"
49-
alias: "digest"
50-
govet:
51-
enable:
52-
- nilness
53-
- unusedwrite
54-
# enable-all: true
55-
# disable:
56-
# - fieldalignment
57-
# - shadow
58-
depguard:
25+
settings:
26+
depguard:
27+
rules:
28+
main:
29+
deny:
30+
- pkg: "github.com/containerd/containerd/errdefs"
31+
desc: The containerd errdefs package was migrated to a separate module. Use github.com/containerd/errdefs instead.
32+
- pkg: "github.com/containerd/containerd/log"
33+
desc: The containerd log package was migrated to a separate module. Use github.com/containerd/log instead.
34+
- pkg: "github.com/containerd/containerd/platforms"
35+
desc: The containerd platforms package was migrated to a separate module. Use github.com/containerd/platforms instead.
36+
- pkg: "io/ioutil"
37+
desc: The io/ioutil package has been deprecated.
38+
forbidigo:
39+
forbid:
40+
- pattern: ^context\.WithCancel(# use context\.WithCancelCause instead)?$
41+
- pattern: ^context\.WithDeadline(# use context\.WithDeadline instead)?$
42+
- pattern: ^context\.WithTimeout(# use context\.WithTimeoutCause instead)?$
43+
- pattern: ^ctx\.Err(# use context\.Cause instead)?$
44+
- pattern: ^fmt\.Errorf(# use errors\.Errorf instead)?$
45+
- pattern: ^platforms\.DefaultString(# use platforms\.Format(platforms\.DefaultSpec()) instead\.)?$
46+
gocritic:
47+
disabled-checks:
48+
- "ifElseChain"
49+
- "assignOp"
50+
- "appendAssign"
51+
- "singleCaseSwitch"
52+
- "exitAfterDefer" # FIXME
53+
gosec:
54+
excludes:
55+
- G204
56+
- G402
57+
- G115
58+
config:
59+
G306: "0644"
60+
govet:
61+
enable:
62+
- nilness
63+
- unusedwrite
64+
importas:
65+
alias:
66+
- pkg: "github.com/containerd/errdefs"
67+
alias: "cerrdefs"
68+
- pkg: "github.com/docker/docker/client"
69+
alias: "dockerclient"
70+
- pkg: "github.com/opencontainers/image-spec/specs-go/v1"
71+
alias: "ocispecs"
72+
- pkg: "github.com/opencontainers/go-digest"
73+
alias: "digest"
74+
testifylint:
75+
disable:
76+
- empty
77+
- bool-compare
78+
- len
79+
- negative-positive
80+
exclusions:
81+
generated: lax
82+
presets:
83+
- comments
84+
- common-false-positives
85+
- legacy
86+
- std-error-handling
5987
rules:
60-
main:
61-
deny:
62-
- pkg: "github.com/containerd/containerd/errdefs"
63-
desc: The containerd errdefs package was migrated to a separate module. Use github.com/containerd/errdefs instead.
64-
- pkg: "github.com/containerd/containerd/log"
65-
desc: The containerd log package was migrated to a separate module. Use github.com/containerd/log instead.
66-
- pkg: "github.com/containerd/containerd/platforms"
67-
desc: The containerd platforms package was migrated to a separate module. Use github.com/containerd/platforms instead.
68-
- pkg: "io/ioutil"
69-
desc: The io/ioutil package has been deprecated.
70-
forbidigo:
71-
forbid:
72-
- '^context\.WithCancel(# use context\.WithCancelCause instead)?$'
73-
- '^context\.WithDeadline(# use context\.WithDeadline instead)?$'
74-
- '^context\.WithTimeout(# use context\.WithTimeoutCause instead)?$'
75-
- '^ctx\.Err(# use context\.Cause instead)?$'
76-
- '^fmt\.Errorf(# use errors\.Errorf instead)?$'
77-
- '^platforms\.DefaultString(# use platforms\.Format(platforms\.DefaultSpec()) instead\.)?$'
78-
gosec:
79-
excludes:
80-
- G204 # Audit use of command execution
81-
- G402 # TLS MinVersion too low
82-
- G115 # integer overflow conversion (TODO: verify these)
83-
config:
84-
G306: "0644"
85-
testifylint:
86-
disable:
87-
# disable rules that reduce the test condition
88-
- "empty"
89-
- "bool-compare"
90-
- "len"
91-
- "negative-positive"
88+
- linters:
89+
- revive
90+
text: stutters
91+
- linters:
92+
- revive
93+
text: empty-block
94+
- linters:
95+
- revive
96+
text: superfluous-else
97+
- linters:
98+
- revive
99+
text: unused-parameter
100+
- linters:
101+
- revive
102+
text: redefines-builtin-id
103+
- linters:
104+
- revive
105+
text: if-return
106+
paths:
107+
- .*\.pb\.go$
92108

109+
formatters:
110+
enable:
111+
- gofmt
112+
- goimports
113+
exclusions:
114+
generated: lax
115+
paths:
116+
- .*\.pb\.go$
93117

94118
issues:
95-
exclude-files:
96-
- ".*\\.pb\\.go$"
97-
exclude-rules:
98-
- linters:
99-
- revive
100-
text: "stutters"
101-
- linters:
102-
- revive
103-
text: "empty-block"
104-
- linters:
105-
- revive
106-
text: "superfluous-else"
107-
- linters:
108-
- revive
109-
text: "unused-parameter"
110-
- linters:
111-
- revive
112-
text: "redefines-builtin-id"
113-
- linters:
114-
- revive
115-
text: "if-return"
116-
117-
# show all
118119
max-issues-per-linter: 0
119120
max-same-issues: 0

bake/hclparser/hclparser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ func Parse(b hcl.Body, opt Opt, val any) (*ParseMeta, hcl.Diagnostics) {
936936
}
937937
}
938938
if exists {
939-
if m := oldValue.Value.MethodByName("Merge"); m.IsValid() {
939+
if m := oldValue.MethodByName("Merge"); m.IsValid() {
940940
m.Call([]reflect.Value{vv})
941941
} else {
942942
v.Elem().Field(t.idx).Index(oldValue.idx).Set(vv)

bake/hclparser/stdlib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func indexOfFunc() function.Function {
144144
},
145145
Type: function.StaticReturnType(cty.Number),
146146
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
147-
if !(args[0].Type().IsListType() || args[0].Type().IsTupleType()) {
147+
if !args[0].Type().IsListType() && !args[0].Type().IsTupleType() {
148148
return cty.NilVal, errors.New("argument must be a list or tuple")
149149
}
150150

build/build.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import (
4444
"github.com/moby/buildkit/util/progress/progresswriter"
4545
"github.com/moby/buildkit/util/tracing"
4646
"github.com/opencontainers/go-digest"
47-
specs "github.com/opencontainers/image-spec/specs-go/v1"
47+
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
4848
"github.com/pkg/errors"
4949
"github.com/sirupsen/logrus"
5050
"github.com/tonistiigi/fsutil"
@@ -76,7 +76,7 @@ type Options struct {
7676
NetworkMode string
7777
NoCache bool
7878
NoCacheFilter []string
79-
Platforms []specs.Platform
79+
Platforms []ocispecs.Platform
8080
Pull bool
8181
SecretSpecs []*controllerapi.Secret
8282
SSHSpecs []*controllerapi.SSH
@@ -600,7 +600,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opts map[
600600

601601
if pushNames != "" {
602602
err := progress.Write(pw, fmt.Sprintf("merging manifest list %s", pushNames), func() error {
603-
descs := make([]specs.Descriptor, 0, len(res))
603+
descs := make([]ocispecs.Descriptor, 0, len(res))
604604

605605
for _, r := range res {
606606
s, ok := r.ExporterResponse[exptypes.ExporterImageDescriptorKey]
@@ -609,7 +609,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opts map[
609609
if err != nil {
610610
return err
611611
}
612-
var desc specs.Descriptor
612+
var desc ocispecs.Descriptor
613613
if err := json.Unmarshal(dt, &desc); err != nil {
614614
return errors.Wrapf(err, "failed to unmarshal descriptor %s", s)
615615
}
@@ -622,7 +622,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opts map[
622622
// mediatype value in the Accept header does not seem to matter.
623623
s, ok = r.ExporterResponse[exptypes.ExporterImageDigestKey]
624624
if ok {
625-
descs = append(descs, specs.Descriptor{
625+
descs = append(descs, ocispecs.Descriptor{
626626
Digest: digest.Digest(s),
627627
MediaType: images.MediaTypeDockerSchema2ManifestList,
628628
Size: -1,

build/dial.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
"github.com/containerd/platforms"
1010
"github.com/docker/buildx/builder"
1111
"github.com/docker/buildx/util/progress"
12-
v1 "github.com/opencontainers/image-spec/specs-go/v1"
12+
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
1313
"github.com/pkg/errors"
1414
)
1515

16-
func Dial(ctx context.Context, nodes []builder.Node, pw progress.Writer, platform *v1.Platform) (net.Conn, error) {
16+
func Dial(ctx context.Context, nodes []builder.Node, pw progress.Writer, platform *ocispecs.Platform) (net.Conn, error) {
1717
nodes, err := filterAvailableNodes(nodes)
1818
if err != nil {
1919
return nil, err
@@ -23,9 +23,9 @@ func Dial(ctx context.Context, nodes []builder.Node, pw progress.Writer, platfor
2323
return nil, errors.New("no nodes available")
2424
}
2525

26-
var pls []v1.Platform
26+
var pls []ocispecs.Platform
2727
if platform != nil {
28-
pls = []v1.Platform{*platform}
28+
pls = []ocispecs.Platform{*platform}
2929
}
3030

3131
opts := map[string]Options{"default": {Platforms: pls}}

build/driver.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
gateway "github.com/moby/buildkit/frontend/gateway/client"
1515
"github.com/moby/buildkit/util/flightcontrol"
1616
"github.com/moby/buildkit/util/tracing"
17-
specs "github.com/opencontainers/image-spec/specs-go/v1"
17+
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
1818
"github.com/pkg/errors"
1919
"go.opentelemetry.io/otel/trace"
2020
"golang.org/x/sync/errgroup"
@@ -23,7 +23,7 @@ import (
2323
type resolvedNode struct {
2424
resolver *nodeResolver
2525
driverIndex int
26-
platforms []specs.Platform
26+
platforms []ocispecs.Platform
2727
}
2828

2929
func (dp resolvedNode) Node() builder.Node {
@@ -46,7 +46,7 @@ func (dp resolvedNode) BuildOpts(ctx context.Context) (gateway.BuildOpts, error)
4646
return opts[0], nil
4747
}
4848

49-
type matchMaker func(specs.Platform) platforms.MatchComparer
49+
type matchMaker func(ocispecs.Platform) platforms.MatchComparer
5050

5151
type cachedGroup[T any] struct {
5252
g flightcontrol.Group[T]
@@ -112,7 +112,7 @@ func (r *nodeResolver) Resolve(ctx context.Context, opt map[string]Options, pw p
112112
return nil, err
113113
}
114114
eg, egCtx := errgroup.WithContext(ctx)
115-
workers := make([][]specs.Platform, len(clients))
115+
workers := make([][]ocispecs.Platform, len(clients))
116116
for i, c := range clients {
117117
i, c := i, c
118118
if c == nil {
@@ -124,7 +124,7 @@ func (r *nodeResolver) Resolve(ctx context.Context, opt map[string]Options, pw p
124124
return errors.Wrap(err, "listing workers")
125125
}
126126

127-
ps := make(map[string]specs.Platform, len(ww))
127+
ps := make(map[string]ocispecs.Platform, len(ww))
128128
for _, w := range ww {
129129
for _, p := range w.Platforms {
130130
pk := platforms.Format(platforms.Normalize(p))
@@ -145,7 +145,7 @@ func (r *nodeResolver) Resolve(ctx context.Context, opt map[string]Options, pw p
145145
// (this time we don't care about imperfect matches)
146146
nodes = map[string][]*resolvedNode{}
147147
for k, opt := range opt {
148-
node, _, err := r.resolve(ctx, opt.Platforms, pw, platforms.Only, func(idx int, n builder.Node) []specs.Platform {
148+
node, _, err := r.resolve(ctx, opt.Platforms, pw, platforms.Only, func(idx int, n builder.Node) []ocispecs.Platform {
149149
return workers[idx]
150150
})
151151
if err != nil {
@@ -173,7 +173,7 @@ func (r *nodeResolver) Resolve(ctx context.Context, opt map[string]Options, pw p
173173
return nodes, nil
174174
}
175175

176-
func (r *nodeResolver) resolve(ctx context.Context, ps []specs.Platform, pw progress.Writer, matcher matchMaker, additional func(idx int, n builder.Node) []specs.Platform) ([]*resolvedNode, bool, error) {
176+
func (r *nodeResolver) resolve(ctx context.Context, ps []ocispecs.Platform, pw progress.Writer, matcher matchMaker, additional func(idx int, n builder.Node) []ocispecs.Platform) ([]*resolvedNode, bool, error) {
177177
if len(r.nodes) == 0 {
178178
return nil, true, nil
179179
}
@@ -203,7 +203,7 @@ func (r *nodeResolver) resolve(ctx context.Context, ps []specs.Platform, pw prog
203203
driverIndex: idx,
204204
}
205205
if len(ps) > 0 {
206-
node.platforms = []specs.Platform{ps[i]}
206+
node.platforms = []ocispecs.Platform{ps[i]}
207207
}
208208
nodes = append(nodes, node)
209209
}
@@ -216,9 +216,9 @@ func (r *nodeResolver) resolve(ctx context.Context, ps []specs.Platform, pw prog
216216
return nodes, perfect, nil
217217
}
218218

219-
func (r *nodeResolver) get(p specs.Platform, matcher matchMaker, additionalPlatforms func(int, builder.Node) []specs.Platform) int {
219+
func (r *nodeResolver) get(p ocispecs.Platform, matcher matchMaker, additionalPlatforms func(int, builder.Node) []ocispecs.Platform) int {
220220
best := -1
221-
bestPlatform := specs.Platform{}
221+
bestPlatform := ocispecs.Platform{}
222222
for i, node := range r.nodes {
223223
platforms := node.Platforms
224224
if additionalPlatforms != nil {

0 commit comments

Comments
 (0)