From c47732ca10fd08b51ed2267cf2a17b7ef1792598 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 1 May 2026 13:01:21 +0100 Subject: [PATCH] chore(ci): tighten go linting --- .golangci.yml | 13 +++++++++++++ cmd/discrawl/main_test.go | 2 +- internal/cli/cli_test.go | 2 +- internal/cli/direct_messages.go | 7 ++++--- internal/cli/docker_smoke_test.go | 4 ++-- internal/share/share_test.go | 17 +++++++---------- 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 06f8c2a..260645d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,21 +2,33 @@ version: "2" linters: enable: + - asasalint + - bidichk - bodyclose + - canonicalheader - copyloopvar + - dupword - durationcheck - errcheck - errchkjson - errorlint + - exptostd + - gocheckcompilerdirectives + - gocritic + - gomoddirectives - govet - intrange - ineffassign + - makezero - misspell - modernize - nilerr - nilnesserr + - noctx - nolintlint + - nosprintfhostport - perfsprint + - predeclared - rowserrcheck - sloglint - sqlclosecheck @@ -24,6 +36,7 @@ linters: - testifylint - unconvert - unused + - usetesting - usestdlibvars - wastedassign diff --git a/cmd/discrawl/main_test.go b/cmd/discrawl/main_test.go index 9131da6..63f1fc5 100644 --- a/cmd/discrawl/main_test.go +++ b/cmd/discrawl/main_test.go @@ -27,7 +27,7 @@ func TestMainHelpAndVersion(t *testing.T) { if err != nil { t.Fatalf("os.Executable: %v", err) } - cmd := exec.Command(exe, "-test.run=TestMainHelpAndVersion") + cmd := exec.CommandContext(t.Context(), exe, "-test.run=TestMainHelpAndVersion") cmd.Env = append(os.Environ(), "DISCRAWL_MAIN_ERROR=1") err = cmd.Run() var exitErr *exec.ExitError diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go index 6d44925..4af3ce8 100644 --- a/internal/cli/cli_test.go +++ b/internal/cli/cli_test.go @@ -728,7 +728,7 @@ func publishSnapshot(t *testing.T, ctx context.Context, s *store.Store, opts sha func runGit(t *testing.T, dir string, args ...string) { t.Helper() // #nosec G204 -- fixed git argv in test setup. - cmd := exec.Command("git", args...) + cmd := exec.CommandContext(t.Context(), "git", args...) cmd.Dir = dir out, err := cmd.CombinedOutput() require.NoError(t, err, string(out)) diff --git a/internal/cli/direct_messages.go b/internal/cli/direct_messages.go index 6d44ae8..d417e0c 100644 --- a/internal/cli/direct_messages.go +++ b/internal/cli/direct_messages.go @@ -84,12 +84,13 @@ func (r *runtime) runDirectMessages(args []string) error { messageLimit := *limit messageLast := *last - if *all { + switch { + case *all: messageLimit = 0 messageLast = 0 - } else if flagPassed(fs, "limit") { + case flagPassed(fs, "limit"): messageLast = 0 - } else { + default: messageLimit = 0 } rows, err := r.store.ListMessages(r.ctx, store.MessageListOptions{ diff --git a/internal/cli/docker_smoke_test.go b/internal/cli/docker_smoke_test.go index 58f262c..d7427a0 100644 --- a/internal/cli/docker_smoke_test.go +++ b/internal/cli/docker_smoke_test.go @@ -18,7 +18,7 @@ func TestDockerGitSourceSmoke(t *testing.T) { t.Skip("docker is not installed") } root := repoRoot(t) - cmd := exec.Command("bash", filepath.Join(root, "scripts", "docker-git-source-smoke.sh")) + cmd := exec.CommandContext(t.Context(), "bash", filepath.Join(root, "scripts", "docker-git-source-smoke.sh")) cmd.Dir = root out, err := cmd.CombinedOutput() require.NoError(t, err, string(out)) @@ -26,7 +26,7 @@ func TestDockerGitSourceSmoke(t *testing.T) { func repoRoot(t *testing.T) string { t.Helper() - cmd := exec.Command("git", "rev-parse", "--show-toplevel") + cmd := exec.CommandContext(t.Context(), "git", "rev-parse", "--show-toplevel") out, err := cmd.Output() require.NoError(t, err) return strings.TrimSpace(string(out)) diff --git a/internal/share/share_test.go b/internal/share/share_test.go index 473c667..cc4971c 100644 --- a/internal/share/share_test.go +++ b/internal/share/share_test.go @@ -462,9 +462,9 @@ func TestGitCommitDetectsNoChanges(t *testing.T) { _, err := Export(ctx, src, opts) require.NoError(t, err) // #nosec G204 -- fixed git argv in test setup. - require.NoError(t, exec.Command("git", "-C", repo, "config", "user.name", "discrawl test").Run()) + require.NoError(t, exec.CommandContext(t.Context(), "git", "-C", repo, "config", "user.name", "discrawl test").Run()) // #nosec G204 -- fixed git argv in test setup. - require.NoError(t, exec.Command("git", "-C", repo, "config", "user.email", "discrawl@example.com").Run()) + require.NoError(t, exec.CommandContext(t.Context(), "git", "-C", repo, "config", "user.email", "discrawl@example.com").Run()) committed, err := Commit(ctx, opts, "test: snapshot") require.NoError(t, err) @@ -483,16 +483,13 @@ func TestPullAndPushWithBareRemote(t *testing.T) { dir := t.TempDir() remote := filepath.Join(dir, "remote.git") // #nosec G204 -- fixed git argv in test setup. - require.NoError(t, exec.Command("git", "-C", dir, "init", "--bare", remote).Run()) + require.NoError(t, exec.CommandContext(t.Context(), "git", "-C", dir, "init", "--bare", remote).Run()) publisher := filepath.Join(dir, "publisher") opts := Options{RepoPath: publisher, Remote: remote, Branch: "main"} _, err := Export(ctx, src, opts) require.NoError(t, err) - // #nosec G204 -- fixed git argv in test setup. - require.NoError(t, exec.Command("git", "-C", publisher, "config", "user.name", "discrawl test").Run()) - // #nosec G204 -- fixed git argv in test setup. - require.NoError(t, exec.Command("git", "-C", publisher, "config", "user.email", "discrawl@example.com").Run()) + configureGitUser(t, publisher) committed, err := Commit(ctx, opts, "test: snapshot") require.NoError(t, err) require.True(t, committed) @@ -512,7 +509,7 @@ func TestPushRebasesRemoteReadmeUpdates(t *testing.T) { dir := t.TempDir() remote := filepath.Join(dir, "remote.git") // #nosec G204 -- fixed git argv in test setup. - require.NoError(t, exec.Command("git", "-C", dir, "init", "--bare", remote).Run()) + require.NoError(t, exec.CommandContext(t.Context(), "git", "-C", dir, "init", "--bare", remote).Run()) publisher := filepath.Join(dir, "publisher") opts := Options{RepoPath: publisher, Remote: remote, Branch: "main"} @@ -908,9 +905,9 @@ func seedDirectMessageData(t *testing.T, ctx context.Context, s *store.Store) { func configureGitUser(t *testing.T, repo string) { t.Helper() // #nosec G204 -- fixed git argv in test setup. - require.NoError(t, exec.Command("git", "-C", repo, "config", "user.name", "discrawl test").Run()) + require.NoError(t, exec.CommandContext(t.Context(), "git", "-C", repo, "config", "user.name", "discrawl test").Run()) // #nosec G204 -- fixed git argv in test setup. - require.NoError(t, exec.Command("git", "-C", repo, "config", "user.email", "discrawl@example.com").Run()) + require.NoError(t, exec.CommandContext(t.Context(), "git", "-C", repo, "config", "user.email", "discrawl@example.com").Run()) } func mustReadManifest(t *testing.T, repo string) Manifest {