Skip to content

Commit 6aa060f

Browse files
authored
ruletuard: change group filter signature (#376)
1 parent cb19258 commit 6aa060f

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

analyzer/analyzer.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import (
1010
"strings"
1111
"sync"
1212

13-
"github.com/quasilyte/go-ruleguard/ruleguard"
1413
"golang.org/x/tools/go/analysis"
14+
15+
"github.com/quasilyte/go-ruleguard/ruleguard"
1516
)
1617

1718
// Version contains extra version info.
18-
// It's is initialized via ldflags -X when ruleguard is built with Make.
19+
// It's initialized via ldflags -X when ruleguard is built with Make.
1920
// Can contain a git hash (dev builds) or a version tag (release builds).
2021
var Version string
2122

@@ -27,7 +28,7 @@ func docString() string {
2728
return doc + " (" + Version + ")"
2829
}
2930

30-
// Analyzer exports ruleguard as a analysis-compatible object.
31+
// Analyzer exports ruleguard as an analysis-compatible object.
3132
var Analyzer = &analysis.Analyzer{
3233
Name: "ruleguard",
3334
Doc: docString(),
@@ -191,20 +192,20 @@ func newEngine() (*ruleguard.Engine, error) {
191192
DebugFilter: flagDebugFilter,
192193
DebugImports: flagDebugImports,
193194
DebugPrint: debugPrint,
194-
GroupFilter: func(g string) bool {
195+
GroupFilter: func(g *ruleguard.GoRuleGroup) bool {
195196
whyDisabled := ""
196-
enabled := flagEnable == "<all>" || enabledGroups[g]
197+
enabled := flagEnable == "<all>" || enabledGroups[g.Name]
197198
switch {
198199
case !enabled:
199200
whyDisabled = "not enabled by -enabled flag"
200-
case disabledGroups[g]:
201+
case disabledGroups[g.Name]:
201202
whyDisabled = "disabled by -disable flag"
202203
}
203204
if flagDebugEnableDisable {
204205
if whyDisabled != "" {
205-
debugPrint(fmt.Sprintf("(-) %s is %s", g, whyDisabled))
206+
debugPrint(fmt.Sprintf("(-) %s is %s", g.Name, whyDisabled))
206207
} else {
207-
debugPrint(fmt.Sprintf("(+) %s is enabled", g))
208+
debugPrint(fmt.Sprintf("(+) %s is enabled", g.Name))
208209
}
209210
}
210211
return whyDisabled == ""

ruleguard/ir_loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func (l *irLoader) loadRuleGroup(group *ir.RuleGroup) error {
238238
l.group.Name = l.prefix + "/" + l.group.Name
239239
}
240240

241-
if l.ctx.GroupFilter != nil && !l.ctx.GroupFilter(l.group.Name) {
241+
if l.ctx.GroupFilter != nil && !l.ctx.GroupFilter(l.group) {
242242
return nil // Skip this group
243243
}
244244
if _, ok := l.res.groups[l.group.Name]; ok {

ruleguard/ruleguard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type LoadContext struct {
8383
// If function returns false, that group will not be included
8484
// in the resulting rules set.
8585
// Nil filter accepts all rule groups.
86-
GroupFilter func(string) bool
86+
GroupFilter func(*GoRuleGroup) bool
8787

8888
Fset *token.FileSet
8989
}

0 commit comments

Comments
 (0)