Skip to content

Commit 581a356

Browse files
committed
Allow --enable, --enable-all and --fast to coexist.
This is useful to first enable all linters (including fast ones), then only enable fast linters, then add extra linters. eg. ``` golangci-lint run --no-config --enable-all --fast --print-issued-lines=false \ --exclude-use-default=false --tests --enable typecheck . ```
1 parent 9ed7dad commit 581a356

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

pkg/lint/lintersdb/lintersdb.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func validateAllDisableEnableOptions(cfg *config.Linters) error {
256256
}
257257
}
258258

259-
if cfg.EnableAll && len(cfg.Enable) != 0 {
259+
if cfg.EnableAll && len(cfg.Enable) != 0 && !cfg.Fast {
260260
return fmt.Errorf("can't combine options --enable-all and --enable %s", cfg.Enable[0])
261261
}
262262

test/run_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,19 @@ func getEnabledByDefaultFastLintersExcept(except ...string) []string {
139139
return ret
140140
}
141141

142+
func getAllFastLintersWith(with ...string) []string {
143+
linters := lintersdb.GetAllSupportedLinterConfigs()
144+
ret := append([]string{}, with...)
145+
for _, linter := range linters {
146+
if linter.DoesFullImport {
147+
continue
148+
}
149+
ret = append(ret, linter.Linter.Name())
150+
}
151+
152+
return ret
153+
}
154+
142155
func getEnabledByDefaultLinters() []string {
143156
ebdl := lintersdb.GetAllEnabledByDefaultLinters()
144157
ret := []string{}
@@ -180,6 +193,15 @@ func mergeMegacheck(linters []string) []string {
180193
return linters
181194
}
182195

196+
func TestEnableAllFastAndEnableCanCoexist(t *testing.T) {
197+
out, exitCode := runGolangciLint(t, "--fast", "--enable-all", "--enable=typecheck")
198+
checkNoIssuesRun(t, out, exitCode)
199+
200+
_, exitCode = runGolangciLint(t, "--enable-all", "--enable=typecheck")
201+
assert.Equal(t, 3, exitCode)
202+
203+
}
204+
183205
func TestEnabledLinters(t *testing.T) {
184206
type tc struct {
185207
name string
@@ -267,6 +289,12 @@ func TestEnabledLinters(t *testing.T) {
267289
el: getEnabledByDefaultLinters(),
268290
noImplicitFast: true,
269291
},
292+
{
293+
name: "fast option combined with enable and enable-all",
294+
args: "--enable-all --fast --enable=typecheck",
295+
el: getAllFastLintersWith("typecheck"),
296+
noImplicitFast: true,
297+
},
270298
}
271299

272300
for _, c := range cases {

0 commit comments

Comments
 (0)