Skip to content

Commit debc0a3

Browse files
committed
fix: custom linters are enable by default
1 parent d147d8b commit debc0a3

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

pkg/commands/executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func NewExecutor(buildInfo BuildInfo) *Executor {
120120
}
121121

122122
// recreate after getting config
123-
e.DBManager = lintersdb.NewManager(e.cfg, e.log).WithCustomLinters()
123+
e.DBManager = lintersdb.NewManager(e.cfg, e.log)
124124

125125
// Slice options must be explicitly set for proper merging of config and command-line options.
126126
fixSlicesFlags(e.runCmd.Flags())

pkg/lint/lintersdb/custom_linters.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,30 @@ import (
1212
"github.com/golangci/golangci-lint/pkg/config"
1313
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
1414
"github.com/golangci/golangci-lint/pkg/lint/linter"
15-
"github.com/golangci/golangci-lint/pkg/logutils"
16-
"github.com/golangci/golangci-lint/pkg/report"
1715
)
1816

1917
type AnalyzerPlugin interface {
2018
GetAnalyzers() []*analysis.Analyzer
2119
}
2220

23-
// WithCustomLinters loads private linters that are specified in the golangci config file.
24-
func (m *Manager) WithCustomLinters() *Manager {
25-
if m.log == nil {
26-
m.log = report.NewLogWrapper(logutils.NewStderrLog(logutils.DebugKeyEmpty), &report.Data{})
21+
// getCustomLinterConfigs loads private linters that are specified in the golangci config file.
22+
func (m *Manager) getCustomLinterConfigs() []*linter.Config {
23+
if m.cfg == nil || m.log == nil {
24+
return nil
2725
}
2826

29-
if m.cfg == nil {
30-
return m
31-
}
27+
var linters []*linter.Config
3228

3329
for name, settings := range m.cfg.LintersSettings.Custom {
3430
lc, err := m.loadCustomLinterConfig(name, settings)
35-
3631
if err != nil {
3732
m.log.Errorf("Unable to load custom analyzer %s:%s, %v", name, settings.Path, err)
3833
} else {
39-
m.nameToLCs[name] = append(m.nameToLCs[name], lc)
34+
linters = append(linters, lc)
4035
}
4136
}
4237

43-
return m
38+
return linters
4439
}
4540

4641
// loadCustomLinterConfig loads the configuration of private linters.

pkg/lint/lintersdb/manager.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ import (
88
)
99

1010
type Manager struct {
11-
nameToLCs map[string][]*linter.Config
12-
cfg *config.Config
13-
log logutils.Log
11+
cfg *config.Config
12+
log logutils.Log
13+
14+
nameToLCs map[string][]*linter.Config
15+
customLinters []*linter.Config
1416
}
1517

1618
func NewManager(cfg *config.Config, log logutils.Log) *Manager {
1719
m := &Manager{cfg: cfg, log: log}
20+
m.customLinters = m.getCustomLinterConfigs()
1821

1922
nameToLCs := make(map[string][]*linter.Config)
2023
for _, lc := range m.GetAllSupportedLinterConfigs() {
@@ -247,9 +250,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
247250

248251
const megacheckName = "megacheck"
249252

253+
var linters []*linter.Config
254+
linters = append(linters, m.customLinters...)
255+
250256
// The linters are sorted in the alphabetical order (case-insensitive).
251257
// When a new linter is added the version in `WithSince(...)` must be the next minor version of golangci-lint.
252-
return []*linter.Config{
258+
linters = append(linters,
253259
linter.NewConfig(golinters.NewAsasalint(asasalintCfg)).
254260
WithSince("1.47.0").
255261
WithPresets(linter.PresetBugs).
@@ -878,7 +884,9 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
878884
WithPresets(linter.PresetBugs).
879885
WithLoadForGoAnalysis().
880886
WithURL("https://github.com/ykadowak/zerologlint"),
881-
}
887+
)
888+
889+
return linters
882890
}
883891

884892
func (m Manager) GetAllEnabledByDefaultLinters() []*linter.Config {

0 commit comments

Comments
 (0)