Skip to content

Commit 6ba20c8

Browse files
authored
Fix various lints (google#1507)
* Replace interface{} with any * Add godoc comments * Add missing err check * gofmt * Bump things to 1.18 * Update staticcheck, drop golint * Fix io/ioutil deprecation * Run gofmt * boilerplate
1 parent 4270e04 commit 6ba20c8

Some content is hidden

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

98 files changed

+445
-414
lines changed

.github/workflows/build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
go-version: [1.18] # TODO: add 1.19
15+
go-version: [1.18, 1.19] # TODO: add 1.20
1616

1717
steps:
1818
- uses: actions/checkout@v3

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
run: git fetch --prune --unshallow
1616
- uses: actions/setup-go@v3
1717
with:
18-
go-version: 1.17
18+
go-version: 1.18
1919
check-latest: true
2020
- uses: goreleaser/[email protected]
2121
id: run-goreleaser

.github/workflows/test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
test:
1212
strategy:
1313
matrix:
14-
go-version: [1.18] # TODO: add 1.19
14+
go-version: [1.18, 1.19] # TODO: add 1.20
1515

1616
name: Unit Tests
1717
runs-on: ubuntu-latest

cmd/crane/cmd/auth.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"encoding/json"
1919
"errors"
2020
"fmt"
21-
"io/ioutil"
21+
"io"
2222
"log"
2323
"os"
2424
"strings"
@@ -86,7 +86,7 @@ func NewCmdAuthGet(options []crane.Option, argv ...string) *cobra.Command {
8686
if len(args) == 1 {
8787
registryAddr = args[0]
8888
} else {
89-
b, err := ioutil.ReadAll(os.Stdin)
89+
b, err := io.ReadAll(os.Stdin)
9090
if err != nil {
9191
return err
9292
}
@@ -170,7 +170,7 @@ type loginOptions struct {
170170

171171
func login(opts loginOptions) error {
172172
if opts.passwordStdin {
173-
contents, err := ioutil.ReadAll(os.Stdin)
173+
contents, err := io.ReadAll(os.Stdin)
174174
if err != nil {
175175
return err
176176
}

cmd/crane/cmd/export.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package cmd
1717
import (
1818
"fmt"
1919
"io"
20-
"io/ioutil"
2120
"log"
2221
"os"
2322

@@ -55,7 +54,7 @@ func NewCmdExport(options *[]crane.Option) *cobra.Command {
5554

5655
var img v1.Image
5756
if src == "-" {
58-
tmpfile, err := ioutil.TempFile("", "crane")
57+
tmpfile, err := os.CreateTemp("", "crane")
5958
if err != nil {
6059
log.Fatal(err)
6160
}

cmd/crane/cmd/push.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package cmd
1616

1717
import (
1818
"fmt"
19-
"io/ioutil"
2019
"os"
2120

2221
"github.com/google/go-containerregistry/pkg/crane"
@@ -72,7 +71,7 @@ func NewCmdPush(options *[]crane.Option) *cobra.Command {
7271

7372
digest := ref.Context().Digest(h.String())
7473
if imageRefs != "" {
75-
return ioutil.WriteFile(imageRefs, []byte(digest.String()), 0600)
74+
return os.WriteFile(imageRefs, []byte(digest.String()), 0600)
7675
}
7776
// TODO(mattmoor): think about printing the digest to standard out
7877
// to facilitate command composition similar to ko build.

cmd/crane/cmd/root.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copyright 2019 Google LLC All Rights Reserved.
2+
//
13
// Licensed under the Apache License, Version 2.0 (the "License");
24
// you may not use this file except in compliance with the License.
35
// You may obtain a copy of the License at

cmd/crane/cmd/util.go

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2020 Google LLC All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package cmd
216

317
import (

cmd/crane/cmd/version.go

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2019 Google LLC All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package cmd
216

317
import (

cmd/crane/help/main.go

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2018 Google LLC All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package main
216

317
import (

cmd/crane/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ package main
1717
import (
1818
"context"
1919
"os"
20+
"os/signal"
2021

2122
"github.com/google/go-containerregistry/cmd/crane/cmd"
22-
"github.com/google/go-containerregistry/internal/signal"
2323
"github.com/google/go-containerregistry/pkg/logs"
2424
)
2525

cmd/gcrane/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ package main
1717
import (
1818
"context"
1919
"os"
20+
"os/signal"
2021

2122
"github.com/google/go-containerregistry/cmd/crane/cmd"
2223
gcmd "github.com/google/go-containerregistry/cmd/gcrane/cmd"
23-
"github.com/google/go-containerregistry/internal/signal"
2424
"github.com/google/go-containerregistry/pkg/crane"
2525
"github.com/google/go-containerregistry/pkg/gcrane"
2626
"github.com/google/go-containerregistry/pkg/logs"

cmd/krane/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/google/go-containerregistry/cmd/krane
22

3-
go 1.17
3+
go 1.18
44

55
replace github.com/google/go-containerregistry => ../../
66

cmd/krane/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ package main
1616

1717
import (
1818
"context"
19-
"io/ioutil"
19+
"io"
2020
"os"
21+
"os/signal"
2122

2223
ecr "github.com/awslabs/amazon-ecr-credential-helper/ecr-login"
2324
"github.com/chrismellard/docker-credential-acr-env/pkg/credhelper"
2425
"github.com/google/go-containerregistry/cmd/crane/cmd"
25-
"github.com/google/go-containerregistry/internal/signal"
2626
"github.com/google/go-containerregistry/pkg/authn"
2727
"github.com/google/go-containerregistry/pkg/authn/github"
2828
"github.com/google/go-containerregistry/pkg/crane"
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
var (
34-
amazonKeychain authn.Keychain = authn.NewKeychainFromHelper(ecr.NewECRHelper(ecr.WithLogger(ioutil.Discard)))
34+
amazonKeychain authn.Keychain = authn.NewKeychainFromHelper(ecr.NewECRHelper(ecr.WithLogger(io.Discard)))
3535
azureKeychain authn.Keychain = authn.NewKeychainFromHelper(credhelper.NewACRCredentialsHelper())
3636
)
3737

cmd/registry/main.go

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2019 Google LLC All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package main
216

317
import (

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/google/go-containerregistry
22

3-
go 1.17
3+
go 1.18
44

55
require (
66
github.com/containerd/stargz-snapshotter/estargz v0.12.1

hack/bump-deps.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ pushd ${PROJECT_ROOT}
2424
trap popd EXIT
2525

2626
go get -u ./...
27-
go mod tidy -compat=1.17
27+
go mod tidy -compat=1.18
2828
go mod vendor
2929

3030
cd ${PROJECT_ROOT}/pkg/authn/k8schain
3131
go get -u ./...
32-
go mod tidy -compat=1.17
32+
go mod tidy -compat=1.18
3333
go mod download
3434

3535
cd ${PROJECT_ROOT}/pkg/authn/kubernetes
3636
go get -u ./...
37-
go mod tidy -compat=1.17
37+
go mod tidy -compat=1.18
3838
go mod download
3939

4040
cd ${PROJECT_ROOT}/cmd/krane
4141
go get -u ./...
42-
go mod tidy -compat=1.17
42+
go mod tidy -compat=1.18
4343
go mod download
4444

4545
cd ${PROJECT_ROOT}

hack/presubmit.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ export PATH="${PATH}:${TMP_DIR}/bin"
2626
export GOPATH="${TMP_DIR}"
2727
pushd ${TMP_DIR}
2828
trap popd EXIT
29-
go install golang.org/x/lint/[email protected]
30-
go install honnef.co/go/tools/cmd/[email protected]
29+
go install honnef.co/go/tools/cmd/[email protected]
3130
popd
3231

3332
pushd ${PROJECT_ROOT}
3433
trap popd EXIT
3534

36-
golint -set_exit_status ./pkg/...
3735
staticcheck ./pkg/...
3836

3937
# Verify that all source files are correctly formatted.

internal/and/and_closer_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package and
1616

1717
import (
1818
"bytes"
19-
"io/ioutil"
19+
"io"
2020
"testing"
2121
)
2222

@@ -33,7 +33,7 @@ func TestRead(t *testing.T) {
3333
},
3434
}
3535

36-
data, err := ioutil.ReadAll(rac)
36+
data, err := io.ReadAll(rac)
3737
if err != nil {
3838
t.Errorf("ReadAll(rac) = %v", err)
3939
}

internal/cmd/edit.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"errors"
2121
"fmt"
2222
"io"
23-
"io/ioutil"
2423
"os"
2524
"path/filepath"
2625
"strings"
@@ -139,7 +138,7 @@ func interactive(in io.Reader, out io.Writer) bool {
139138
return interactiveFile(in) && interactiveFile(out)
140139
}
141140

142-
func interactiveFile(i interface{}) bool {
141+
func interactiveFile(i any) bool {
143142
f, ok := i.(*os.File)
144143
if !ok {
145144
return false
@@ -170,7 +169,7 @@ func editConfig(in io.Reader, out io.Writer, src, dst string, options ...crane.O
170169
return nil, err
171170
}
172171
} else {
173-
b, err := ioutil.ReadAll(in)
172+
b, err := io.ReadAll(in)
174173
if err != nil {
175174
return nil, err
176175
}
@@ -235,7 +234,7 @@ func editManifest(in io.Reader, out io.Writer, src string, dst string, options .
235234
return nil, err
236235
}
237236
} else {
238-
b, err := ioutil.ReadAll(in)
237+
b, err := io.ReadAll(in)
239238
if err != nil {
240239
return nil, err
241240
}
@@ -299,7 +298,7 @@ func editFile(in io.Reader, out io.Writer, src, file, dst string, options ...cra
299298
}
300299
header = h
301300
} else {
302-
b, err := ioutil.ReadAll(in)
301+
b, err := io.ReadAll(in)
303302
if err != nil {
304303
return nil, err
305304
}
@@ -324,7 +323,7 @@ func editFile(in io.Reader, out io.Writer, src, file, dst string, options ...cra
324323

325324
fileBytes := buf.Bytes()
326325
fileLayer, err := tarball.LayerFromOpener(func() (io.ReadCloser, error) {
327-
return ioutil.NopCloser(bytes.NewBuffer(fileBytes)), nil
326+
return io.NopCloser(bytes.NewBuffer(fileBytes)), nil
328327
})
329328
if err != nil {
330329
return nil, err

internal/cmd/edit_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package cmd
1616

1717
import (
1818
"bytes"
19-
"io/ioutil"
19+
"io"
2020
"net/http/httptest"
2121
"net/url"
2222
"path"
@@ -112,7 +112,7 @@ func TestEditFilesystem(t *testing.T) {
112112
t.Fatal(err)
113113
}
114114

115-
got, err := ioutil.ReadAll(r)
115+
got, err := io.ReadAll(r)
116116
if err != nil {
117117
t.Fatal(err)
118118
}
@@ -140,7 +140,7 @@ func TestEditFilesystem(t *testing.T) {
140140
t.Fatal(err)
141141
}
142142

143-
got, err = ioutil.ReadAll(r)
143+
got, err = io.ReadAll(r)
144144
if err != nil {
145145
t.Fatal(err)
146146
}
@@ -160,7 +160,7 @@ func TestFindFile(t *testing.T) {
160160
t.Fatal(err)
161161
}
162162

163-
b, err := ioutil.ReadAll(r)
163+
b, err := io.ReadAll(r)
164164
if err != nil {
165165
t.Fatal(err)
166166
}

0 commit comments

Comments
 (0)