diff --git a/pkg/commands/linters.go b/pkg/commands/linters.go index 30d1958c..bd1057b5 100644 --- a/pkg/commands/linters.go +++ b/pkg/commands/linters.go @@ -30,10 +30,10 @@ type lintersCommand struct { dbManager *lintersdb.Manager } -func newLintersCommand(logger logutils.Log, cfg *config.Config) *lintersCommand { +func newLintersCommand(logger logutils.Log) *lintersCommand { c := &lintersCommand{ viper: viper.New(), - cfg: cfg, + cfg: config.NewDefault(), log: logger, } diff --git a/pkg/commands/root.go b/pkg/commands/root.go index 2a5e7cf1..de2710ca 100644 --- a/pkg/commands/root.go +++ b/pkg/commands/root.go @@ -10,9 +10,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/logutils" - "github.com/golangci/golangci-lint/pkg/report" ) func Execute(info BuildInfo) error { @@ -56,13 +54,12 @@ func newRootCommand(info BuildInfo) *rootCommand { setupRootPersistentFlags(rootCmd.PersistentFlags(), &c.opts) - reportData := &report.Data{} - log := report.NewLogWrapper(logutils.NewStderrLog(logutils.DebugKeyEmpty), reportData) + log := logutils.NewStderrLog(logutils.DebugKeyEmpty) - // Dedicated configuration for each command to avoid side effects of bindings. + // Each command uses a dedicated configuration structure to avoid side effects of bindings. rootCmd.AddCommand( - newLintersCommand(log, config.NewDefault()).cmd, - newRunCommand(log, config.NewDefault(), reportData, info).cmd, + newLintersCommand(log).cmd, + newRunCommand(log, info).cmd, newCacheCommand().cmd, newConfigCommand(log).cmd, newVersionCommand(info).cmd, diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 0b4501ef..bcf4c51c 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -98,12 +98,14 @@ type runCommand struct { exitCode int } -func newRunCommand(logger logutils.Log, cfg *config.Config, reportData *report.Data, info BuildInfo) *runCommand { +func newRunCommand(logger logutils.Log, info BuildInfo) *runCommand { + reportData := &report.Data{} + c := &runCommand{ viper: viper.New(), - log: logger, + log: report.NewLogWrapper(logger, reportData), debugf: logutils.Debug(logutils.DebugKeyExec), - cfg: cfg, + cfg: config.NewDefault(), reportData: reportData, buildInfo: info, } @@ -126,7 +128,7 @@ func newRunCommand(logger logutils.Log, cfg *config.Config, reportData *report.D // Only for testing purpose. // Don't add other flags here. - fs.BoolVar(&cfg.InternalCmdTest, "internal-cmd-test", false, + fs.BoolVar(&c.cfg.InternalCmdTest, "internal-cmd-test", false, color.GreenString("Option is used only for testing golangci-lint command, don't use it")) _ = fs.MarkHidden("internal-cmd-test") diff --git a/pkg/printers/json.go b/pkg/printers/json.go index 4bae526b..28509cac 100644 --- a/pkg/printers/json.go +++ b/pkg/printers/json.go @@ -9,7 +9,7 @@ import ( ) type JSON struct { - rd *report.Data + rd *report.Data // TODO(ldez) should be drop in v2. Only use by JSON reporter. w io.Writer } diff --git a/pkg/result/processors/severity_test.go b/pkg/result/processors/severity_test.go index 574387ed..9690b550 100644 --- a/pkg/result/processors/severity_test.go +++ b/pkg/result/processors/severity_test.go @@ -9,14 +9,13 @@ import ( "github.com/golangci/golangci-lint/pkg/fsutils" "github.com/golangci/golangci-lint/pkg/logutils" - "github.com/golangci/golangci-lint/pkg/report" "github.com/golangci/golangci-lint/pkg/result" ) func TestSeverity_multiple(t *testing.T) { lineCache := fsutils.NewLineCache(fsutils.NewFileCache()) files := fsutils.NewFiles(lineCache, "") - log := report.NewLogWrapper(logutils.NewStderrLog(logutils.DebugKeyEmpty), &report.Data{}) + log := logutils.NewStderrLog(logutils.DebugKeyEmpty) opts := SeverityOptions{ Default: "error", @@ -132,7 +131,7 @@ func TestSeverity_pathPrefix(t *testing.T) { lineCache := fsutils.NewLineCache(fsutils.NewFileCache()) pathPrefix := path.Join("some", "dir") files := fsutils.NewFiles(lineCache, pathPrefix) - log := report.NewLogWrapper(logutils.NewStderrLog(logutils.DebugKeyEmpty), &report.Data{}) + log := logutils.NewStderrLog(logutils.DebugKeyEmpty) opts := SeverityOptions{ Default: "error", @@ -217,7 +216,7 @@ func TestSeverity_text(t *testing.T) { func TestSeverity_onlyDefault(t *testing.T) { lineCache := fsutils.NewLineCache(fsutils.NewFileCache()) files := fsutils.NewFiles(lineCache, "") - log := report.NewLogWrapper(logutils.NewStderrLog(logutils.DebugKeyEmpty), &report.Data{}) + log := logutils.NewStderrLog(logutils.DebugKeyEmpty) opts := SeverityOptions{ Default: "info",