Skip to content

Commit

Permalink
ruletuard: change group filter signature (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
peakle authored Feb 13, 2022
1 parent cb19258 commit 6aa060f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(),
Expand Down Expand Up @@ -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 == "<all>" || enabledGroups[g]
enabled := flagEnable == "<all>" || 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 == ""
Expand Down
2 changes: 1 addition & 1 deletion ruleguard/ir_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ruleguard/ruleguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 6aa060f

Please sign in to comment.