Skip to content

Commit a424bbe

Browse files
authored
feat: check version of the configuration (#5524)
1 parent e6059cb commit a424bbe

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

pkg/commands/fmt.go

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ func (c *fmtCommand) persistentPreRunE(cmd *cobra.Command, args []string) error
8989
}
9090

9191
func (c *fmtCommand) preRunE(_ *cobra.Command, _ []string) error {
92+
if c.cfg.GetConfigDir() != "" && c.cfg.Version != "2" {
93+
return fmt.Errorf("invalid version of the configuration: %q", c.cfg.Version)
94+
}
95+
9296
metaFormatter, err := goformatters.NewMetaFormatter(c.log, &c.cfg.Formatters, &c.cfg.Run)
9397
if err != nil {
9498
return fmt.Errorf("failed to create meta-formatter: %w", err)

pkg/commands/run.go

+4
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ func (c *runCommand) persistentPostRunE(_ *cobra.Command, _ []string) error {
185185
}
186186

187187
func (c *runCommand) preRunE(_ *cobra.Command, args []string) error {
188+
if c.cfg.GetConfigDir() != "" && c.cfg.Version != "2" {
189+
return fmt.Errorf("invalid version of the configuration: %q", c.cfg.Version)
190+
}
191+
188192
dbManager, err := lintersdb.NewManager(c.log.Child(logutils.DebugKeyLintersDB), c.cfg,
189193
lintersdb.NewLinterBuilder(), lintersdb.NewPluginModuleBuilder(c.log), lintersdb.NewPluginGoBuilder(c.log))
190194
if err != nil {

test/run_test.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ func TestAutogeneratedNoIssues(t *testing.T) {
3030
binPath := testshared.InstallGolangciLint(t)
3131

3232
cfg := `
33-
linters:
34-
exclusions:
35-
generated: lax
36-
`
33+
version: "2"
34+
linters:
35+
exclusions:
36+
generated: lax
37+
`
3738

3839
testshared.NewRunnerBuilder(t).
3940
WithConfig(cfg).
@@ -96,9 +97,10 @@ func TestTimeoutInConfig(t *testing.T) {
9697
binPath := testshared.InstallGolangciLint(t)
9798

9899
cfg := `
99-
run:
100-
timeout: 1ms
101-
`
100+
version: "2"
101+
run:
102+
timeout: 1ms
103+
`
102104

103105
// Run with disallowed option set only in config
104106
testshared.NewRunnerBuilder(t).
@@ -331,11 +333,12 @@ func TestUnsafeOk(t *testing.T) {
331333
binPath := testshared.InstallGolangciLint(t)
332334

333335
cfg := `
334-
linters:
335-
exclusions:
336-
presets:
337-
- common-false-positives
338-
`
336+
version: "2"
337+
linters:
338+
exclusions:
339+
presets:
340+
- common-false-positives
341+
`
339342

340343
testshared.NewRunnerBuilder(t).
341344
WithConfig(cfg).

0 commit comments

Comments
 (0)