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>
50 lines
1.7 KiB
Go
50 lines
1.7 KiB
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
func init() {
|
|
register(Check{
|
|
Seq: 24,
|
|
ID: "2e",
|
|
Title: "Warn on any usage in Go and TypeScript",
|
|
Run: func(ctx *ScanContext, rep *Reporter) {
|
|
// Check 2e: Warn on any usage in Go and TypeScript
|
|
fmt.Println("=== Check 2e: Warn on any usage in Go and TypeScript ===")
|
|
var anyWarnings []anyUsageWarning
|
|
for _, target := range ctx.backendTargets {
|
|
for _, w := range checkGoAnyUsage(target.root) {
|
|
w.file = prefixDisplayPath(target.displayOrRoot(), w.file)
|
|
anyWarnings = append(anyWarnings, w)
|
|
}
|
|
}
|
|
for _, target := range ctx.pluginTargets {
|
|
for _, w := range checkGoAnyUsage(target.root) {
|
|
w.file = prefixDisplayPath(target.display, w.file)
|
|
anyWarnings = append(anyWarnings, w)
|
|
}
|
|
}
|
|
for _, target := range collectESLintDirectiveTargets(ctx.repoRoot, ctx.frontendTargets) {
|
|
for _, w := range checkTypeScriptAnyUsage(target.dir) {
|
|
w.file = prefixDisplayPath(target.label, w.file)
|
|
anyWarnings = append(anyWarnings, w)
|
|
}
|
|
}
|
|
if len(anyWarnings) > 0 {
|
|
fmt.Printf(" WARN: %d any usage warning(s):\n", len(anyWarnings))
|
|
limit := min(len(anyWarnings), maxAnyWarningsPrinted)
|
|
for _, w := range anyWarnings[:limit] {
|
|
fmt.Printf(" %s:%d [%s] %s\n", w.file, w.line, w.lang, w.snippet)
|
|
}
|
|
if len(anyWarnings) > limit {
|
|
fmt.Printf(" ... %d additional warning(s) omitted\n", len(anyWarnings)-limit)
|
|
}
|
|
fmt.Println("\n Guidance: prefer concrete types, generics, typed maps/structs, or unknown-style narrowing patterns over any.")
|
|
} else {
|
|
fmt.Println(" OK: No any usage found in scanned Go or TypeScript sources")
|
|
}
|
|
|
|
fmt.Println()
|
|
},
|
|
})
|
|
}
|