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 .
```
This commit is contained in:
Alec Thomas 2018-06-09 13:31:00 +10:00
parent 9ed7dad894
commit 581a3564ff
2 changed files with 29 additions and 1 deletions

View File

@ -256,7 +256,7 @@ func validateAllDisableEnableOptions(cfg *config.Linters) error {
}
}
if cfg.EnableAll && len(cfg.Enable) != 0 {
if cfg.EnableAll && len(cfg.Enable) != 0 && !cfg.Fast {
return fmt.Errorf("can't combine options --enable-all and --enable %s", cfg.Enable[0])
}

View File

@ -139,6 +139,19 @@ func getEnabledByDefaultFastLintersExcept(except ...string) []string {
return ret
}
func getAllFastLintersWith(with ...string) []string {
linters := lintersdb.GetAllSupportedLinterConfigs()
ret := append([]string{}, with...)
for _, linter := range linters {
if linter.DoesFullImport {
continue
}
ret = append(ret, linter.Linter.Name())
}
return ret
}
func getEnabledByDefaultLinters() []string {
ebdl := lintersdb.GetAllEnabledByDefaultLinters()
ret := []string{}
@ -180,6 +193,15 @@ func mergeMegacheck(linters []string) []string {
return linters
}
func TestEnableAllFastAndEnableCanCoexist(t *testing.T) {
out, exitCode := runGolangciLint(t, "--fast", "--enable-all", "--enable=typecheck")
checkNoIssuesRun(t, out, exitCode)
_, exitCode = runGolangciLint(t, "--enable-all", "--enable=typecheck")
assert.Equal(t, 3, exitCode)
}
func TestEnabledLinters(t *testing.T) {
type tc struct {
name string
@ -267,6 +289,12 @@ func TestEnabledLinters(t *testing.T) {
el: getEnabledByDefaultLinters(),
noImplicitFast: true,
},
{
name: "fast option combined with enable and enable-all",
args: "--enable-all --fast --enable=typecheck",
el: getAllFastLintersWith("typecheck"),
noImplicitFast: true,
},
}
for _, c := range cases {