a86bda490b
The golangci-lint being used was quite dated. This change upgrades to the latest version. Adds and updates exclusions based on new failures. Note on revive: I've included an opt-out for unused parameters for revive because turning `newThing(required bool)` to `newThing(_ bool)` is a loss of useful information. The changes to the Go files are to fix the following issues: ``` camelcase.go:16: File is not `gofmt`-ed with `-s` (gofmt) config_test.go:50:18: directive `//nolint: gosec` is unused for linter "gosec" (nolintlint) defaults_test.go:28:25: G601: Implicit memory aliasing in for loop. (gosec) doc.go:5: File is not `gofmt`-ed with `-s` (gofmt) kong.go:446:18: directive `//nolint: gosec` is unused for linter "gosec" (nolintlint) kong_test.go:503:20: G601: Implicit memory aliasing in for loop. (gosec) model.go:493:10: composites: reflect.ValueError struct literal uses unkeyed fields (govet) scanner.go:112: File is not `gofmt`-ed with `-s` (gofmt) ``` And to address broken nolint directives reported as follows by golangci-lint. ``` [.. skipped .. ] tag.go:65:1: directive `// nolint:gocyclo` should be written without leading space as `//nolint:gocyclo` (nolintlint) tag.go:206:51: directive `// nolint: gocyclo` should be written without leading space as `//nolint: gocyclo` (nolintlint) util_test.go:23:43: directive `// nolint: errcheck` should be written without leading space as `//nolint: errcheck` (nolintlint) util_test.go:51:22: directive `// nolint: errcheck` should be written without leading space as `//nolint: errcheck` (nolintlint) ```
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package kong_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/alecthomas/assert/v2"
|
|
"github.com/alecthomas/kong"
|
|
)
|
|
|
|
func TestMultipleConfigLoading(t *testing.T) {
|
|
var cli struct {
|
|
Flag string `json:"flag,omitempty"`
|
|
}
|
|
|
|
cli.Flag = "first"
|
|
first, cleanFirst := makeConfig(t, &cli)
|
|
defer cleanFirst()
|
|
|
|
cli.Flag = ""
|
|
second, cleanSecond := makeConfig(t, &cli)
|
|
defer cleanSecond()
|
|
|
|
p := mustNew(t, &cli, kong.Configuration(kong.JSON, first, second))
|
|
_, err := p.Parse(nil)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, "first", cli.Flag)
|
|
}
|
|
|
|
func TestConfigValidation(t *testing.T) {
|
|
var cli struct {
|
|
Flag string `json:"flag,omitempty" enum:"valid" required:""`
|
|
}
|
|
|
|
cli.Flag = "invalid"
|
|
conf, cleanConf := makeConfig(t, &cli)
|
|
defer cleanConf()
|
|
|
|
p := mustNew(t, &cli, kong.Configuration(kong.JSON, conf))
|
|
_, err := p.Parse(nil)
|
|
assert.Error(t, err)
|
|
}
|
|
|
|
func makeConfig(t *testing.T, config interface{}) (path string, cleanup func()) {
|
|
t.Helper()
|
|
w, err := ioutil.TempFile("", "")
|
|
assert.NoError(t, err)
|
|
defer w.Close()
|
|
err = json.NewEncoder(w).Encode(config)
|
|
assert.NoError(t, err)
|
|
return w.Name(), func() { os.Remove(w.Name()) }
|
|
}
|