diff --git a/pkg/commands/fmt.go b/pkg/commands/fmt.go index cb7472847f25..66ba197f05f6 100644 --- a/pkg/commands/fmt.go +++ b/pkg/commands/fmt.go @@ -89,6 +89,10 @@ func (c *fmtCommand) persistentPreRunE(cmd *cobra.Command, args []string) error } func (c *fmtCommand) preRunE(_ *cobra.Command, _ []string) error { + if c.cfg.GetConfigDir() != "" && c.cfg.Version != "2" { + return fmt.Errorf("invalid version of the configuration: %q", c.cfg.Version) + } + metaFormatter, err := goformatters.NewMetaFormatter(c.log, &c.cfg.Formatters, &c.cfg.Run) if err != nil { return fmt.Errorf("failed to create meta-formatter: %w", err) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 76735afe9384..20ff2df9a0d3 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -185,6 +185,10 @@ func (c *runCommand) persistentPostRunE(_ *cobra.Command, _ []string) error { } func (c *runCommand) preRunE(_ *cobra.Command, args []string) error { + if c.cfg.GetConfigDir() != "" && c.cfg.Version != "2" { + return fmt.Errorf("invalid version of the configuration: %q", c.cfg.Version) + } + dbManager, err := lintersdb.NewManager(c.log.Child(logutils.DebugKeyLintersDB), c.cfg, lintersdb.NewLinterBuilder(), lintersdb.NewPluginModuleBuilder(c.log), lintersdb.NewPluginGoBuilder(c.log)) if err != nil { diff --git a/test/run_test.go b/test/run_test.go index 67344d9d82c0..5267764fbb39 100644 --- a/test/run_test.go +++ b/test/run_test.go @@ -30,10 +30,11 @@ func TestAutogeneratedNoIssues(t *testing.T) { binPath := testshared.InstallGolangciLint(t) cfg := ` - linters: - exclusions: - generated: lax - ` +version: "2" +linters: + exclusions: + generated: lax +` testshared.NewRunnerBuilder(t). WithConfig(cfg). @@ -96,9 +97,10 @@ func TestTimeoutInConfig(t *testing.T) { binPath := testshared.InstallGolangciLint(t) cfg := ` - run: - timeout: 1ms - ` +version: "2" +run: + timeout: 1ms +` // Run with disallowed option set only in config testshared.NewRunnerBuilder(t). @@ -331,11 +333,12 @@ func TestUnsafeOk(t *testing.T) { binPath := testshared.InstallGolangciLint(t) cfg := ` - linters: - exclusions: - presets: - - common-false-positives - ` +version: "2" +linters: + exclusions: + presets: + - common-false-positives +` testshared.NewRunnerBuilder(t). WithConfig(cfg).