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>
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func init() {
|
|
register(Check{
|
|
Seq: 30,
|
|
ID: "3",
|
|
Title: "Go code compiles and passes go fix, golangci-lint --fix, go vet, and strict lint",
|
|
Run: func(ctx *ScanContext, rep *Reporter) {
|
|
// Check 3: Go lint pipeline
|
|
fmt.Println("=== Check 3: Go code compiles and passes go fix, golangci-lint --fix, go vet, and strict lint ===")
|
|
goLintRoots := make([]string, 0, len(ctx.pluginTargets))
|
|
for _, target := range ctx.pluginTargets {
|
|
goLintRoots = append(goLintRoots, target.root)
|
|
}
|
|
backendLintRoots := make([]string, 0, len(ctx.backendTargets))
|
|
for _, target := range ctx.backendTargets {
|
|
backendLintRoots = append(backendLintRoots, target.root)
|
|
}
|
|
completedGoTargets, skippedGoTargets, goLintFailures, goLintErr := runStrictGoLint(ctx.repoRoot, backendLintRoots, goLintRoots)
|
|
if goLintErr != nil {
|
|
fmt.Printf(" ERROR: failed to run Go lint pipeline: %v\n", goLintErr)
|
|
os.Exit(2)
|
|
}
|
|
for _, skipped := range skippedGoTargets {
|
|
fmt.Printf(" SKIP: %s\n", skipped)
|
|
}
|
|
if len(goLintFailures) > 0 {
|
|
fmt.Printf(" FAIL: %d Go module(s) failed the Go lint pipeline:\n", len(goLintFailures))
|
|
for _, failure := range goLintFailures {
|
|
fmt.Printf(" [%s]\n", failure.target)
|
|
if failure.output != "" {
|
|
for line := range strings.SplitSeq(failure.output, "\n") {
|
|
fmt.Printf(" %s\n", line)
|
|
}
|
|
}
|
|
}
|
|
rep.Fail()
|
|
} else if len(completedGoTargets) > 0 {
|
|
fmt.Printf(" OK: Go lint pipeline clean for %d module(s)\n", len(completedGoTargets))
|
|
for _, target := range completedGoTargets {
|
|
fmt.Printf(" - %s\n", target)
|
|
}
|
|
} else {
|
|
fmt.Println(" SKIP: no Go modules found")
|
|
}
|
|
|
|
fmt.Println()
|
|
},
|
|
})
|
|
}
|