Skip to content

feat: Include custom linters in enable-all #3085

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

Closed
wants to merge 2 commits into from
Closed
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
19 changes: 14 additions & 5 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (
)

type Manager struct {
nameToLCs map[string][]*linter.Config
cfg *config.Config
log logutils.Log
nameToLCs map[string][]*linter.Config
nameToCustomLCs map[string][]*linter.Config
cfg *config.Config
log logutils.Log
}

func NewManager(cfg *config.Config, log logutils.Log) *Manager {
Expand All @@ -37,6 +38,7 @@ func NewManager(cfg *config.Config, log logutils.Log) *Manager {

// WithCustomLinters loads private linters that are specified in the golangci config file.
func (m *Manager) WithCustomLinters() *Manager {
nameToCustomLCs := make(map[string][]*linter.Config)
if m.log == nil {
m.log = report.NewLogWrapper(logutils.NewStderrLog(""), &report.Data{})
}
Expand All @@ -50,10 +52,11 @@ func (m *Manager) WithCustomLinters() *Manager {
settings.Path,
err)
} else {
m.nameToLCs[name] = append(m.nameToLCs[name], lc)
nameToCustomLCs[name] = append(nameToCustomLCs[name], lc)
}
}
}
m.nameToCustomLCs = nameToCustomLCs
return m
}

Expand Down Expand Up @@ -84,7 +87,10 @@ func (m Manager) allPresetsSet() map[string]bool {
}

func (m Manager) GetLinterConfigs(name string) []*linter.Config {
return m.nameToLCs[name]
if v, ok := m.nameToLCs[name]; ok {
return v
}
return m.nameToCustomLCs[name]
}

func enableLinterConfigs(lcs []*linter.Config, isEnabled func(lc *linter.Config) bool) []*linter.Config {
Expand Down Expand Up @@ -817,6 +823,9 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithPresets(linter.PresetStyle).
WithURL("https://github.com/golangci/golangci-lint/blob/master/pkg/golinters/nolintlint/README.md"),
}
for _, configs := range m.nameToCustomLCs {
lcs = append(lcs, configs...)
}

enabledByDefault := map[string]bool{
golinters.NewGovet(nil).Name(): true,
Expand Down