Skip to content

Commit 6e7c5bd

Browse files
committed
dev: update GL_DEBUG=revive to see enabled analyzers
1 parent 6d29861 commit 6e7c5bd

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

pkg/golinters/revive/revive.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"go/token"
99
"os"
1010
"reflect"
11+
"sort"
1112
"sync"
1213

1314
"github.com/BurntSushi/toml"
@@ -27,7 +28,10 @@ import (
2728

2829
const linterName = "revive"
2930

30-
var debugf = logutils.Debug(logutils.DebugKeyRevive)
31+
var (
32+
debugf = logutils.Debug(logutils.DebugKeyRevive)
33+
isDebug = logutils.HaveDebugTag(logutils.DebugKeyRevive)
34+
)
3135

3236
// jsonObject defines a JSON object of a failure
3337
type jsonObject struct {
@@ -228,14 +232,23 @@ func getConfig(cfg *config.ReviveSettings) (*lint.Config, error) {
228232

229233
normalizeConfig(conf)
230234

235+
rulesEnabledByConfig := []string{}
231236
for k, r := range conf.Rules {
232237
err := r.Initialize()
233238
if err != nil {
234239
return nil, fmt.Errorf("error in config of rule %q: %w", k, err)
235240
}
236241
conf.Rules[k] = r
242+
243+
if !r.Disabled {
244+
rulesEnabledByConfig = append(rulesEnabledByConfig, k)
245+
}
237246
}
238247

248+
debugChecksListf(extractRulesName(allRules), "All available analyzers")
249+
debugChecksListf(extractRulesName(defaultRules), "Default analyzers")
250+
debugChecksListf(rulesEnabledByConfig, "Enabled by config analyzers")
251+
239252
debugf("revive configuration: %#v", conf)
240253

241254
return conf, nil
@@ -447,3 +460,20 @@ func defaultConfig() *lint.Config {
447460
}
448461
return &defaultConfig
449462
}
463+
464+
func extractRulesName(rules []lint.Rule) []string {
465+
names := []string{}
466+
for _, r := range rules {
467+
names = append(names, r.Name())
468+
}
469+
return names
470+
}
471+
472+
func debugChecksListf(checks []string, format string, args ...any) {
473+
if !isDebug {
474+
return
475+
}
476+
sort.Strings(checks)
477+
478+
debugf("%s checks (%d): %s", fmt.Sprintf(format, args...), len(checks), fmt.Sprint(checks))
479+
}

0 commit comments

Comments
 (0)