Skip to content

Commit

Permalink
update ruleguard (#1214)
Browse files Browse the repository at this point in the history
  • Loading branch information
peakle committed Mar 27, 2022
1 parent 7f98529 commit 73c0832
Show file tree
Hide file tree
Showing 5 changed files with 1,105 additions and 1,589 deletions.
16 changes: 9 additions & 7 deletions checkers/embedded_rules.go
Expand Up @@ -7,9 +7,10 @@ import (
"go/token"
"os"

"github.com/quasilyte/go-ruleguard/ruleguard"

"github.com/go-critic/go-critic/checkers/rulesdata"
"github.com/go-critic/go-critic/framework/linter"
"github.com/quasilyte/go-ruleguard/ruleguard"
)

//go:generate go run ./rules/precompile.go -rules ./rules/rules.go -o ./rulesdata/rulesdata.go
Expand Down Expand Up @@ -65,8 +66,8 @@ func init() {
collection.AddChecker(info, func(ctx *linter.CheckerContext) (linter.FileWalker, error) {
parseContext := &ruleguard.LoadContext{
Fset: fset,
GroupFilter: func(name string) bool {
return name == g.Name
GroupFilter: func(gr *ruleguard.GoRuleGroup) bool {
return gr.Name == g.Name
},
DebugImports: ruleguardDebug,
DebugPrint: func(s string) {
Expand Down Expand Up @@ -95,9 +96,10 @@ type embeddedRuleguardChecker struct {

func (c *embeddedRuleguardChecker) WalkFile(f *ast.File) {
runRuleguardEngine(c.ctx, f, c.engine, &ruleguard.RunContext{
Pkg: c.ctx.Pkg,
Types: c.ctx.TypesInfo,
Sizes: c.ctx.SizesInfo,
Fset: c.ctx.FileSet,
Pkg: c.ctx.Pkg,
Types: c.ctx.TypesInfo,
Sizes: c.ctx.SizesInfo,
Fset: c.ctx.FileSet,
TruncateLen: 100,
})
}
19 changes: 10 additions & 9 deletions checkers/ruleguard_checker.go
Expand Up @@ -153,20 +153,20 @@ func newRuleguardChecker(info *linter.CheckerInfo, ctx *linter.CheckerContext) (
Fset: fset,
DebugImports: ruleguardDebug,
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 ruleguardDebug {
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 Expand Up @@ -225,10 +225,11 @@ func (c *ruleguardChecker) WalkFile(f *ast.File) {
DebugPrint: func(s string) {
fmt.Fprintln(os.Stderr, s)
},
Pkg: c.ctx.Pkg,
Types: c.ctx.TypesInfo,
Sizes: c.ctx.SizesInfo,
Fset: c.ctx.FileSet,
Pkg: c.ctx.Pkg,
Types: c.ctx.TypesInfo,
Sizes: c.ctx.SizesInfo,
Fset: c.ctx.FileSet,
TruncateLen: 100,
})
}

Expand Down

0 comments on commit 73c0832

Please sign in to comment.