Skip to content

Commit

Permalink
dev: add GL_DEBUG=govet to see enabled analyzers (#4465)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored Mar 7, 2024
1 parent 6628d21 commit 4fea092
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
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

0 comments on commit 4fea092

Please sign in to comment.