check-safety/check_codegen.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

64 lines
2.0 KiB
Go

package main
import "strings"
func init() {
register(Check{
Seq: 25,
ID: "2f",
Title: "sqlc compile and buf generate",
Run: func(ctx *ScanContext, rep *Reporter) {
codegenTargets := discoverCodegenTargets(ctx.repoRoot, ctx.backendDir, ctx.backendTargets, ctx.pluginTargets, ctx.includeCoreTargets)
if len(codegenTargets) > 0 {
completedCodegenTargets, codegenFailures, codegenErr := runCodegenChecks(codegenTargets)
if codegenErr != nil {
rep.Fatal("failed to run codegen checks: %v", codegenErr)
}
if len(codegenFailures) > 0 {
rep.Fail("%d codegen target(s) failed sqlc compile or buf generate", len(codegenFailures))
for _, failure := range codegenFailures {
rep.Findingf("[%s] %s", failure.stage, failure.target)
if failure.output != "" {
for line := range strings.SplitSeq(failure.output, "\n") {
rep.Findingf("%s", line)
}
}
}
} else {
rep.OK("sqlc compile / buf generate clean for %d target(s)", len(completedCodegenTargets))
}
} else {
rep.Skip("no sqlc or buf codegen targets found")
}
protoFreshness, protoFreshnessErr := checkProtoGeneratedFreshness(ctx.repoRoot)
if protoFreshnessErr != nil {
rep.Fail("failed to run make proto freshness check: %v", protoFreshnessErr)
if protoFreshness.output != "" {
for line := range strings.SplitSeq(protoFreshness.output, "\n") {
rep.Findingf("%s", line)
}
}
} else if protoFreshness.changed() {
rep.Fail("make proto changed generated outputs; run make proto and commit the generated files")
rep.Finding("before:")
appendStatusFindings(rep, protoFreshness.beforeStatus)
rep.Finding("after:")
appendStatusFindings(rep, protoFreshness.afterStatus)
} else if protoFreshness.checked {
rep.OK("make proto freshness check clean")
}
},
})
}
func appendStatusFindings(rep *Reporter, status string) {
if strings.TrimSpace(status) == "" {
rep.Finding("(clean)")
return
}
for line := range strings.SplitSeq(status, "\n") {
rep.Findingf("%s", line)
}
}