Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit b07eaf2

Browse files
committed
lint
Signed-off-by: Yves Brissaud <yves.brissaud@docker.com>
1 parent cb3e200 commit b07eaf2

19 files changed

Lines changed: 53 additions & 63 deletions

.github/workflows/build-pr.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Checkout code into the Go module directory
1212
uses: actions/checkout@v2
1313

14-
- name: Set up Go 1.17
14+
- name: Set up Go
1515
uses: actions/setup-go@v3
1616
with:
1717
go-version-file: go.mod
@@ -24,7 +24,7 @@ jobs:
2424

2525
- name: Run golangci-lint
2626
run: |
27-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b . v1.27.0
27+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b . v1.51.1
2828
./golangci-lint run
2929
3030
build-linux:
@@ -43,7 +43,7 @@ jobs:
4343
- name: Checkout code into the Go module directory
4444
uses: actions/checkout@v2
4545

46-
- name: Set up Go 1.17
46+
- name: Set up Go
4747
uses: actions/setup-go@v3
4848
with:
4949
go-version-file: go.mod

.github/workflows/release-weekly-build.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ jobs:
1818
env:
1919
GO111MODULE: "on"
2020
steps:
21-
- name: Set up Go 1.17
22-
uses: actions/setup-go@v1
21+
- name: Set up Go
22+
uses: actions/setup-go@v3
2323
with:
24-
go-version: 1.17
24+
go-version-file: go.mod
25+
check-latest: true
26+
cache: true
2527
id: go
2628

2729
- name: Checkout code into the Go module directory
@@ -32,7 +34,7 @@ jobs:
3234

3335
- name: Run golangci-lint
3436
run: |
35-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b . v1.27.0
37+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b . v1.51.1
3638
./golangci-lint run
3739
3840
build:
@@ -58,7 +60,7 @@ jobs:
5860
with:
5961
ref: ${{ github.event.inputs.branch }}
6062

61-
- name: Set up Go 1.17
63+
- name: Set up Go
6264
uses: actions/setup-go@v3
6365
with:
6466
go-version-file: go.mod

.golangci.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,21 @@ linters:
44
enable-all: false
55
disable-all: true
66
enable:
7-
- deadcode
87
- errcheck
98
- gocyclo
109
- gofmt
1110
- goimports
12-
- golint
1311
- gosimple
1412
- govet
1513
- ineffassign
16-
- interfacer
1714
- lll
1815
- misspell
1916
- nakedret
2017
- staticcheck
21-
- structcheck
2218
- typecheck
2319
- unconvert
2420
- unparam
2521
- unused
26-
- varcheck
2722
linters-settings:
2823
gocyclo:
2924
min-complexity: 16

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
ARG GO_VERSION=1.19
2020
ARG CLI_VERSION=19.03.9
2121
ARG ALPINE_VERSION=3.14.2
22-
ARG GOLANGCI_LINT_VERSION=v1.27.0-alpine
22+
ARG GOLANGCI_LINT_VERSION=v1.51.1-alpine
2323

2424
####
2525
# BUILDER

cmd/docker-scan/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func runScan(ctx context.Context, cmd *cobra.Command, dockerCli command.Cli, fla
242242

243243
func newSigContext() (context.Context, func()) {
244244
ctx, cancel := context.WithCancel(context.Background())
245-
s := make(chan os.Signal)
245+
s := make(chan os.Signal, 1)
246246
signal.Notify(s, syscall.SIGTERM, syscall.SIGINT)
247247
go func() {
248248
<-s

config/config.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package config
1818

1919
import (
2020
"encoding/json"
21-
"io/ioutil"
2221
"os"
2322
"path/filepath"
2423
"runtime"
@@ -48,7 +47,7 @@ func ReadConfigFile() (Config, error) {
4847
}
4948
}
5049
}
51-
buf, err := ioutil.ReadFile(path)
50+
buf, err := os.ReadFile(path)
5251
if err != nil {
5352
_ = os.Remove(path)
5453
return conf, errors.Wrap(err, "failed to read docker scan configuration file. Please restart Docker Desktop")
@@ -72,5 +71,5 @@ func SaveConfigFile(conf Config) error {
7271
}
7372

7473
path := filepath.Join(cliConfig.Dir(), "scan", "config.json")
75-
return errors.Wrap(ioutil.WriteFile(path, out, os.FileMode(0644)), "failed to write docker scan configuration file")
74+
return errors.Wrap(os.WriteFile(path, out, os.FileMode(0644)), "failed to write docker scan configuration file")
7675
}

config/config_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package config
1818

1919
import (
2020
"encoding/json"
21-
"io/ioutil"
2221
"os"
2322
"path/filepath"
2423
"testing"
@@ -29,7 +28,7 @@ import (
2928
)
3029

3130
func TestSaveConfigFile(t *testing.T) {
32-
configDir, err := ioutil.TempDir("", "config")
31+
configDir, err := os.MkdirTemp(os.TempDir(), "config")
3332
assert.NilError(t, err)
3433
defer os.RemoveAll(configDir) //nolint:errcheck
3534

e2e/auth_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package e2e
1818

1919
import (
2020
"fmt"
21-
"io/ioutil"
2221
"os"
2322
"runtime"
2423
"strings"
@@ -52,7 +51,7 @@ func TestSnykAuthentication(t *testing.T) {
5251
icmd.RunCmd(cmd).Assert(t, icmd.Success)
5352

5453
// snyk config file should be updated
55-
buff, err := ioutil.ReadFile(homeDir.Join(".config", "configstore", "snyk.json"))
54+
buff, err := os.ReadFile(homeDir.Join(".config", "configstore", "snyk.json"))
5655
assert.NilError(t, err)
5756
assert.Assert(t, strings.Contains(string(buff), token), string(buff))
5857
}
@@ -103,7 +102,7 @@ func TestAuthWithContainerizedSnyk(t *testing.T) {
103102
icmd.RunCmd(cmd).Assert(t, icmd.Success)
104103

105104
// snyk config file should be created
106-
buff, err := ioutil.ReadFile(homeDir.Join(".config", "configstore", "snyk.json"))
105+
buff, err := os.ReadFile(homeDir.Join(".config", "configstore", "snyk.json"))
107106
assert.NilError(t, err)
108107
assert.Assert(t, strings.Contains(string(buff), token))
109108
}

e2e/main_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package e2e
1818

1919
import (
2020
"encoding/json"
21-
"io/ioutil"
2221
"os"
2322
"path/filepath"
2423
"runtime"
@@ -42,7 +41,7 @@ func (d dockerCliCommand) createTestCmd() (icmd.Cmd, string, func()) {
4241
}
4342

4443
func (d dockerCliCommand) createTestCommand(withSnykBinary bool) (icmd.Cmd, string, func()) {
45-
configDir, err := ioutil.TempDir("", "config")
44+
configDir, err := os.MkdirTemp(os.TempDir(), "config")
4645
if err != nil {
4746
panic(err)
4847
}
@@ -87,7 +86,7 @@ func (d dockerCliCommand) Command(args ...string) []string {
8786
func TestMain(m *testing.M) {
8887
// Prepare docker cli to call the docker-scan plugin binary:
8988
// - Create a symbolic link with the docker-scan binary to the plugin directory
90-
cliPluginDir, err := ioutil.TempDir("", "configContent")
89+
cliPluginDir, err := os.MkdirTemp(os.TempDir(), "configContent")
9190
if err != nil {
9291
panic(err)
9392
}
@@ -104,11 +103,11 @@ func copyBinary(binaryName, sourceDir, configDir string) {
104103
if runtime.GOOS == "windows" {
105104
binaryName += ".exe"
106105
}
107-
input, err := ioutil.ReadFile(filepath.Join(sourceDir, binaryName))
106+
input, err := os.ReadFile(filepath.Join(sourceDir, binaryName))
108107
if err != nil {
109108
panic(err)
110109
}
111-
err = ioutil.WriteFile(filepath.Join(configDir, binaryName), input, 0744)
110+
err = os.WriteFile(filepath.Join(configDir, binaryName), input, 0744)
112111
if err != nil {
113112
panic(err)
114113
}

e2e/optin_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build !windows
1+
//go:build !windows
22

33
/*
44
Copyright 2020 Docker Inc.
@@ -21,7 +21,6 @@ package e2e
2121
import (
2222
"encoding/json"
2323
"fmt"
24-
"io/ioutil"
2524
"os"
2625
"path/filepath"
2726
"strings"
@@ -54,7 +53,7 @@ func TestFirstScanOptinMessage(t *testing.T) {
5453
assert.Assert(t, strings.Contains(result.Combined(), `Docker Scan relies upon access to Snyk, a third party provider, do you consent to proceed using Snyk? (y/N)`))
5554

5655
// check the consent has been stored in config file
57-
data, err := ioutil.ReadFile(filepath.Join(configDir, "scan", "config.json"))
56+
data, err := os.ReadFile(filepath.Join(configDir, "scan", "config.json"))
5857
assert.NilError(t, err)
5958
var conf config.Config
6059
assert.NilError(t, json.Unmarshal(data, &conf))
@@ -74,7 +73,7 @@ func TestRefuseOptinWithDisableFlag(t *testing.T) {
7473
})
7574

7675
// check the consent has been stored in config file
77-
data, err := ioutil.ReadFile(filepath.Join(configDir, "scan", "config.json"))
76+
data, err := os.ReadFile(filepath.Join(configDir, "scan", "config.json"))
7877
assert.NilError(t, err)
7978
var conf config.Config
8079
assert.NilError(t, json.Unmarshal(data, &conf))

0 commit comments

Comments
 (0)