dev: clean up command contructors (#4478)
This commit is contained in:
parent
6fda81008d
commit
05f27abc01
pkg
@ -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,
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user