check-safety/check_placeholder.go
Alex Dunmow cd88c808b0 initial: standalone check-safety module hoisted from CMS
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>
2026-06-06 13:04:02 +08:00

66 lines
2.2 KiB
Go

package main
import (
"fmt"
"sort"
)
func init() {
register(Check{
Seq: 110,
ID: "11",
Title: "No placeholder code; only shipped features",
Run: func(ctx *ScanContext, rep *Reporter) {
// Check 11: No placeholder code; only shipped features
fmt.Println("=== Check 11: No placeholder code; only shipped features ===")
comingSoonViolations := []comingSoonViolation{}
placeholderRoots := make([]todoScanRoot, 0, len(ctx.backendTargets)+len(ctx.frontendTargets)+len(ctx.pluginTargets))
for _, target := range ctx.backendTargets {
placeholderRoots = append(placeholderRoots, todoScanRoot{
root: target.root,
displayPrefix: target.display,
})
}
for _, target := range ctx.frontendTargets {
for _, v := range checkComingSoon(target.dir) {
v.file = prefixDisplayPath(target.label, v.file)
comingSoonViolations = append(comingSoonViolations, v)
}
placeholderRoots = append(placeholderRoots, todoScanRoot{
root: target.dir,
displayPrefix: target.label,
})
}
for _, target := range ctx.pluginTargets {
placeholderRoots = append(placeholderRoots, todoScanRoot{
root: target.root,
displayPrefix: target.display,
})
}
placeholderViolations := checkPlaceholderLanguage(placeholderRoots)
allPlaceholderViolations := append(comingSoonViolations, placeholderViolations...)
sort.Slice(allPlaceholderViolations, func(i, j int) bool {
if allPlaceholderViolations[i].file == allPlaceholderViolations[j].file {
return allPlaceholderViolations[i].line < allPlaceholderViolations[j].line
}
return allPlaceholderViolations[i].file < allPlaceholderViolations[j].file
})
if len(allPlaceholderViolations) > 0 {
fmt.Printf(" FAIL: %d placeholder reference(s) found:\n", len(allPlaceholderViolations))
for _, v := range allPlaceholderViolations {
fmt.Printf(" %s:%d %s\n", v.file, v.line, v.snippet)
}
fmt.Println("\n Fix: ship the feature now. Placeholder code is not allowed.")
rep.Fail()
} else {
fmt.Println(" OK: No placeholder code found")
printPerTargetOKLines(pluginTargetLabels(ctx.pluginTargets))
}
fmt.Println()
},
})
}