Skip to content

Commit 5e32cce

Browse files
authored
Merge pull request #5835 from thaJeztah/bump_golangci_lint
Dockerfile: update golangci-lint to v1.64.5, replace deprecated `tenv` linter in favor of `usetesting`
2 parents e3abf7f + a8affef commit 5e32cce

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

.golangci.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ linters:
2626
- revive # Metalinter; drop-in replacement for golint.
2727
- staticcheck
2828
- stylecheck # Replacement for golint
29-
- tenv # Detects using os.Setenv instead of t.Setenv.
3029
- thelper # Detects test helpers without t.Helper().
3130
- tparallel # Detects inappropriate usage of t.Parallel().
3231
- typecheck
3332
- unconvert # Detects unnecessary type conversions.
3433
- unparam
3534
- unused
3635
- usestdlibvars
36+
- usetesting # Reports uses of functions with replacement inside the testing package.
3737
- wastedassign
3838

3939
disable:
@@ -42,6 +42,8 @@ linters:
4242
run:
4343
# prevent golangci-lint from deducting the go version to lint for through go.mod,
4444
# which causes it to fallback to go1.17 semantics.
45+
#
46+
# TODO(thaJeztah): update "usetesting" settings to enable go1.24 features once our minimum version is go1.24
4547
go: "1.23.6"
4648
timeout: 5m
4749

@@ -111,6 +113,14 @@ linters-settings:
111113
severity: warning
112114
disabled: false
113115

116+
usetesting:
117+
# FIXME(thaJeztah): Disable `os.Chdir()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
118+
os-chdir: false
119+
# FIXME(thaJeztah): Disable `context.Background()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
120+
context-background: false
121+
# FIXME(thaJeztah): Disable `context.TODO()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
122+
context-todo: false
123+
114124
issues:
115125
# The default exclusion rules are a bit too permissive, so copying the relevant ones below
116126
exclude-use-default: false

cli/command/trust/signer_add_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ func TestTrustSignerAddErrors(t *testing.T) {
6868
func TestSignerAddCommandNoTargetsKey(t *testing.T) {
6969
config.SetDir(t.TempDir())
7070

71-
tmpfile, err := os.CreateTemp("", "pemfile")
71+
tmpDir := t.TempDir()
72+
tmpFile, err := os.CreateTemp(tmpDir, "pemfile")
7273
assert.NilError(t, err)
73-
tmpfile.Close()
74-
defer os.Remove(tmpfile.Name())
74+
assert.Check(t, tmpFile.Close())
7575

7676
cli := test.NewFakeCli(&fakeClient{})
7777
cli.SetNotaryClient(notaryfake.GetEmptyTargetsNotaryRepository)
7878
cmd := newSignerAddCommand(cli)
79-
cmd.SetArgs([]string{"--key", tmpfile.Name(), "alice", "alpine", "linuxkit/alpine"})
79+
cmd.SetArgs([]string{"--key", tmpFile.Name(), "alice", "alpine", "linuxkit/alpine"})
8080

8181
cmd.SetOut(io.Discard)
8282
cmd.SetErr(io.Discard)
83-
assert.Error(t, cmd.Execute(), fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpfile.Name()))
83+
assert.Error(t, cmd.Execute(), fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpFile.Name()))
8484
}
8585

8686
func TestSignerAddCommandBadKeyPath(t *testing.T) {
@@ -130,10 +130,10 @@ func TestIngestPublicKeys(t *testing.T) {
130130
}
131131
assert.Error(t, err, expectedError)
132132
// Call with real file path
133-
tmpfile, err := os.CreateTemp("", "pemfile")
133+
tmpDir := t.TempDir()
134+
tmpFile, err := os.CreateTemp(tmpDir, "pemfile")
134135
assert.NilError(t, err)
135-
tmpfile.Close()
136-
defer os.Remove(tmpfile.Name())
137-
_, err = ingestPublicKeys([]string{tmpfile.Name()})
138-
assert.Error(t, err, fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpfile.Name()))
136+
assert.Check(t, tmpFile.Close())
137+
_, err = ingestPublicKeys([]string{tmpFile.Name()})
138+
assert.Error(t, err, fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpFile.Name()))
139139
}

cli/debug/debug.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import (
1010
// Enable sets the DEBUG env var to true
1111
// and makes the logger to log at debug level.
1212
func Enable() {
13-
os.Setenv("DEBUG", "1")
13+
_ = os.Setenv("DEBUG", "1")
1414
logrus.SetLevel(logrus.DebugLevel)
1515
}
1616

1717
// Disable sets the DEBUG env var to false
1818
// and makes the logger to log at info level.
1919
func Disable() {
20-
os.Setenv("DEBUG", "")
20+
_ = os.Setenv("DEBUG", "")
2121
logrus.SetLevel(logrus.InfoLevel)
2222
}
2323

cli/debug/debug_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99

1010
func TestEnable(t *testing.T) {
1111
defer func() {
12-
os.Setenv("DEBUG", "")
1312
logrus.SetLevel(logrus.InfoLevel)
1413
}()
14+
t.Setenv("DEBUG", "")
1515
Enable()
1616
if os.Getenv("DEBUG") != "1" {
1717
t.Fatalf("expected DEBUG=1, got %s\n", os.Getenv("DEBUG"))
@@ -22,6 +22,7 @@ func TestEnable(t *testing.T) {
2222
}
2323

2424
func TestDisable(t *testing.T) {
25+
t.Setenv("DEBUG", "1")
2526
Disable()
2627
if os.Getenv("DEBUG") != "" {
2728
t.Fatalf("expected DEBUG=\"\", got %s\n", os.Getenv("DEBUG"))
@@ -32,6 +33,7 @@ func TestDisable(t *testing.T) {
3233
}
3334

3435
func TestEnabled(t *testing.T) {
36+
t.Setenv("DEBUG", "")
3537
Enable()
3638
if !IsEnabled() {
3739
t.Fatal("expected debug enabled, got false")

dockerfiles/Dockerfile.lint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
ARG GO_VERSION=1.23.6
44
ARG ALPINE_VERSION=3.21
5-
ARG GOLANGCI_LINT_VERSION=v1.63.4
5+
ARG GOLANGCI_LINT_VERSION=v1.64.5
66

77
FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint
88

0 commit comments

Comments
 (0)