check-safety/check_golint.go
Alex Dunmow c4d01de82c feat: concise output + diff-scoped any check
Reporter is now a collector: checks declare a verdict (OK/Skip/Warn/Fail/
Fatal) plus findings, and a single central render() prints output. Default
output is silent on pass/skip — only FAIL/WARN/ERR checks print, followed by
one tally line, so a clean run is two lines. --verbose restores full per-check
output. All ~30 checks were converted to this API; orphaned guidance/label
helpers (printPerTargetOKLines, per-check *Help blocks, colors_format.go) were
removed.

The any-usage check (2e) now defaults to only the unstaged working-tree diff
(changed lines), via a new per-repo git-diff index in changedlines.go; --all-any
restores the full scan. Not-a-git-repo / no-diff warns on nothing.

Golden fixtures regenerated; integration tests updated to the new format; added
unit tests for the diff index.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-04 01:16:56 +08:00

44 lines
1.4 KiB
Go

package main
import "strings"
func init() {
register(Check{
Seq: 30,
ID: "3",
Title: "Go code compiles and passes go fix, golangci-lint --fix, go vet, and strict lint",
Run: func(ctx *ScanContext, rep *Reporter) {
goLintRoots := make([]string, 0, len(ctx.pluginTargets))
for _, target := range ctx.pluginTargets {
goLintRoots = append(goLintRoots, target.root)
}
backendLintRoots := make([]string, 0, len(ctx.backendTargets))
for _, target := range ctx.backendTargets {
backendLintRoots = append(backendLintRoots, target.root)
}
completedGoTargets, skippedGoTargets, goLintFailures, goLintErr := runStrictGoLint(ctx.repoRoot, backendLintRoots, goLintRoots)
if goLintErr != nil {
rep.Fatal("failed to run Go lint pipeline: %v", goLintErr)
}
for _, skipped := range skippedGoTargets {
rep.Skip("%s", skipped)
}
if len(goLintFailures) > 0 {
rep.Fail("%d Go module(s) failed the Go lint pipeline", len(goLintFailures))
for _, failure := range goLintFailures {
rep.Findingf("[%s]", failure.target)
if failure.output != "" {
for line := range strings.SplitSeq(failure.output, "\n") {
rep.Findingf(" %s", line)
}
}
}
} else if len(completedGoTargets) > 0 {
rep.OK("Go lint pipeline clean for %d module(s)", len(completedGoTargets))
} else {
rep.Skip("no Go modules found")
}
},
})
}