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>
82 lines
3.1 KiB
Go
82 lines
3.1 KiB
Go
package main
|
|
|
|
func init() {
|
|
register(Check{
|
|
Seq: 22,
|
|
ID: "2c",
|
|
Title: "Standalone plugin SDK import boundaries",
|
|
Run: func(ctx *ScanContext, rep *Reporter) {
|
|
var cmsGoModViolations []pluginGoModViolation
|
|
var pluginImportViolations []pluginImportViolation
|
|
var pluginGoModViolations []pluginGoModViolation
|
|
var standalonePluginLabels []string
|
|
checkedStandalonePluginRoots := make(map[string]bool)
|
|
requiredSDKVersion, requiredSDKVersionErr := currentCMSCoreSDKVersion()
|
|
if requiredSDKVersionErr != nil {
|
|
rep.Fatal("failed to resolve CMS SDK version: %v", requiredSDKVersionErr)
|
|
}
|
|
checkStandalonePluginRoot := func(root string, label string) {
|
|
if checkedStandalonePluginRoots[root] || !shouldCheckStandalonePluginImports(root) {
|
|
return
|
|
}
|
|
checkedStandalonePluginRoots[root] = true
|
|
standalonePluginLabels = append(standalonePluginLabels, label)
|
|
for _, v := range checkStandalonePluginImports(root) {
|
|
v.file = prefixDisplayPath(label, v.file)
|
|
pluginImportViolations = append(pluginImportViolations, v)
|
|
}
|
|
for _, v := range checkStandalonePluginGoMod(root, requiredSDKVersion) {
|
|
v.file = prefixDisplayPath(label, v.file)
|
|
pluginGoModViolations = append(pluginGoModViolations, v)
|
|
}
|
|
}
|
|
for _, target := range ctx.backendTargets {
|
|
if samePath(target.root, ctx.backendDir) {
|
|
for _, v := range checkCMSCoreSDKGoMod(target.root) {
|
|
v.file = prefixDisplayPath(target.displayOrRoot(), v.file)
|
|
cmsGoModViolations = append(cmsGoModViolations, v)
|
|
}
|
|
}
|
|
checkStandalonePluginRoot(target.root, target.displayOrRoot())
|
|
}
|
|
for _, target := range ctx.pluginTargets {
|
|
checkStandalonePluginRoot(target.root, target.display)
|
|
}
|
|
if len(cmsGoModViolations) > 0 || len(pluginImportViolations) > 0 || len(pluginGoModViolations) > 0 {
|
|
if len(cmsGoModViolations) > 0 {
|
|
rep.Fail("%d CMS backend go.mod violation(s)", len(cmsGoModViolations))
|
|
for _, v := range cmsGoModViolations {
|
|
if v.line > 0 {
|
|
rep.Findingf("%s:%d [%s] %s", v.file, v.line, v.rule, v.detail)
|
|
continue
|
|
}
|
|
rep.Findingf("%s [%s] %s", v.file, v.rule, v.detail)
|
|
}
|
|
}
|
|
if len(pluginImportViolations) > 0 {
|
|
rep.Fail("%d standalone plugin import violation(s)", len(pluginImportViolations))
|
|
for _, v := range pluginImportViolations {
|
|
rep.Findingf("%s:%d imports BlockNinja CMS package %q", v.file, v.line, v.importPath)
|
|
}
|
|
}
|
|
if len(pluginGoModViolations) > 0 {
|
|
rep.Fail("%d standalone plugin go.mod violation(s)", len(pluginGoModViolations))
|
|
for _, v := range pluginGoModViolations {
|
|
if v.line > 0 {
|
|
rep.Findingf("%s:%d [%s] %s", v.file, v.line, v.rule, v.detail)
|
|
continue
|
|
}
|
|
rep.Findingf("%s [%s] %s", v.file, v.rule, v.detail)
|
|
}
|
|
}
|
|
} else if len(standalonePluginLabels) > 0 {
|
|
rep.OK("Standalone plugin imports and go.mod stay on SDK version %s", requiredSDKVersion)
|
|
} else if ctx.includeCoreTargets {
|
|
rep.OK("%s/go.mod does not locally replace %s", ctx.backendTargets[0].displayOrRoot(), blockCoreImportPrefix)
|
|
} else {
|
|
rep.Skip("no standalone plugin roots scanned")
|
|
}
|
|
},
|
|
})
|
|
}
|