Skip to content

Commit ccaa0d6

Browse files
authored
Migrate linter to v2 (#2096)
* use default migrated config + fix issues * bump linter for real this time I promise
1 parent 098045d commit ccaa0d6

File tree

13 files changed

+85
-82
lines changed

13 files changed

+85
-82
lines changed

.github/workflows/style.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ jobs:
2626
with:
2727
go-version-file: go.mod
2828

29-
- uses: golangci/golangci-lint-action@v3.4.0
29+
- uses: golangci/golangci-lint-action@v8.0.0
3030
with:
31-
version: v1.61.0
31+
version: v2.1.6
3232

3333
- uses: reviewdog/action-misspell@v1
3434
if: ${{ always() }}

.golangci.yaml

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,54 @@
1-
run:
2-
timeout: 5m
3-
4-
issues:
5-
exclude-dirs:
6-
- internal
7-
- pkg/registry
8-
exclude-rules:
9-
- path: test # Excludes /test, *_test.go etc.
10-
linters:
11-
- gosec
12-
1+
version: "2"
132
linters:
143
enable:
15-
- asciicheck
16-
- depguard
17-
- errorlint
18-
- gofmt
19-
- gosec
20-
- goimports
21-
- importas
22-
- prealloc
23-
- revive
24-
- misspell
25-
- stylecheck
26-
- tparallel
27-
- unconvert
28-
- unparam
29-
- unused
30-
- whitespace
31-
4+
- asciicheck
5+
- depguard
6+
- errorlint
7+
- gosec
8+
- importas
9+
- misspell
10+
- prealloc
11+
- revive
12+
- staticcheck
13+
- tparallel
14+
- unconvert
15+
- unparam
16+
- whitespace
3217
disable:
33-
- errcheck
34-
35-
linters-settings:
36-
depguard:
18+
- errcheck
19+
settings:
20+
depguard:
21+
rules:
22+
main:
23+
deny:
24+
- pkg: crypto/sha256
25+
desc: use crypto.SHA256 instead
26+
exclusions:
27+
generated: lax
28+
presets:
29+
- comments
30+
- common-false-positives
31+
- legacy
32+
- std-error-handling
3733
rules:
38-
main:
39-
deny:
40-
- pkg: "crypto/sha256"
41-
desc: use crypto.SHA256 instead
34+
- linters:
35+
- gosec
36+
path: test # Excludes /test, *_test.go etc.
37+
paths:
38+
- internal
39+
- pkg/registry
40+
- third_party$
41+
- builtin$
42+
- examples$
43+
formatters:
44+
enable:
45+
- gofmt
46+
- goimports
47+
exclusions:
48+
generated: lax
49+
paths:
50+
- internal
51+
- pkg/registry
52+
- third_party$
53+
- builtin$
54+
- examples$

pkg/crane/copy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func CopyRepository(src, dst string, opt ...Option) error {
114114
if errors.As(err, &terr) {
115115
// Some registries create repository on first push, so listing tags will fail.
116116
// If we see 404 or 403, assume we failed because the repository hasn't been created yet.
117-
if !(terr.StatusCode == http.StatusNotFound || terr.StatusCode == http.StatusForbidden) {
117+
if terr.StatusCode != http.StatusNotFound && terr.StatusCode != http.StatusForbidden {
118118
return err
119119
}
120120
} else {

pkg/crane/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func MultiSave(imgMap map[string]v1.Image, path string, opt ...Option) error {
7070
if !ok {
7171
return fmt.Errorf("ref wasn't a tag or digest")
7272
}
73-
tag = d.Repository.Tag(iWasADigestTag)
73+
tag = d.Tag(iWasADigestTag)
7474
}
7575
tagToImage[tag] = img
7676
}

pkg/v1/google/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ func newLister(repo name.Repository, options ...Option) (*lister, error) {
8989

9090
func (l *lister) list(repo name.Repository) (*Tags, error) {
9191
uri := &url.URL{
92-
Scheme: repo.Registry.Scheme(),
93-
Host: repo.Registry.RegistryStr(),
92+
Scheme: repo.Scheme(),
93+
Host: repo.RegistryStr(),
9494
Path: fmt.Sprintf("/v2/%s/tags/list", repo.RepositoryStr()),
9595
RawQuery: "n=10000",
9696
}

pkg/v1/layout/write.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ func (l Path) ReplaceIndex(ii v1.ImageIndex, matcher match.Matcher, options ...O
126126

127127
// replaceDescriptor adds a descriptor to the index.json of the Path, replacing
128128
// any one matching matcher, if found.
129-
func (l Path) replaceDescriptor(append mutate.Appendable, matcher match.Matcher, options ...Option) error {
129+
func (l Path) replaceDescriptor(appendable mutate.Appendable, matcher match.Matcher, options ...Option) error {
130130
ii, err := l.ImageIndex()
131131
if err != nil {
132132
return err
133133
}
134134

135-
desc, err := partial.Descriptor(append)
135+
desc, err := partial.Descriptor(appendable)
136136
if err != nil {
137137
return err
138138
}
@@ -143,7 +143,7 @@ func (l Path) replaceDescriptor(append mutate.Appendable, matcher match.Matcher,
143143
}
144144

145145
add := mutate.IndexAddendum{
146-
Add: append,
146+
Add: appendable,
147147
Descriptor: *desc,
148148
}
149149
ii = mutate.AppendManifests(mutate.RemoveManifests(ii, matcher), add)

pkg/v1/mutate/index.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,26 @@ func computeDescriptor(ia IndexAddendum) (*v1.Descriptor, error) {
3535
}
3636

3737
// The IndexAddendum allows overriding Descriptor values.
38-
if ia.Descriptor.Size != 0 {
39-
desc.Size = ia.Descriptor.Size
38+
if ia.Size != 0 {
39+
desc.Size = ia.Size
4040
}
41-
if string(ia.Descriptor.MediaType) != "" {
42-
desc.MediaType = ia.Descriptor.MediaType
41+
if string(ia.MediaType) != "" {
42+
desc.MediaType = ia.MediaType
4343
}
44-
if ia.Descriptor.Digest != (v1.Hash{}) {
45-
desc.Digest = ia.Descriptor.Digest
44+
if ia.Digest != (v1.Hash{}) {
45+
desc.Digest = ia.Digest
4646
}
47-
if ia.Descriptor.Platform != nil {
48-
desc.Platform = ia.Descriptor.Platform
47+
if ia.Platform != nil {
48+
desc.Platform = ia.Platform
4949
}
50-
if len(ia.Descriptor.URLs) != 0 {
51-
desc.URLs = ia.Descriptor.URLs
50+
if len(ia.URLs) != 0 {
51+
desc.URLs = ia.URLs
5252
}
53-
if len(ia.Descriptor.Annotations) != 0 {
54-
desc.Annotations = ia.Descriptor.Annotations
53+
if len(ia.Annotations) != 0 {
54+
desc.Annotations = ia.Annotations
5555
}
56-
if ia.Descriptor.Data != nil {
57-
desc.Data = ia.Descriptor.Data
56+
if ia.Data != nil {
57+
desc.Data = ia.Data
5858
}
5959

6060
return desc, nil

pkg/v1/mutate/mutate.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func extract(img v1.Image, w io.Writer) error {
328328

329329
// mark file as handled. non-directory implicitly tombstones
330330
// any entries with a matching (or child) name
331-
fileMap[name] = tombstone || !(header.Typeflag == tar.TypeDir)
331+
fileMap[name] = tombstone || (header.Typeflag != tar.TypeDir)
332332
if !tombstone {
333333
if err := tarWriter.WriteHeader(header); err != nil {
334334
return err
@@ -345,10 +345,7 @@ func extract(img v1.Image, w io.Writer) error {
345345
}
346346

347347
func inWhiteoutDir(fileMap map[string]bool, file string) bool {
348-
for {
349-
if file == "" {
350-
break
351-
}
348+
for file != "" {
352349
dirname := filepath.Dir(file)
353350
if file == dirname {
354351
break
@@ -361,13 +358,6 @@ func inWhiteoutDir(fileMap map[string]bool, file string) bool {
361358
return false
362359
}
363360

364-
func max(a, b int) int {
365-
if a > b {
366-
return a
367-
}
368-
return b
369-
}
370-
371361
// Time sets all timestamps in an image to the given timestamp.
372362
func Time(img v1.Image, t time.Time) (v1.Image, error) {
373363
newImage := empty.Image

pkg/v1/remote/multi_write_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func TestMultiWrite_Retry(t *testing.T) {
269269

270270
// using a transport.Wrapper, meaning retry logic should not be wrapped
271271
doesNotRetryTransport := &countTransport{inner: http.DefaultTransport}
272-
transportWrapper, err := transport.NewWithContext(context.Background(), tag1.Repository.Registry, authn.Anonymous, doesNotRetryTransport, nil)
272+
transportWrapper, err := transport.NewWithContext(context.Background(), tag1.Registry, authn.Anonymous, doesNotRetryTransport, nil)
273273
if err != nil {
274274
t.Fatal(err)
275275
}
@@ -311,7 +311,7 @@ func TestMultiWrite_Retry(t *testing.T) {
311311

312312
tag1 := mustNewTag(t, u.Host+"/repo:tag1")
313313
// using a transport.Wrapper, meaning retry logic should not be wrapped
314-
transportWrapper, err := transport.NewWithContext(context.Background(), tag1.Repository.Registry, authn.Anonymous, http.DefaultTransport, nil)
314+
transportWrapper, err := transport.NewWithContext(context.Background(), tag1.Registry, authn.Anonymous, http.DefaultTransport, nil)
315315
if err != nil {
316316
t.Fatal(err)
317317
}

pkg/v1/remote/pusher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (p *Pusher) Delete(ctx context.Context, ref name.Reference) error {
162162
}
163163

164164
u := url.URL{
165-
Scheme: ref.Context().Registry.Scheme(),
165+
Scheme: ref.Context().Scheme(),
166166
Host: ref.Context().RegistryStr(),
167167
Path: fmt.Sprintf("/v2/%s/manifests/%s", ref.Context().RepositoryStr(), ref.Identifier()),
168168
}

0 commit comments

Comments
 (0)