Skip to content

Commit 4fea092

Browse files
authored
dev: add GL_DEBUG=govet to see enabled analyzers (#4465)
1 parent 6628d21 commit 4fea092

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

.golangci.reference.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ linters-settings:
11001100
# stdmethods, stringintconv, structtag, testinggoroutine, tests, timeformat, unmarshal, unreachable, unsafeptr,
11011101
# unusedresult
11021102
# ).
1103-
# Run `go tool vet help` to see all analyzers.
1103+
# Run `GL_DEBUG=govet golangci-lint run --enable=govet` to see default, all available analyzers, and enabled analyzers.
11041104
# Default: []
11051105
enable:
11061106
- appends
@@ -1152,7 +1152,7 @@ linters-settings:
11521152
# atomicalign, deepequalerrors, fieldalignment, findcall, nilness, reflectvaluecompare, shadow, sortslice,
11531153
# timeformat, unusedwrite
11541154
# ).
1155-
# Run `go tool vet help` to see all analyzers.
1155+
# Run `GL_DEBUG=govet golangci-lint run --enable=govet` to see default, all available analyzers, and enabled analyzers.
11561156
# Default: []
11571157
disable:
11581158
- appends

pkg/golinters/govet.go

+27
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package golinters
22

33
import (
44
"slices"
5+
"sort"
56

67
"golang.org/x/tools/go/analysis"
78
"golang.org/x/tools/go/analysis/passes/appends"
@@ -52,6 +53,7 @@ import (
5253

5354
"github.com/golangci/golangci-lint/pkg/config"
5455
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
56+
"github.com/golangci/golangci-lint/pkg/logutils"
5557
)
5658

5759
var (
@@ -136,6 +138,11 @@ var (
136138
}
137139
)
138140

141+
var (
142+
govetDebugf = logutils.Debug(logutils.DebugKeyGovet)
143+
isGovetDebug = logutils.HaveDebugTag(logutils.DebugKeyGovet)
144+
)
145+
139146
func NewGovet(settings *config.GovetSettings) *goanalysis.Linter {
140147
var conf map[string]map[string]any
141148
if settings != nil {
@@ -152,6 +159,9 @@ func NewGovet(settings *config.GovetSettings) *goanalysis.Linter {
152159
}
153160

154161
func analyzersFromConfig(settings *config.GovetSettings) []*analysis.Analyzer {
162+
debugAnalyzersListf(allAnalyzers, "All available analyzers")
163+
debugAnalyzersListf(defaultAnalyzers, "Default analyzers")
164+
155165
if settings == nil {
156166
return defaultAnalyzers
157167
}
@@ -168,6 +178,8 @@ func analyzersFromConfig(settings *config.GovetSettings) []*analysis.Analyzer {
168178
}
169179
}
170180

181+
debugAnalyzersListf(enabledAnalyzers, "Enabled by config analyzers")
182+
171183
return enabledAnalyzers
172184
}
173185

@@ -194,3 +206,18 @@ func isAnalyzerEnabled(name string, cfg *config.GovetSettings, defaultAnalyzers
194206
return slices.ContainsFunc(defaultAnalyzers, func(a *analysis.Analyzer) bool { return a.Name == name })
195207
}
196208
}
209+
210+
func debugAnalyzersListf(analyzers []*analysis.Analyzer, message string) {
211+
if !isGovetDebug {
212+
return
213+
}
214+
215+
analyzerNames := make([]string, 0, len(analyzers))
216+
for _, a := range analyzers {
217+
analyzerNames = append(analyzerNames, a.Name)
218+
}
219+
220+
sort.Strings(analyzerNames)
221+
222+
govetDebugf("%s (%d): %s", message, len(analyzerNames), analyzerNames)
223+
}

pkg/logutils/logutils.go

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const (
5757

5858
const (
5959
DebugKeyGoCritic = "gocritic" // Debugs `go-critic` linter.
60+
DebugKeyGovet = "govet" // Debugs `govet` linter.
6061
DebugKeyMegacheck = "megacheck" // Debugs `staticcheck` related linters.
6162
DebugKeyNolint = "nolint" // Debugs a filter excluding issues by `//nolint` comments.
6263
DebugKeyRevive = "revive" // Debugs `revive` linter.

0 commit comments

Comments
 (0)