Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions pkg/golinters/govet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package golinters

import (
"slices"
"sort"

"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/appends"
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -168,6 +178,8 @@ func analyzersFromConfig(settings *config.GovetSettings) []*analysis.Analyzer {
}
}

debugAnalyzersListf(enabledAnalyzers, "Enabled by config analyzers")

return enabledAnalyzers
}

Expand All @@ -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)
}
1 change: 1 addition & 0 deletions pkg/logutils/logutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down