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

checkers: add hidden ruleguard debug handle #1134

Merged
merged 1 commit into from Oct 19, 2021
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
12 changes: 11 additions & 1 deletion checkers/checkers.go
Expand Up @@ -34,6 +34,8 @@ func init() {

var buildContext *build.Context

ruleguardDebug := os.Getenv("GOCRITIC_RULEGUARD_DEBUG") != ""

// First we create an Engine to parse all rules.
// We need it to get the structured info about our rules
// that will be used to generate checkers.
Expand All @@ -46,7 +48,11 @@ func init() {
buildContext = rootEngine.BuildContext

loadContext := &ruleguard.LoadContext{
Fset: fset,
Fset: fset,
DebugImports: ruleguardDebug,
DebugPrint: func(s string) {
fmt.Println("debug:", s)
},
}
if err := rootEngine.LoadFromIR(loadContext, filename, rulesdata.PrecompiledRules); err != nil {
panic(fmt.Sprintf("load embedded ruleguard rules: %v", err))
Expand Down Expand Up @@ -74,6 +80,10 @@ func init() {
GroupFilter: func(name string) bool {
return name == g.Name
},
DebugImports: ruleguardDebug,
DebugPrint: func(s string) {
fmt.Println("debug:", s)
},
}
engine := ruleguard.NewEngine()
engine.BuildContext = buildContext
Expand Down
8 changes: 7 additions & 1 deletion checkers/ruleguard_checker.go
Expand Up @@ -124,8 +124,14 @@ func newRuleguardChecker(info *linter.CheckerInfo, ctx *linter.CheckerContext) (
fset := token.NewFileSet()
filePatterns := strings.Split(rulesFlag, ",")

ruleguardDebug := os.Getenv("GOCRITIC_RULEGUARD_DEBUG") != ""

loadContext := &ruleguard.LoadContext{
Fset: fset,
Fset: fset,
DebugImports: ruleguardDebug,
DebugPrint: func(s string) {
fmt.Println("debug:", s)
},
}

loaded := 0
Expand Down