Richard van der Hoff 8fff0e887c Update gometalinter config (#331)
* Update gometalinter config

gometalinter now uses `maligned` instead of `aligncheck`
(https://github.com/alecthomas/gometalinter/pull/367), so we need to update our
config accordingly.

* Update gometalinter

* Disable gotype linter

gotype does not seem to play nicely with the gb vendor directory. In
particular, it wants each of our dependencies to be built and installed (see
https://github.com/golang/go/issues/10969), but (empirically) it will not
accept them being installed in `pkg` but insists on them being in `vendor/pkg`.

This presents a problem because `gb build` builds the packages into `pkg`
(which doesn't seem entirely unreasonable since `.` comes before `vendor` in
`$GOPATH`). `go install github.com/x/y` does install in `vendor/pkg` but
requires us to know the name of each package.

The general conclusion of https://github.com/alecthomas/gometalinter/issues/91
seems to have been that the easiest thing to do is to disable `gotype` for now.

* Fix `unparam` lint

* Fix goshadow lint
2017-11-15 10:25:48 +00:00

62 lines
1.8 KiB
Go

package main
import (
"reflect"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewLinterWithCustomLinter(t *testing.T) {
config := LinterConfig{
Command: "/usr/bin/custom",
Pattern: "path",
}
linter, err := NewLinter("thename", config)
require.NoError(t, err)
assert.Equal(t, functionName(partitionPathsAsDirectories), functionName(linter.LinterConfig.PartitionStrategy))
assert.Equal(t, "(?m:path)", linter.regex.String())
assert.Equal(t, "thename", linter.Name)
assert.Equal(t, config.Command, linter.Command)
}
func TestGetLinterByName(t *testing.T) {
config := LinterConfig{
Command: "maligned",
Pattern: "path",
InstallFrom: "./install/path",
PartitionStrategy: partitionPathsAsDirectories,
IsFast: true,
}
overrideConfig := getLinterByName(config.Command, config)
assert.Equal(t, config.Command, overrideConfig.Command)
assert.Equal(t, config.Pattern, overrideConfig.Pattern)
assert.Equal(t, config.InstallFrom, overrideConfig.InstallFrom)
assert.Equal(t, functionName(config.PartitionStrategy), functionName(overrideConfig.PartitionStrategy))
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()
}