chore(ci): tighten go linting

This commit is contained in:
Peter Steinberger 2026-05-01 13:01:21 +01:00
parent b7346ada62
commit c47732ca10
No known key found for this signature in database
6 changed files with 28 additions and 17 deletions

View File

@ -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

View File

@ -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

View File

@ -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))

View File

@ -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{

View File

@ -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))

View File

@ -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 {