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

update ruleguard version #1214

Merged
merged 4 commits into from Mar 27, 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
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