Skip to content
This repository has been archived by the owner on Apr 10, 2019. It is now read-only.

Improve error message in the case of an unknown linter #370

Merged
merged 3 commits into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions linters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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<path>.*?\.go):(?P<line>\d+):(?P<col>\d+):\s*(?P<message>.*))|(?:(?P<path>.*?\.go):(?P<line>\d+):\s*(?P<message>.*))$`

var defaultLinters = map[string]LinterConfig{
Expand Down
18 changes: 18 additions & 0 deletions linters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down