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

41 lines
1.3 KiB
Go

package main
func init() {
register(Check{
Seq: 180,
ID: "18",
Title: "Plugin segmentation (safety-rules.yml)",
Run: func(ctx *ScanContext, rep *Reporter) {
var segViolations []segmentationViolation
segPluginsChecked := 0
for _, target := range ctx.resolvedPluginTargets {
rules, loadErr := loadSafetyRules(target.root)
if loadErr != nil {
rep.Fail("%s: %v", target.display, loadErr)
continue
}
if rules == nil || rules.Segmentation == nil {
continue // No safety-rules.yml or no segmentation section — skip
}
segPluginsChecked++
vs := checkSegmentation(target.root, target.display, rules.Segmentation)
segViolations = append(segViolations, vs...)
}
if len(segViolations) > 0 {
rep.Fail("%d segmentation violation(s) found", len(segViolations))
for _, v := range segViolations {
if v.line > 0 {
rep.Findingf("%s/%s:%d [%s] %s", v.pluginName, v.file, v.line, v.rule, v.detail)
} else {
rep.Findingf("%s/%s [%s] %s", v.pluginName, v.file, v.rule, v.detail)
}
}
} else if segPluginsChecked > 0 {
rep.OK("Plugin segmentation clean (%d plugin(s) checked)", segPluginsChecked)
} else {
rep.OK("No plugins define safety-rules.yml segmentation rules")
}
},
})
}