Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ linters:
- revive # Metalinter; drop-in replacement for golint.
- staticcheck
- stylecheck # Replacement for golint
- tenv # Detects using os.Setenv instead of t.Setenv.
- thelper # Detects test helpers without t.Helper().
- tparallel # Detects inappropriate usage of t.Parallel().
- typecheck
- unconvert # Detects unnecessary type conversions.
- unparam
- unused
- usestdlibvars
- usetesting # Reports uses of functions with replacement inside the testing package.
- wastedassign

disable:
Expand All @@ -43,6 +43,8 @@ linters:
run:
# prevent golangci-lint from deducting the go version to lint for through go.mod,
# which causes it to fallback to go1.17 semantics.
#
# TODO(thaJeztah): update "usetesting" settings to enable go1.24 features once our minimum version is go1.24
go: "1.23.6"
timeout: 5m

Expand Down Expand Up @@ -103,6 +105,14 @@ linters-settings:
severity: warning
disabled: false

usetesting:
# FIXME(thaJeztah): Disable `os.Chdir()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
os-chdir: false
# FIXME(thaJeztah): Disable `context.Background()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
context-background: false
# FIXME(thaJeztah): Disable `context.TODO()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
context-todo: false

issues:
# The default exclusion rules are a bit too permissive, so copying the relevant ones below
exclude-use-default: false
Expand Down
20 changes: 10 additions & 10 deletions cli/command/trust/signer_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ func TestTrustSignerAddErrors(t *testing.T) {
func TestSignerAddCommandNoTargetsKey(t *testing.T) {
config.SetDir(t.TempDir())

tmpfile, err := os.CreateTemp("", "pemfile")
tmpDir := t.TempDir()
tmpFile, err := os.CreateTemp(tmpDir, "pemfile")
assert.NilError(t, err)
tmpfile.Close()
defer os.Remove(tmpfile.Name())
assert.Check(t, tmpFile.Close())

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

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

func TestSignerAddCommandBadKeyPath(t *testing.T) {
Expand Down Expand Up @@ -130,10 +130,10 @@ func TestIngestPublicKeys(t *testing.T) {
}
assert.Error(t, err, expectedError)
// Call with real file path
tmpfile, err := os.CreateTemp("", "pemfile")
tmpDir := t.TempDir()
tmpFile, err := os.CreateTemp(tmpDir, "pemfile")
assert.NilError(t, err)
tmpfile.Close()
defer os.Remove(tmpfile.Name())
_, err = ingestPublicKeys([]string{tmpfile.Name()})
assert.Error(t, err, fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpfile.Name()))
assert.Check(t, tmpFile.Close())
_, err = ingestPublicKeys([]string{tmpFile.Name()})
assert.Error(t, err, fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpFile.Name()))
}
4 changes: 2 additions & 2 deletions cli/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
// Enable sets the DEBUG env var to true
// and makes the logger to log at debug level.
func Enable() {
os.Setenv("DEBUG", "1")
_ = os.Setenv("DEBUG", "1")
logrus.SetLevel(logrus.DebugLevel)
}

// Disable sets the DEBUG env var to false
// and makes the logger to log at info level.
func Disable() {
os.Setenv("DEBUG", "")
_ = os.Setenv("DEBUG", "")
logrus.SetLevel(logrus.InfoLevel)
}

Expand Down
4 changes: 3 additions & 1 deletion cli/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

func TestEnable(t *testing.T) {
defer func() {
os.Setenv("DEBUG", "")
logrus.SetLevel(logrus.InfoLevel)
}()
t.Setenv("DEBUG", "")
Enable()
if os.Getenv("DEBUG") != "1" {
t.Fatalf("expected DEBUG=1, got %s\n", os.Getenv("DEBUG"))
Expand All @@ -22,6 +22,7 @@ func TestEnable(t *testing.T) {
}

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

func TestEnabled(t *testing.T) {
t.Setenv("DEBUG", "")
Enable()
if !IsEnabled() {
t.Fatal("expected debug enabled, got false")
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/Dockerfile.lint
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ARG GO_VERSION=1.23.6
ARG ALPINE_VERSION=3.21
ARG GOLANGCI_LINT_VERSION=v1.63.4
ARG GOLANGCI_LINT_VERSION=v1.64.5

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

Expand Down
Loading