Skip to content

Commit aa98835

Browse files
authored
dev: display list of staticcheck checks in debug (#5853)
1 parent 5993608 commit aa98835

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

pkg/golinters/staticcheck/staticcheck.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import (
1515

1616
"github.com/golangci/golangci-lint/v2/pkg/config"
1717
"github.com/golangci/golangci-lint/v2/pkg/goanalysis"
18+
"github.com/golangci/golangci-lint/v2/pkg/logutils"
19+
)
20+
21+
var (
22+
debugf = logutils.Debug(logutils.DebugKeyStaticcheck)
23+
isDebug = logutils.HaveDebugTag(logutils.DebugKeyStaticcheck)
1824
)
1925

2026
func New(settings *config.StaticCheckSettings) *goanalysis.Linter {
@@ -29,6 +35,21 @@ func New(settings *config.StaticCheckSettings) *goanalysis.Linter {
2935

3036
analyzers := setupAnalyzers(allAnalyzers, cfg.Checks)
3137

38+
if isDebug {
39+
allAnalyzerNames := extractAnalyzerNames(allAnalyzers)
40+
slices.Sort(allAnalyzerNames)
41+
debugf("All available checks (%d): %s", len(allAnalyzers), strings.Join(allAnalyzerNames, ","))
42+
43+
var cfgAnalyzerNames []string
44+
for _, a := range analyzers {
45+
cfgAnalyzerNames = append(cfgAnalyzerNames, a.Name)
46+
}
47+
slices.Sort(cfgAnalyzerNames)
48+
debugf("Enabled by config checks (%d): %s", len(analyzers), strings.Join(cfgAnalyzerNames, ","))
49+
50+
debugf("staticcheck configuration: %#v", cfg)
51+
}
52+
3253
return goanalysis.NewLinter(
3354
"staticcheck",
3455
"It's the set of rules from staticcheck.",
@@ -107,12 +128,7 @@ func normalizeList(list []string) []string {
107128
}
108129

109130
func setupAnalyzers(src []*lint.Analyzer, checks []string) []*analysis.Analyzer {
110-
var names []string
111-
for _, a := range src {
112-
names = append(names, a.Analyzer.Name)
113-
}
114-
115-
filter := filterAnalyzerNames(names, checks)
131+
filter := filterAnalyzerNames(extractAnalyzerNames(src), checks)
116132

117133
var ret []*analysis.Analyzer
118134
for _, a := range src {
@@ -124,6 +140,14 @@ func setupAnalyzers(src []*lint.Analyzer, checks []string) []*analysis.Analyzer
124140
return ret
125141
}
126142

143+
func extractAnalyzerNames(analyzers []*lint.Analyzer) []string {
144+
var names []string
145+
for _, a := range analyzers {
146+
names = append(names, a.Analyzer.Name)
147+
}
148+
return names
149+
}
150+
127151
// https://github.com/dominikh/go-tools/blob/9bf17c0388a65710524ba04c2d821469e639fdc2/lintcmd/lint.go#L437-L477
128152
//
129153
//nolint:gocritic // Keep the original source code.

pkg/logutils/logutils.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ const (
7979

8080
// Linters.
8181
const (
82-
DebugKeyForbidigo = "forbidigo" // Debugs `forbidigo` linter.
83-
DebugKeyGoCritic = "gocritic" // Debugs `gocritic` linter.
84-
DebugKeyGovet = "govet" // Debugs `govet` linter.
85-
DebugKeyLinter = "linter"
86-
DebugKeyRevive = "revive" // Debugs `revive` linter.
82+
DebugKeyForbidigo = "forbidigo" // Debugs `forbidigo` linter.
83+
DebugKeyGoCritic = "gocritic" // Debugs `gocritic` linter.
84+
DebugKeyGovet = "govet" // Debugs `govet` linter.
85+
DebugKeyLinter = "linter"
86+
DebugKeyRevive = "revive" // Debugs `revive` linter.
87+
DebugKeyStaticcheck = "staticcheck" // Debugs `staticcheck` linter.
8788
)
8889

8990
func getEnabledDebugs() map[string]bool {

0 commit comments

Comments
 (0)