Skip to content

Commit d45036a

Browse files
ccoVeilleldez
andauthored
dev: displays revive rules inside debug logs (#5325)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent 37bca37 commit d45036a

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

.golangci.next.reference.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2371,7 +2371,7 @@ linters-settings:
23712371
# This means that linting errors with less than 0.8 confidence will be ignored.
23722372
# Default: 0.8
23732373
confidence: 0.1
2374-
2374+
# Run `GL_DEBUG=revive golangci-lint run --enable-only=revive` to see default, all available rules, and enabled rules.
23752375
rules:
23762376
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#add-constant
23772377
- name: add-constant

pkg/golinters/revive/revive.go

+41-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"go/token"
99
"os"
1010
"reflect"
11+
"slices"
12+
"strings"
1113
"sync"
1214

1315
"github.com/BurntSushi/toml"
@@ -27,7 +29,10 @@ import (
2729

2830
const linterName = "revive"
2931

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

3237
// jsonObject defines a JSON object of a failure
3338
type jsonObject struct {
@@ -91,6 +96,8 @@ func newWrapper(settings *config.ReviveSettings) (*wrapper, error) {
9196
return nil, err
9297
}
9398

99+
displayRules(conf)
100+
94101
conf.GoVersion, err = hcversion.NewVersion(settings.Go)
95102
if err != nil {
96103
return nil, err
@@ -236,8 +243,6 @@ func getConfig(cfg *config.ReviveSettings) (*lint.Config, error) {
236243
conf.Rules[k] = r
237244
}
238245

239-
debugf("revive configuration: %#v", conf)
240-
241246
return conf, nil
242247
}
243248

@@ -447,3 +452,36 @@ func defaultConfig() *lint.Config {
447452
}
448453
return &defaultConfig
449454
}
455+
456+
func displayRules(conf *lint.Config) {
457+
if !isDebug {
458+
return
459+
}
460+
461+
var enabledRules []string
462+
for k, r := range conf.Rules {
463+
if !r.Disabled {
464+
enabledRules = append(enabledRules, k)
465+
}
466+
}
467+
468+
slices.Sort(enabledRules)
469+
470+
debugf("All available rules (%d): %s.", len(allRules), strings.Join(extractRulesName(allRules), ", "))
471+
debugf("Default rules (%d): %s.", len(allRules), strings.Join(extractRulesName(allRules), ", "))
472+
debugf("Enabled by config rules (%d): %s.", len(enabledRules), strings.Join(enabledRules, ", "))
473+
474+
debugf("revive configuration: %#v", conf)
475+
}
476+
477+
func extractRulesName(rules []lint.Rule) []string {
478+
var names []string
479+
480+
for _, r := range rules {
481+
names = append(names, r.Name())
482+
}
483+
484+
slices.Sort(names)
485+
486+
return names
487+
}

0 commit comments

Comments
 (0)