Skip to content

Commit 05f27ab

Browse files
authored
dev: clean up command contructors (#4478)
1 parent 6fda810 commit 05f27ab

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

pkg/commands/linters.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ type lintersCommand struct {
3030
dbManager *lintersdb.Manager
3131
}
3232

33-
func newLintersCommand(logger logutils.Log, cfg *config.Config) *lintersCommand {
33+
func newLintersCommand(logger logutils.Log) *lintersCommand {
3434
c := &lintersCommand{
3535
viper: viper.New(),
36-
cfg: cfg,
36+
cfg: config.NewDefault(),
3737
log: logger,
3838
}
3939

pkg/commands/root.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import (
1010
"github.com/spf13/cobra"
1111
"github.com/spf13/pflag"
1212

13-
"github.com/golangci/golangci-lint/pkg/config"
1413
"github.com/golangci/golangci-lint/pkg/logutils"
15-
"github.com/golangci/golangci-lint/pkg/report"
1614
)
1715

1816
func Execute(info BuildInfo) error {
@@ -56,13 +54,12 @@ func newRootCommand(info BuildInfo) *rootCommand {
5654

5755
setupRootPersistentFlags(rootCmd.PersistentFlags(), &c.opts)
5856

59-
reportData := &report.Data{}
60-
log := report.NewLogWrapper(logutils.NewStderrLog(logutils.DebugKeyEmpty), reportData)
57+
log := logutils.NewStderrLog(logutils.DebugKeyEmpty)
6158

62-
// Dedicated configuration for each command to avoid side effects of bindings.
59+
// Each command uses a dedicated configuration structure to avoid side effects of bindings.
6360
rootCmd.AddCommand(
64-
newLintersCommand(log, config.NewDefault()).cmd,
65-
newRunCommand(log, config.NewDefault(), reportData, info).cmd,
61+
newLintersCommand(log).cmd,
62+
newRunCommand(log, info).cmd,
6663
newCacheCommand().cmd,
6764
newConfigCommand(log).cmd,
6865
newVersionCommand(info).cmd,

pkg/commands/run.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,14 @@ type runCommand struct {
9898
exitCode int
9999
}
100100

101-
func newRunCommand(logger logutils.Log, cfg *config.Config, reportData *report.Data, info BuildInfo) *runCommand {
101+
func newRunCommand(logger logutils.Log, info BuildInfo) *runCommand {
102+
reportData := &report.Data{}
103+
102104
c := &runCommand{
103105
viper: viper.New(),
104-
log: logger,
106+
log: report.NewLogWrapper(logger, reportData),
105107
debugf: logutils.Debug(logutils.DebugKeyExec),
106-
cfg: cfg,
108+
cfg: config.NewDefault(),
107109
reportData: reportData,
108110
buildInfo: info,
109111
}
@@ -126,7 +128,7 @@ func newRunCommand(logger logutils.Log, cfg *config.Config, reportData *report.D
126128

127129
// Only for testing purpose.
128130
// Don't add other flags here.
129-
fs.BoolVar(&cfg.InternalCmdTest, "internal-cmd-test", false,
131+
fs.BoolVar(&c.cfg.InternalCmdTest, "internal-cmd-test", false,
130132
color.GreenString("Option is used only for testing golangci-lint command, don't use it"))
131133
_ = fs.MarkHidden("internal-cmd-test")
132134

pkg/printers/json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
type JSON struct {
12-
rd *report.Data
12+
rd *report.Data // TODO(ldez) should be drop in v2. Only use by JSON reporter.
1313
w io.Writer
1414
}
1515

pkg/result/processors/severity_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import (
99

1010
"github.com/golangci/golangci-lint/pkg/fsutils"
1111
"github.com/golangci/golangci-lint/pkg/logutils"
12-
"github.com/golangci/golangci-lint/pkg/report"
1312
"github.com/golangci/golangci-lint/pkg/result"
1413
)
1514

1615
func TestSeverity_multiple(t *testing.T) {
1716
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
1817
files := fsutils.NewFiles(lineCache, "")
19-
log := report.NewLogWrapper(logutils.NewStderrLog(logutils.DebugKeyEmpty), &report.Data{})
18+
log := logutils.NewStderrLog(logutils.DebugKeyEmpty)
2019

2120
opts := SeverityOptions{
2221
Default: "error",
@@ -132,7 +131,7 @@ func TestSeverity_pathPrefix(t *testing.T) {
132131
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
133132
pathPrefix := path.Join("some", "dir")
134133
files := fsutils.NewFiles(lineCache, pathPrefix)
135-
log := report.NewLogWrapper(logutils.NewStderrLog(logutils.DebugKeyEmpty), &report.Data{})
134+
log := logutils.NewStderrLog(logutils.DebugKeyEmpty)
136135

137136
opts := SeverityOptions{
138137
Default: "error",
@@ -217,7 +216,7 @@ func TestSeverity_text(t *testing.T) {
217216
func TestSeverity_onlyDefault(t *testing.T) {
218217
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
219218
files := fsutils.NewFiles(lineCache, "")
220-
log := report.NewLogWrapper(logutils.NewStderrLog(logutils.DebugKeyEmpty), &report.Data{})
219+
log := logutils.NewStderrLog(logutils.DebugKeyEmpty)
221220

222221
opts := SeverityOptions{
223222
Default: "info",

0 commit comments

Comments
 (0)