diff --git a/linters.go b/linters.go index 56d7c05c..c523b17e 100644 --- a/linters.go +++ b/linters.go @@ -182,6 +182,21 @@ func defaultEnabled() []string { return enabled } +func validateLinters(linters map[string]*Linter, config *Config) error { + var unknownLinters []string + for name := range linters { + if _, isDefault := defaultLinters[name]; !isDefault { + if _, isCustom := config.Linters[name]; !isCustom { + unknownLinters = append(unknownLinters, name) + } + } + } + if len(unknownLinters) > 0 { + return fmt.Errorf("unknown linters: %s", strings.Join(unknownLinters, ", ")) + } + return nil +} + const vetPattern = `^(?:vet:.*?\.go:\s+(?P.*?\.go):(?P\d+):(?P\d+):\s*(?P.*))|(?:(?P.*?\.go):(?P\d+):\s*(?P.*))$` var defaultLinters = map[string]LinterConfig{ diff --git a/linters_test.go b/linters_test.go index 9188187e..bf706cd5 100644 --- a/linters_test.go +++ b/linters_test.go @@ -35,6 +35,24 @@ func TestGetLinterByName(t *testing.T) { assert.Equal(t, config.IsFast, overrideConfig.IsFast) } +func TestValidateLinters(t *testing.T) { + originalConfig := *config + defer func() { config = &originalConfig }() + + config = &Config{ + Enable: []string{"_dummylinter_"}, + } + + err := validateLinters(lintersFromConfig(config), config) + require.Error(t, err, "expected unknown linter error for _dummylinter_") + + config = &Config{ + Enable: defaultEnabled(), + } + err = validateLinters(lintersFromConfig(config), config) + require.NoError(t, err) +} + func functionName(i interface{}) string { return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name() } diff --git a/main.go b/main.go index 4e4fa81c..4770d95d 100644 --- a/main.go +++ b/main.go @@ -201,6 +201,9 @@ Severity override map (default is "warning"): paths := resolvePaths(*pathsArg, config.Skip) linters := lintersFromConfig(config) + err := validateLinters(linters, config) + kingpin.FatalIfError(err, "") + issues, errch := runLinters(linters, paths, config.Concurrency, exclude, include) status := 0 if config.JSON {