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

62 lines
1.7 KiB
Go

package main
import (
"os"
"path/filepath"
)
func init() {
register(Check{
Seq: 210,
ID: "21",
Title: "Plugin presets.json validation",
Run: func(ctx *ScanContext, rep *Reporter) {
var presetViolations []presetViolation
presetsChecked := 0
// Check internal plugins
if ctx.includeCoreTargets {
internalPluginsDir := filepath.Join(ctx.backendDir, "internal", "plugins")
if dirExists(internalPluginsDir) {
entries, _ := os.ReadDir(internalPluginsDir)
for _, entry := range entries {
if !entry.IsDir() {
continue
}
pluginDir := filepath.Join(internalPluginsDir, entry.Name())
if !fileExists(filepath.Join(pluginDir, "presets.json")) {
continue
}
presetsChecked++
for _, v := range checkPresets(pluginDir) {
v.file = prefixDisplayPath("plugins/"+entry.Name(), v.file)
presetViolations = append(presetViolations, v)
}
}
}
}
// Check external plugin roots
for _, target := range ctx.resolvedPluginTargets {
vs := checkPresets(target.root)
if len(vs) == 0 && len(findPresetsFiles(target.root)) > 0 {
presetsChecked++
}
for _, v := range vs {
presetsChecked++
v.file = prefixDisplayPath(target.display, v.file)
presetViolations = append(presetViolations, v)
}
}
if len(presetViolations) > 0 {
rep.Fail("%d presets.json validation error(s)", len(presetViolations))
for _, v := range presetViolations {
rep.Findingf("%s — %s", v.file, v.message)
}
} else if presetsChecked > 0 {
rep.OK("All presets.json files are valid (%d checked)", presetsChecked)
} else {
rep.OK("No presets.json files found in scanned targets")
}
},
})
}