dev: add GL_DEBUG=govet to see enabled analyzers (#4465)

This commit is contained in:
Oleksandr Redko 2024-03-07 16:23:42 +02:00 committed by GitHub
parent 6628d211b3
commit 4fea092fa2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 2 deletions

View File

@ -1100,7 +1100,7 @@ linters-settings:
# stdmethods, stringintconv, structtag, testinggoroutine, tests, timeformat, unmarshal, unreachable, unsafeptr,
# unusedresult
# ).
# Run `go tool vet help` to see all analyzers.
# Run `GL_DEBUG=govet golangci-lint run --enable=govet` to see default, all available analyzers, and enabled analyzers.
# Default: []
enable:
- appends
@ -1152,7 +1152,7 @@ linters-settings:
# atomicalign, deepequalerrors, fieldalignment, findcall, nilness, reflectvaluecompare, shadow, sortslice,
# timeformat, unusedwrite
# ).
# Run `go tool vet help` to see all analyzers.
# Run `GL_DEBUG=govet golangci-lint run --enable=govet` to see default, all available analyzers, and enabled analyzers.
# Default: []
disable:
- appends

View File

@ -2,6 +2,7 @@ package golinters
import (
"slices"
"sort"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/appends"
@ -52,6 +53,7 @@ import (
"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
"github.com/golangci/golangci-lint/pkg/logutils"
)
var (
@ -136,6 +138,11 @@ var (
}
)
var (
govetDebugf = logutils.Debug(logutils.DebugKeyGovet)
isGovetDebug = logutils.HaveDebugTag(logutils.DebugKeyGovet)
)
func NewGovet(settings *config.GovetSettings) *goanalysis.Linter {
var conf map[string]map[string]any
if settings != nil {
@ -152,6 +159,9 @@ func NewGovet(settings *config.GovetSettings) *goanalysis.Linter {
}
func analyzersFromConfig(settings *config.GovetSettings) []*analysis.Analyzer {
debugAnalyzersListf(allAnalyzers, "All available analyzers")
debugAnalyzersListf(defaultAnalyzers, "Default analyzers")
if settings == nil {
return defaultAnalyzers
}
@ -168,6 +178,8 @@ func analyzersFromConfig(settings *config.GovetSettings) []*analysis.Analyzer {
}
}
debugAnalyzersListf(enabledAnalyzers, "Enabled by config analyzers")
return enabledAnalyzers
}
@ -194,3 +206,18 @@ func isAnalyzerEnabled(name string, cfg *config.GovetSettings, defaultAnalyzers
return slices.ContainsFunc(defaultAnalyzers, func(a *analysis.Analyzer) bool { return a.Name == name })
}
}
func debugAnalyzersListf(analyzers []*analysis.Analyzer, message string) {
if !isGovetDebug {
return
}
analyzerNames := make([]string, 0, len(analyzers))
for _, a := range analyzers {
analyzerNames = append(analyzerNames, a.Name)
}
sort.Strings(analyzerNames)
govetDebugf("%s (%d): %s", message, len(analyzerNames), analyzerNames)
}

View File

@ -57,6 +57,7 @@ const (
const (
DebugKeyGoCritic = "gocritic" // Debugs `go-critic` linter.
DebugKeyGovet = "govet" // Debugs `govet` linter.
DebugKeyMegacheck = "megacheck" // Debugs `staticcheck` related linters.
DebugKeyNolint = "nolint" // Debugs a filter excluding issues by `//nolint` comments.
DebugKeyRevive = "revive" // Debugs `revive` linter.