diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 6ae7f3bf71bd..7faa00161fdb 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -185,10 +185,6 @@ 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/pkg/config/loader.go b/pkg/config/loader.go index f3c87af07ebc..deace8ff0b17 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -60,6 +60,11 @@ func (l *Loader) Load(opts LoadOptions) error { l.cfg.Linters.Exclusions.Generated = GeneratedModeStrict } + err = l.checkConfigurationVersion() + if err != nil { + return err + } + if !l.cfg.InternalCmdTest { for _, n := range slices.Concat(l.cfg.Linters.Enable, l.cfg.Linters.Disable) { if n == "typecheck" { @@ -127,6 +132,15 @@ func (l *Loader) appendStringSlice(name string, current *[]string) { } } +func (l *Loader) checkConfigurationVersion() error { + if l.cfg.GetConfigDir() != "" && l.cfg.Version != "2" { + return fmt.Errorf("unsupported version of the configuration: %q "+ + "See https://golangci-lint.run/product/migration-guide for migration instructions", l.cfg.Version) + } + + return nil +} + func (l *Loader) handleGoVersion() { if l.cfg.Run.Go == "" { l.cfg.Run.Go = detectGoVersion(context.Background()) diff --git a/test/enabled_linters_test.go b/test/enabled_linters_test.go index 70ad679b400b..908b8f282490 100644 --- a/test/enabled_linters_test.go +++ b/test/enabled_linters_test.go @@ -28,18 +28,20 @@ func TestEnabledLinters(t *testing.T) { { name: "disable govet in config", cfg: ` - linters: - disable: - - govet +version: "2" +linters: + disable: + - govet `, enabledLinters: getEnabledByDefaultLintersExcept(t, "govet"), }, { name: "enable revive in config", cfg: ` - linters: - enable: - - revive +version: "2" +linters: + enable: + - revive `, enabledLinters: getEnabledByDefaultLintersWith(t, "revive"), }, @@ -52,17 +54,19 @@ func TestEnabledLinters(t *testing.T) { name: "enable revive in cmd and enable gofmt in config", args: []string{"-Erevive"}, cfg: ` - formatters: - enable: - - gofmt +version: "2" +formatters: + enable: + - gofmt `, enabledLinters: getEnabledByDefaultLintersWith(t, "revive", "gofmt"), }, { name: "fast option in config", cfg: ` - linters: - default: fast +version: "2" +linters: + default: fast `, enabledLinters: getAllLintersFromGroupFast(t), }, @@ -74,8 +78,9 @@ func TestEnabledLinters(t *testing.T) { { name: "fast option in command-line has higher priority to enable", cfg: ` - linters: - default: none +version: "2" +linters: + default: none `, args: []string{"--default=fast"}, enabledLinters: getAllLintersFromGroupFast(t),