Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change group filter signature #376

Merged
merged 1 commit into from Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions analyzer/analyzer.go
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
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
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