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

55 lines
1.6 KiB
Go

package main
func init() {
register(Check{
Seq: 50,
ID: "5",
Title: "Frontend uses generated ConnectRPC hooks",
Run: func(ctx *ScanContext, rep *Reporter) {
if len(ctx.frontendTargets) > 0 {
var feViolations []frontendViolation
var feWarnings []frontendViolation
for _, target := range ctx.frontendTargets {
if target.pluginRules {
for _, v := range checkPluginPages([]string{target.dir}) {
v.file = prefixDisplayPath(target.label, v.file)
feViolations = append(feViolations, v)
}
continue
}
coreViolations, coreWarnings := checkFrontend(target.dir)
for _, v := range coreViolations {
v.file = prefixDisplayPath(target.label, v.file)
feViolations = append(feViolations, v)
}
for _, w := range coreWarnings {
w.file = prefixDisplayPath(target.label, w.file)
feWarnings = append(feWarnings, w)
}
}
if len(feViolations) > 0 {
rep.Fail("%d violation(s) — use generated hooks from @block-ninja/api/queries", len(feViolations))
for _, v := range feViolations {
rep.Findingf("%s:%d [%s] %s", v.file, v.line, v.rule, v.snippet)
}
}
if len(feWarnings) > 0 {
rep.Warn("%d fetch() call(s) to non-proto REST endpoints (no ConnectRPC equivalent)", len(feWarnings))
for _, w := range feWarnings {
rep.Findingf("%s:%d %s", w.file, w.line, w.snippet)
}
}
if len(feViolations) == 0 && len(feWarnings) == 0 {
rep.OK("Frontend API patterns are clean")
}
} else {
rep.Skip("no frontend sources found")
}
},
})
}