Skip to content

Commit 7024fff

Browse files
authored
fix: emit an error when no linters enabled (#6323)
1 parent 7bcbbbf commit 7024fff

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

pkg/lint/runner.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ func NewRunner(log logutils.Log, cfg *config.Config, goenv *goutil.Env,
5959
}
6060
}
6161

62+
switch len(enabledLinters) {
63+
case 0:
64+
return nil, errors.New("no linters enabled")
65+
case 1:
66+
if _, ok := enabledLinters["typecheck"]; ok {
67+
return nil, errors.New("no linters enabled")
68+
}
69+
}
70+
6271
formattersCfg := &config.Formatters{
6372
Enable: enabledFormatters,
6473
Settings: cfg.Linters.Settings.FormatterSettings,

test/run_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ func TestNotExistingDirRun(t *testing.T) {
7070
ExpectOutputContains(testshared.NormalizeFileInString("/testdata/no_such_dir"))
7171
}
7272

73+
func TestNoLintersEnabled(t *testing.T) {
74+
cfg := `
75+
version: "2"
76+
linters:
77+
default: none
78+
enable: []
79+
`
80+
81+
testshared.NewRunnerBuilder(t).
82+
WithConfig(cfg).
83+
WithArgs("--show-stats=false").
84+
WithTargetPath(testdataDir, "autogenerated").
85+
Runner().
86+
Install().
87+
Run().
88+
ExpectOutputContains("Running error: no linters enabled")
89+
}
90+
7391
func TestSymlinkLoop(t *testing.T) {
7492
testshared.NewRunnerBuilder(t).
7593
WithArgs("--show-stats=false").

test/testdata/notcompiles/typecheck.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//golangcitest:args -Etypecheck
1+
//golangcitest:args -Emodernize
2+
//golangcitest:expected_linter typecheck
23
package testdata
34

45
fun NotCompiles() { // want "expected declaration, found.* fun"

test/testdata/notcompiles/typecheck_many_issues.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//go:build go1.20
22

3-
//golangcitest:args -Etypecheck
3+
//golangcitest:args -Emodernize
4+
//golangcitest:expected_linter typecheck
45
package testdata
56

67
func TypeCheckBadCalls() {

0 commit comments

Comments
 (0)