From f1f8b6d02ed485764d2cc3515f1f2c1939353ba4 Mon Sep 17 00:00:00 2001 From: Mathias Date: Sat, 3 Oct 2026 20:54:20 +0200 Subject: [PATCH] fix(task): lint step fails on findings instead of printing 'not installed' (#41) Co-Authored-By: Claude Sonnet 5.5 --- Taskfile.yml | 2 +- test/lintgate/lintgate_test.go | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 6997897..6342786 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -34,7 +34,7 @@ tasks: lint: desc: golangci-lint (installed by CI; skipped locally if absent). cmds: - - 'command -v golangci-lint >/dev/null 2>&1 && golangci-lint run ./... || echo "golangci-lint not installed — skipping (CI installs it)"' + - 'if command -v golangci-lint >/dev/null 2>&1; then golangci-lint run ./...; else echo "golangci-lint not installed — skipping (CI installs it)"; fi' test: desc: Run all tests. -p 1 serializes packages so the embedded-postgres tests diff --git a/test/lintgate/lintgate_test.go b/test/lintgate/lintgate_test.go index c924abb..560e2ca 100644 --- a/test/lintgate/lintgate_test.go +++ b/test/lintgate/lintgate_test.go @@ -40,6 +40,17 @@ func scratchModule(t *testing.T) string { return dir } +// hasSkipNotice reports whether the skip notice was printed as output. Task echoes the command +// line first, and that line contains the same words, so a substring match would be vacuous. +func hasSkipNotice(out string) bool { + for _, line := range strings.Split(out, "\n") { + if strings.HasPrefix(line, "golangci-lint not installed") { + return true + } + } + return false +} + // runLint runs `task lint` in dir with the given PATH and returns its combined output and exit code. func runLint(t *testing.T, dir, path string) (string, int) { t.Helper() @@ -73,7 +84,7 @@ func TestTaskLint_ExitsNonZeroWhenGolangciLintReportsAFinding(t *testing.T) { if code == 0 { t.Fatalf("task lint exited 0 on a module with an unchecked error; output:\n%s", out) } - if strings.Contains(out, "not installed") { + if hasSkipNotice(out) { t.Fatalf("task lint blamed a missing binary for a lint failure; output:\n%s", out) } } @@ -91,7 +102,7 @@ func TestTaskLint_SkipsWithANoticeWhenGolangciLintIsAbsent(t *testing.T) { if code != 0 { t.Fatalf("task lint exited %d without golangci-lint on PATH; output:\n%s", code, out) } - if !strings.Contains(out, "not installed") { + if !hasSkipNotice(out) { t.Fatalf("expected the skip notice; output:\n%s", out) } }