A codeless .bnp repo has no go.mod by design — mirror the ninja CLI classifier (core bnp.IsCodelessRepo) and skip both the standalone-plugin go.mod checks and the backend replace-directive parse for such roots. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
84 lines
3.3 KiB
Go
84 lines
3.3 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 {
|
|
// A codeless plugin repo (plugin.mod, no Go) has no go.mod by
|
|
// design — nothing for the replace-directive check to parse.
|
|
if samePath(target.root, ctx.backendDir) && !isCodelessPluginRepo(target.root) {
|
|
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")
|
|
}
|
|
},
|
|
})
|
|
}
|