diff --git a/analyzer/analyzer.go b/analyzer/analyzer.go index 4dd0f8a..01c4499 100644 --- a/analyzer/analyzer.go +++ b/analyzer/analyzer.go @@ -10,12 +10,13 @@ import ( "strings" "sync" - "github.com/quasilyte/go-ruleguard/ruleguard" "golang.org/x/tools/go/analysis" + + "github.com/quasilyte/go-ruleguard/ruleguard" ) // Version contains extra version info. -// It's is initialized via ldflags -X when ruleguard is built with Make. +// It's initialized via ldflags -X when ruleguard is built with Make. // Can contain a git hash (dev builds) or a version tag (release builds). var Version string @@ -27,7 +28,7 @@ func docString() string { return doc + " (" + Version + ")" } -// Analyzer exports ruleguard as a analysis-compatible object. +// Analyzer exports ruleguard as an analysis-compatible object. var Analyzer = &analysis.Analyzer{ Name: "ruleguard", Doc: docString(), @@ -191,20 +192,20 @@ func newEngine() (*ruleguard.Engine, error) { DebugFilter: flagDebugFilter, DebugImports: flagDebugImports, DebugPrint: debugPrint, - GroupFilter: func(g string) bool { + GroupFilter: func(g *ruleguard.GoRuleGroup) bool { whyDisabled := "" - enabled := flagEnable == "" || enabledGroups[g] + enabled := flagEnable == "" || enabledGroups[g.Name] switch { case !enabled: whyDisabled = "not enabled by -enabled flag" - case disabledGroups[g]: + case disabledGroups[g.Name]: whyDisabled = "disabled by -disable flag" } if flagDebugEnableDisable { if whyDisabled != "" { - debugPrint(fmt.Sprintf("(-) %s is %s", g, whyDisabled)) + debugPrint(fmt.Sprintf("(-) %s is %s", g.Name, whyDisabled)) } else { - debugPrint(fmt.Sprintf("(+) %s is enabled", g)) + debugPrint(fmt.Sprintf("(+) %s is enabled", g.Name)) } } return whyDisabled == "" diff --git a/ruleguard/ir_loader.go b/ruleguard/ir_loader.go index ea3402f..ff107f9 100644 --- a/ruleguard/ir_loader.go +++ b/ruleguard/ir_loader.go @@ -238,7 +238,7 @@ func (l *irLoader) loadRuleGroup(group *ir.RuleGroup) error { l.group.Name = l.prefix + "/" + l.group.Name } - if l.ctx.GroupFilter != nil && !l.ctx.GroupFilter(l.group.Name) { + if l.ctx.GroupFilter != nil && !l.ctx.GroupFilter(l.group) { return nil // Skip this group } if _, ok := l.res.groups[l.group.Name]; ok { diff --git a/ruleguard/ruleguard.go b/ruleguard/ruleguard.go index 65eed6e..896fede 100644 --- a/ruleguard/ruleguard.go +++ b/ruleguard/ruleguard.go @@ -83,7 +83,7 @@ type LoadContext struct { // If function returns false, that group will not be included // in the resulting rules set. // Nil filter accepts all rule groups. - GroupFilter func(string) bool + GroupFilter func(*GoRuleGroup) bool Fset *token.FileSet }