Merge pull request #79 from alecthomas/master

Allow --enable, --enable-all and --fast to coexist.
This commit is contained in:
Isaev Denis 2018-06-09 17:29:33 +03:00 committed by GitHub
commit 616bc37d6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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]) 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 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 { func getEnabledByDefaultLinters() []string {
ebdl := lintersdb.GetAllEnabledByDefaultLinters() ebdl := lintersdb.GetAllEnabledByDefaultLinters()
ret := []string{} ret := []string{}
@ -180,6 +193,15 @@ func mergeMegacheck(linters []string) []string {
return linters 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) { func TestEnabledLinters(t *testing.T) {
type tc struct { type tc struct {
name string name string
@ -267,6 +289,12 @@ func TestEnabledLinters(t *testing.T) {
el: getEnabledByDefaultLinters(), el: getEnabledByDefaultLinters(),
noImplicitFast: true, 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 { for _, c := range cases {