Static safety/lint runner for the BlockNinja codebase. ~25 invariant
checks across Go and frontend sources. Was at git.dev.alexdunmow.com:block/ninja
in backend/cmd/check-safety/ until the 2026-06-06 consolidation moved
the BlockNinja repos under a shared ~/src/blockninja/ parent.
This repo is the standalone extraction:
- Own go.mod (git.dev.alexdunmow.com/block/check-safety, go 1.26.4)
- Vendored internal/{helpers,theme} from CMS (Go's internal/ rule
blocks cross-module imports; vendoring is the workaround)
- CLI contract unchanged: `check-safety <target-dir> [--flags]`
- CMS Makefile shells into ../check-safety for safety-check /
install-safety-checker targets
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
67 lines
2.0 KiB
Go
67 lines
2.0 KiB
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
func init() {
|
|
register(Check{
|
|
Seq: 50,
|
|
ID: "5",
|
|
Title: "Frontend uses generated ConnectRPC hooks",
|
|
Run: func(ctx *ScanContext, rep *Reporter) {
|
|
// Check 5: Frontend API usage patterns
|
|
fmt.Println("=== Check 5: Frontend uses generated ConnectRPC hooks ===")
|
|
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 {
|
|
fmt.Printf(" FAIL: %d violation(s) — use generated hooks from @block-ninja/api/queries:\n", len(feViolations))
|
|
for _, v := range feViolations {
|
|
fmt.Printf(" %s:%d [%s] %s\n", v.file, v.line, v.rule, v.snippet)
|
|
}
|
|
rep.Fail()
|
|
}
|
|
|
|
if len(feWarnings) > 0 {
|
|
fmt.Printf(" WARN: %d fetch() call(s) to non-proto REST endpoints (no ConnectRPC equivalent):\n", len(feWarnings))
|
|
for _, w := range feWarnings {
|
|
fmt.Printf(" %s:%d %s\n", w.file, w.line, w.snippet)
|
|
}
|
|
}
|
|
|
|
if len(feViolations) == 0 {
|
|
fmt.Printf(" OK: Frontend API patterns are clean")
|
|
if len(feWarnings) > 0 {
|
|
fmt.Printf(" (%d known non-proto fetches)", len(feWarnings))
|
|
}
|
|
fmt.Println()
|
|
printPerTargetOKLines(frontendTargetLabels(ctx.frontendTargets))
|
|
}
|
|
} else {
|
|
fmt.Println(" SKIP: no frontend sources found")
|
|
}
|
|
|
|
fmt.Println()
|
|
},
|
|
})
|
|
}
|