Skip to content

Commit f2f3719

Browse files
authored
Merge pull request #5955 from tonistiigi/lint-v2
lint: v2 upgrade
2 parents 07244fd + 69d3d44 commit f2f3719

File tree

152 files changed

+471
-494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+471
-494
lines changed

.golangci.yml

Lines changed: 107 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1+
version: "2"
12
run:
2-
timeout: 30m
33
modules-download-mode: vendor
4-
54
linters:
5+
default: none
66
enable:
77
- bodyclose
88
- depguard
9+
- durationcheck
910
- errname
11+
- errorlint
12+
- fatcontext
1013
- forbidigo
1114
- gocritic
12-
- gofmt
13-
- goimports
1415
- gosec
15-
- gosimple
1616
- govet
1717
- importas
1818
- ineffassign
@@ -23,105 +23,108 @@ linters:
2323
- revive
2424
- staticcheck
2525
- testifylint
26-
- typecheck
2726
- unused
27+
- usestdlibvars
2828
- whitespace
29-
disable-all: true
30-
31-
linters-settings:
32-
staticcheck:
33-
checks:
34-
- "all"
35-
gocritic:
36-
disabled-checks:
37-
- "ifElseChain"
38-
- "assignOp"
39-
- "appendAssign"
40-
- "singleCaseSwitch"
41-
govet:
42-
enable:
43-
- nilness
44-
- unusedwrite
45-
# enable-all: true
46-
# disable:
47-
# - fieldalignment
48-
# - shadow
49-
depguard:
29+
settings:
30+
depguard:
31+
rules:
32+
main:
33+
deny:
34+
- pkg: github.com/containerd/containerd/errdefs
35+
desc: The containerd errdefs package was migrated to a separate module. Use github.com/containerd/errdefs instead.
36+
- pkg: github.com/containerd/containerd/log
37+
desc: The containerd log package was migrated to a separate module. Use github.com/containerd/log instead.
38+
- pkg: github.com/containerd/containerd/pkg/userns
39+
desc: Use github.com/moby/sys/userns instead.
40+
- pkg: github.com/containerd/containerd/platforms
41+
desc: The containerd platforms package was migrated to a separate module. Use github.com/containerd/platforms instead.
42+
- pkg: github.com/containerd/nydus-snapshotter/pkg/errdefs
43+
desc: You probably meant to use github.com/containerd/errdefs
44+
- pkg: github.com/opencontainers/runc/libcontainer/userns
45+
desc: Use github.com/moby/sys/userns instead.
46+
- pkg: io/ioutil
47+
desc: The io/ioutil package has been deprecated.
48+
forbidigo:
49+
forbid:
50+
- pattern: ^context\.WithCancel(# use context\.WithCancelCause instead)?$
51+
- pattern: ^context\.WithDeadline(# use context\.WithDeadline instead)?$
52+
- pattern: ^context\.WithTimeout(# use context\.WithTimeoutCause instead)?$
53+
- pattern: ^ctx\.Err(# use context\.Cause instead)?$
54+
- pattern: ^fmt\.Errorf(# use errors\.Errorf instead)?$
55+
- pattern: ^logrus\.(Trace|Debug|Info|Warn|Warning|Error|Fatal)(f|ln)?(# use bklog\.G or bklog\.L instead of logrus directly)?$
56+
- pattern: ^platforms\.DefaultString(# use platforms\.Format(platforms\.DefaultSpec()) instead\. Be aware that DefaultSpec is for the local platform, so must be avoided when working cross-platform)?$
57+
gocritic:
58+
disabled-checks:
59+
- ifElseChain
60+
- assignOp
61+
- appendAssign
62+
- singleCaseSwitch
63+
gosec:
64+
excludes:
65+
- G101
66+
- G402
67+
- G504
68+
- G601
69+
- G115
70+
config:
71+
G306: "0644"
72+
govet:
73+
enable:
74+
- nilness
75+
- unusedwrite
76+
importas:
77+
alias:
78+
- pkg: github.com/containerd/errdefs
79+
alias: cerrdefs
80+
- pkg: github.com/opencontainers/image-spec/specs-go/v1
81+
alias: ocispecs
82+
- pkg: github.com/opencontainers/go-digest
83+
alias: digest
84+
no-unaliased: true
85+
staticcheck:
86+
checks:
87+
- all
88+
testifylint:
89+
disable:
90+
- empty
91+
- bool-compare
92+
- len
93+
- negative-positive
94+
exclusions:
95+
generated: lax
96+
presets:
97+
- comments
98+
- common-false-positives
99+
- legacy
100+
- std-error-handling
50101
rules:
51-
main:
52-
deny:
53-
- pkg: "github.com/containerd/containerd/errdefs"
54-
desc: The containerd errdefs package was migrated to a separate module. Use github.com/containerd/errdefs instead.
55-
- pkg: "github.com/containerd/containerd/log"
56-
desc: The containerd log package was migrated to a separate module. Use github.com/containerd/log instead.
57-
- pkg: "github.com/containerd/containerd/pkg/userns"
58-
desc: Use github.com/moby/sys/userns instead.
59-
- pkg: "github.com/containerd/containerd/platforms"
60-
desc: The containerd platforms package was migrated to a separate module. Use github.com/containerd/platforms instead.
61-
- pkg: "github.com/containerd/nydus-snapshotter/pkg/errdefs"
62-
desc: You probably meant to use github.com/containerd/errdefs
63-
- pkg: "github.com/opencontainers/runc/libcontainer/userns"
64-
desc: Use github.com/moby/sys/userns instead.
65-
- pkg: "io/ioutil"
66-
desc: The io/ioutil package has been deprecated.
67-
forbidigo:
68-
forbid:
69-
- '^context\.WithCancel(# use context\.WithCancelCause instead)?$'
70-
- '^context\.WithDeadline(# use context\.WithDeadline instead)?$'
71-
- '^context\.WithTimeout(# use context\.WithTimeoutCause instead)?$'
72-
- '^ctx\.Err(# use context\.Cause instead)?$'
73-
- '^fmt\.Errorf(# use errors\.Errorf instead)?$'
74-
- '^logrus\.(Trace|Debug|Info|Warn|Warning|Error|Fatal)(f|ln)?(# use bklog\.G or bklog\.L instead of logrus directly)?$'
75-
- '^platforms\.DefaultString(# use platforms\.Format(platforms\.DefaultSpec()) instead\. Be aware that DefaultSpec is for the local platform, so must be avoided when working cross-platform)?$'
76-
importas:
77-
alias:
78-
# Enforce alias to prevent it accidentally being used instead of our
79-
# own errdefs package (or vice-versa).
80-
- pkg: "github.com/containerd/errdefs"
81-
alias: "cerrdefs"
82-
- pkg: "github.com/opencontainers/image-spec/specs-go/v1"
83-
alias: "ocispecs"
84-
- pkg: "github.com/opencontainers/go-digest"
85-
alias: "digest"
86-
87-
# Do not allow unaliased imports of aliased packages.
88-
no-unaliased: true
89-
gosec:
90-
excludes:
91-
- G101 # Potential hardcoded credentials (false positives)
92-
- G402 # TLS MinVersion too low
93-
- G504 # Import blocklist: net/http/cgi
94-
- G601 # Implicit memory aliasing in for loop (false positives)
95-
- G115 # integer overflow conversion (TODO: verify these)
96-
config:
97-
G306: "0644"
98-
testifylint:
99-
disable:
100-
# disable rules that reduce the test condition
101-
- "empty"
102-
- "bool-compare"
103-
- "len"
104-
- "negative-positive"
105-
106-
issues:
107-
exclude-files:
108-
- ".*\\.pb\\.go$"
109-
exclude-rules:
110-
- linters:
111-
- revive
112-
text: "stutters"
113-
- linters:
114-
- revive
115-
text: "empty-block"
116-
- linters:
117-
- revive
118-
text: "superfluous-else"
119-
- linters:
120-
- revive
121-
text: "unused-parameter"
122-
- linters:
123-
- revive
124-
text: "redefines-builtin-id"
125-
- linters:
126-
- revive
127-
text: "if-return"
102+
- linters:
103+
- revive
104+
text: stutters
105+
- linters:
106+
- revive
107+
text: empty-block
108+
- linters:
109+
- revive
110+
text: superfluous-else
111+
- linters:
112+
- revive
113+
text: unused-parameter
114+
- linters:
115+
- revive
116+
text: redefines-builtin-id
117+
- linters:
118+
- revive
119+
text: if-return
120+
paths:
121+
- .*\.pb\.go$
122+
- examples
123+
formatters:
124+
enable:
125+
- gofmt
126+
- goimports
127+
exclusions:
128+
generated: lax
129+
paths:
130+
- .*\.pb\.go$

api/services/control/control_bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package moby_buildkit_v1 //nolint:revive
1+
package moby_buildkit_v1 //nolint:revive,staticcheck
22

33
import (
44
"testing"

cache/blobs.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ func (sr *immutableRef) computeChainMetadata(ctx context.Context, filter map[str
351351
}
352352
diffID := sr.getDiffID()
353353
chainID = diffID
354-
blobChainID = imagespecidentity.ChainID([]digest.Digest{digest.Digest(sr.getBlob()), diffID})
354+
blobChainID = imagespecidentity.ChainID([]digest.Digest{sr.getBlob(), diffID})
355355
case Layer:
356356
if _, ok := filter[sr.ID()]; !ok {
357357
return nil
@@ -368,9 +368,9 @@ func (sr *immutableRef) computeChainMetadata(ctx context.Context, filter map[str
368368
return errors.Errorf("failed to set blobchain for reference with non-addressable parent %q", sr.layerParent.GetDescription())
369369
}
370370
}
371-
diffID := digest.Digest(sr.getDiffID())
371+
diffID := sr.getDiffID()
372372
chainID = imagespecidentity.ChainID([]digest.Digest{chainID, diffID})
373-
blobID := imagespecidentity.ChainID([]digest.Digest{digest.Digest(sr.getBlob()), diffID})
373+
blobID := imagespecidentity.ChainID([]digest.Digest{sr.getBlob(), diffID})
374374
blobChainID = imagespecidentity.ChainID([]digest.Digest{blobChainID, blobID})
375375
case Merge:
376376
baseInput := sr.mergeParents[0]
@@ -386,9 +386,9 @@ func (sr *immutableRef) computeChainMetadata(ctx context.Context, filter map[str
386386
// not enough information to compute chain at this time
387387
return nil
388388
}
389-
diffID := digest.Digest(layer.getDiffID())
389+
diffID := layer.getDiffID()
390390
chainID = imagespecidentity.ChainID([]digest.Digest{chainID, diffID})
391-
blobID := imagespecidentity.ChainID([]digest.Digest{digest.Digest(layer.getBlob()), diffID})
391+
blobID := imagespecidentity.ChainID([]digest.Digest{layer.getBlob(), diffID})
392392
blobChainID = imagespecidentity.ChainID([]digest.Digest{blobChainID, blobID})
393393
}
394394
}
@@ -397,7 +397,7 @@ func (sr *immutableRef) computeChainMetadata(ctx context.Context, filter map[str
397397
// this diff is its own blob
398398
diffID := sr.getDiffID()
399399
chainID = diffID
400-
blobChainID = imagespecidentity.ChainID([]digest.Digest{digest.Digest(sr.getBlob()), diffID})
400+
blobChainID = imagespecidentity.ChainID([]digest.Digest{sr.getBlob(), diffID})
401401
} else {
402402
// re-using upper blob
403403
chainID = sr.diffParents.upper.getChainID()

cache/blobs_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (sr *immutableRef) tryComputeOverlayBlob(ctx context.Context, lower, upper
4545

4646
defer func() {
4747
if cw != nil {
48-
ctx = context.WithoutCancel(ctx)
48+
ctx := context.WithoutCancel(ctx)
4949
// after commit success cw will be set to nil, if cw isn't nil, error
5050
// happened before commit, we should abort this ingest, and because the
5151
// error may incured by ctx cancel, use a new context here. And since

cache/contenthash/checksum.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ func (cc *cacheContext) HandleChange(kind fsutil.ChangeKind, p string, fi os.Fil
399399
for _, l := range links {
400400
pp := convertKeyToPath(l)
401401
cc.txn.Insert(l, cr)
402-
d := path.Dir(string(pp))
402+
d := path.Dir(pp)
403403
if d == "/" {
404404
d = ""
405405
}
@@ -774,11 +774,11 @@ func splitWildcards(p string) (d1, d2 string) {
774774

775775
func containsWildcards(name string) bool {
776776
for i := 0; i < len(name); i++ {
777-
ch := name[i]
778-
if ch == '\\' {
779-
i++
780-
} else if ch == '*' || ch == '?' || ch == '[' {
777+
switch name[i] {
778+
case '*', '?', '[':
781779
return true
780+
case '\\':
781+
i++
782782
}
783783
}
784784
return false
@@ -887,10 +887,7 @@ func (cc *cacheContext) checksum(ctx context.Context, root *iradix.Node[*CacheRe
887887
iter.SeekLowerBound(append(slices.Clone(next), 0))
888888
subk := next
889889
ok := true
890-
for {
891-
if !ok || !bytes.HasPrefix(subk, next) {
892-
break
893-
}
890+
for ok && bytes.HasPrefix(subk, next) {
894891
h.Write(bytes.TrimPrefix(subk, k))
895892

896893
// We do not follow trailing links when checksumming a directory's

cache/contenthash/filehash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ type statInfo struct {
9393
}
9494

9595
func (s *statInfo) Name() string {
96-
return filepath.Base(s.Stat.Path)
96+
return filepath.Base(s.Path)
9797
}
9898

9999
func (s *statInfo) Size() int64 {

cache/manager.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,10 +1427,7 @@ func (cm *cacheManager) DiskUsage(ctx context.Context, opt client.DiskUsageInfo)
14271427
}
14281428
cm.mu.Unlock()
14291429

1430-
for {
1431-
if len(rescan) == 0 {
1432-
break
1433-
}
1430+
for len(rescan) != 0 {
14341431
for id := range rescan {
14351432
v := m[id]
14361433
if v.refs == 0 {

cache/manager_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ func getCompressor(w io.Writer, compressionType compression.Type, customized boo
14641464
case compression.Gzip:
14651465
if customized {
14661466
gz, _ := gzip.NewWriterLevel(w, gzip.NoCompression)
1467-
gz.Header.Comment = "hello"
1467+
gz.Comment = "hello"
14681468
gz.Close()
14691469
}
14701470
return gzip.NewWriter(w), nil
@@ -2788,7 +2788,7 @@ func mapToSystemTarBlob(t *testing.T, m map[string]string) ([]byte, ocispecs.Des
27882788
tr := tar.NewReader(bytes.NewReader(tarout))
27892789
for {
27902790
h, err := tr.Next()
2791-
if err == io.EOF {
2791+
if errors.Is(err, io.EOF) {
27922792
break
27932793
}
27942794
if err != nil {
@@ -2807,7 +2807,7 @@ func mapToSystemTarBlob(t *testing.T, m map[string]string) ([]byte, ocispecs.Des
28072807
if err != nil {
28082808
return nil, ocispecs.Descriptor{}, err
28092809
}
2810-
if string(gotV) != string(v) {
2810+
if string(gotV) != v {
28112811
return nil, ocispecs.Descriptor{}, errors.Errorf("unexpected contents of %s", h.Name)
28122812
}
28132813
}

cache/metadata.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,11 @@ func (md *cacheMetadata) getLastUsed() (int, *time.Time) {
406406
if v == nil {
407407
return usageCount, nil
408408
}
409-
var lastUsedTs int64
410-
if err := v.Unmarshal(&lastUsedTs); err != nil || lastUsedTs == 0 {
409+
var lastUsedTS int64
410+
if err := v.Unmarshal(&lastUsedTS); err != nil || lastUsedTS == 0 {
411411
return usageCount, nil
412412
}
413-
tm := time.Unix(lastUsedTs/1e9, lastUsedTs%1e9)
413+
tm := time.Unix(lastUsedTS/1e9, lastUsedTS%1e9)
414414
return usageCount, &tm
415415
}
416416

cache/migrate_v2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func MigrateV2(ctx context.Context, from, to string, cs content.Store, s snapsho
223223

224224
if blob := md.getBlob(); blob != "" {
225225
if _, err := cs.Update(ctx, content.Info{
226-
Digest: digest.Digest(blob),
226+
Digest: blob,
227227
}, "labels.containerd.io/gc.root"); err != nil {
228228
return err
229229
}

0 commit comments

Comments
 (0)