Hermitise and bump golangci-lint.

This commit is contained in:
Alec Thomas
2021-06-09 12:37:06 +10:00
parent c4a8cb03a7
commit 6cebaa7b85
23 changed files with 95 additions and 28 deletions
+21
View File
@@ -15,6 +15,25 @@ linters:
- gocognit - gocognit
- gomnd - gomnd
- goprintffuncname - goprintffuncname
- paralleltest
- nlreturn
- goerr113
- ifshort
- testpackage
- wrapcheck
- exhaustivestruct
- forbidigo
- gci
- godot
- gofumpt
- cyclop
- errorlint
- nestif
- golint
- scopelint
- interfacer
- tagliatelle
- thelper
linters-settings: linters-settings:
govet: govet:
@@ -26,6 +45,8 @@ linters-settings:
min-occurrences: 3 min-occurrences: 3
gocyclo: gocyclo:
min-complexity: 20 min-complexity: 20
exhaustive:
default-signifies-exhaustive: true
issues: issues:
max-per-linter: 0 max-per-linter: 0
+1
View File
@@ -0,0 +1 @@
hermit
+1
View File
@@ -0,0 +1 @@
hermit
+7
View File
@@ -0,0 +1,7 @@
# Hermit environment
This is a [Hermit](https://github.com/cashapp/hermit) bin directory.
The symlinks in this directory are managed by Hermit and will automatically
download and install Hermit itself as well as packages. These packages are
local to this environment.
+19
View File
@@ -0,0 +1,19 @@
#!/bin/bash
# This file must be used with "source bin/activate-hermit" from bash or zsh.
# You cannot run it directly
if [ "${BASH_SOURCE-}" = "$0" ]; then
echo "You must source this script: \$ source $0" >&2
exit 33
fi
BIN_DIR="$(dirname "${BASH_SOURCE[0]:-${(%):-%x}}")"
if "${BIN_DIR}/hermit" noop > /dev/null; then
eval "$("${BIN_DIR}/hermit" activate "${BIN_DIR}/..")"
if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ]; then
hash -r 2>/dev/null
fi
echo "Hermit environment $("${HERMIT_ENV}"/bin/hermit env HERMIT_ENV) activated"
fi
Symlink
+1
View File
@@ -0,0 +1 @@
.go@latest.pkg
Symlink
+1
View File
@@ -0,0 +1 @@
.go@latest.pkg
+1
View File
@@ -0,0 +1 @@
.golangci-lint-1.40.1.pkg
Executable
+26
View File
@@ -0,0 +1,26 @@
#!/bin/bash
set -eo pipefail
if [ -z "${HERMIT_STATE_DIR}" ]; then
case "$(uname -s)" in
Darwin)
export HERMIT_STATE_DIR="${HOME}/Library/Caches/hermit"
;;
Linux)
export HERMIT_STATE_DIR="${XDG_CACHE_HOME:-${HOME}/.cache}/hermit"
;;
esac
fi
export HERMIT_DIST_URL="${HERMIT_DIST_URL:-https://github.com/cashapp/hermit/releases/download/stable}"
HERMIT_CHANNEL="$(basename "${HERMIT_DIST_URL}")"
export HERMIT_CHANNEL
export HERMIT_EXE=${HERMIT_EXE:-${HERMIT_STATE_DIR}/pkg/hermit@${HERMIT_CHANNEL}/hermit}
if [ ! -x "${HERMIT_EXE}" ]; then
echo "Bootstrapping ${HERMIT_EXE} from ${HERMIT_DIST_URL}" 1>&2
curl -fsSL "${HERMIT_DIST_URL}/install.sh" | /bin/bash 1>&2
fi
exec "${HERMIT_EXE}" --level=fatal exec "$0" -- "$@"
View File
+3 -2
View File
@@ -6,8 +6,9 @@ import (
"os" "os"
"testing" "testing"
"github.com/alecthomas/kong"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/alecthomas/kong"
) )
func TestMultipleConfigLoading(t *testing.T) { func TestMultipleConfigLoading(t *testing.T) {
@@ -47,7 +48,7 @@ func makeConfig(t *testing.T, config interface{}) (path string, cleanup func())
t.Helper() t.Helper()
w, err := ioutil.TempFile("", "") w, err := ioutil.TempFile("", "")
require.NoError(t, err) require.NoError(t, err)
defer w.Close() defer w.Close() // nolint: gosec
err = json.NewEncoder(w).Encode(config) err = json.NewEncoder(w).Encode(config)
require.NoError(t, err) require.NoError(t, err)
return w.Name(), func() { os.Remove(w.Name()) } return w.Name(), func() { os.Remove(w.Name()) }
+1
View File
@@ -585,6 +585,7 @@ func (c *Context) getValue(value *Value) reflect.Value {
v.Set(reflect.MakeSlice(v.Type(), 0, 0)) v.Set(reflect.MakeSlice(v.Type(), 0, 0))
case reflect.Map: case reflect.Map:
v.Set(reflect.MakeMap(v.Type())) v.Set(reflect.MakeMap(v.Type()))
default:
} }
c.values[value] = v c.values[value] = v
} }
-1
View File
@@ -24,7 +24,6 @@ func TestApplyDefaults(t *testing.T) {
expected: CLI{Str: "str", Duration: time.Second}}, expected: CLI{Str: "str", Duration: time.Second}},
} }
for _, tt := range tests { for _, tt := range tests {
// nolint: scopelint
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
err := ApplyDefaults(&tt.target) err := ApplyDefaults(&tt.target)
require.NoError(t, err) require.NoError(t, err)
-6
View File
@@ -11,7 +11,6 @@ import (
"github.com/alecthomas/kong" "github.com/alecthomas/kong"
) )
// nolint: govet
type threeArg struct { type threeArg struct {
RequiredThree bool `required` RequiredThree bool `required`
Three string `arg` Three string `arg`
@@ -54,7 +53,6 @@ Flags:
} }
func TestHelp(t *testing.T) { func TestHelp(t *testing.T) {
// nolint: govet
var cli struct { var cli struct {
String string `help:"A string flag."` String string `help:"A string flag."`
Bool bool `help:"A bool flag with very long help that wraps a lot and is verbose and is really verbose."` Bool bool `help:"A bool flag with very long help that wraps a lot and is verbose and is really verbose."`
@@ -163,7 +161,6 @@ Flags:
} }
func TestFlagsLast(t *testing.T) { func TestFlagsLast(t *testing.T) {
// nolint: govet
var cli struct { var cli struct {
String string `help:"A string flag."` String string `help:"A string flag."`
Bool bool `help:"A bool flag with very long help that wraps a lot and is verbose and is really verbose."` Bool bool `help:"A bool flag with very long help that wraps a lot and is verbose and is really verbose."`
@@ -272,7 +269,6 @@ Flags:
} }
func TestHelpTree(t *testing.T) { func TestHelpTree(t *testing.T) {
// nolint: govet
var cli struct { var cli struct {
One struct { One struct {
Thing struct { Thing struct {
@@ -367,7 +363,6 @@ Commands:
} }
func TestHelpCompactNoExpand(t *testing.T) { func TestHelpCompactNoExpand(t *testing.T) {
// nolint: govet
var cli struct { var cli struct {
One struct { One struct {
Thing struct { Thing struct {
@@ -484,7 +479,6 @@ func TestCustomHelpFormatter(t *testing.T) {
} }
func TestHelpGrouping(t *testing.T) { func TestHelpGrouping(t *testing.T) {
// nolint: govet
var cli struct { var cli struct {
GroupedAString string `help:"A string flag grouped in A." group:"Group A"` GroupedAString string `help:"A string flag grouped in A." group:"Group A"`
FreeString string `help:"A non grouped string flag."` FreeString string `help:"A non grouped string flag."`
+1 -1
View File
@@ -385,7 +385,7 @@ func (k *Kong) LoadConfig(path string) (Resolver, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer r.Close() defer r.Close() // nolint: gosec
return k.loader(r) return k.loader(r)
} }
-3
View File
@@ -118,7 +118,6 @@ func TestFlagSliceWithSeparator(t *testing.T) {
} }
func TestArgSlice(t *testing.T) { func TestArgSlice(t *testing.T) {
// nolint: govet
var cli struct { var cli struct {
Slice []int `arg` Slice []int `arg`
Flag bool Flag bool
@@ -131,7 +130,6 @@ func TestArgSlice(t *testing.T) {
} }
func TestArgSliceWithSeparator(t *testing.T) { func TestArgSliceWithSeparator(t *testing.T) {
// nolint: govet
var cli struct { var cli struct {
Slice []string `arg` Slice []string `arg`
Flag bool Flag bool
@@ -498,7 +496,6 @@ func TestHooks(t *testing.T) {
for _, test := range tests { for _, test := range tests {
*ctx = hookContext{} *ctx = hookContext{}
cli.One = hookCmd{} cli.One = hookCmd{}
// nolint: scopelint
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
_, err := p.Parse(strings.Split(test.input, " ")) _, err := p.Parse(strings.Split(test.input, " "))
require.NoError(t, err) require.NoError(t, err)
+4 -4
View File
@@ -125,7 +125,7 @@ type BoolMapper interface {
// A MapperFunc is a single function that complies with the Mapper interface. // A MapperFunc is a single function that complies with the Mapper interface.
type MapperFunc func(ctx *DecodeContext, target reflect.Value) error type MapperFunc func(ctx *DecodeContext, target reflect.Value) error
func (m MapperFunc) Decode(ctx *DecodeContext, target reflect.Value) error { // nolint: golint func (m MapperFunc) Decode(ctx *DecodeContext, target reflect.Value) error { // nolint: revive
return m(ctx, target) return m(ctx, target)
} }
@@ -737,7 +737,7 @@ func SplitEscaped(s string, sep rune) (out []string) {
func JoinEscaped(s []string, sep rune) string { func JoinEscaped(s []string, sep rune) string {
escaped := []string{} escaped := []string{}
for _, e := range s { for _, e := range s {
escaped = append(escaped, strings.Replace(e, string(sep), `\`+string(sep), -1)) escaped = append(escaped, strings.ReplaceAll(e, string(sep), `\`+string(sep)))
} }
return strings.Join(escaped, string(sep)) return strings.Join(escaped, string(sep))
} }
@@ -748,7 +748,7 @@ type NamedFileContentFlag struct {
Contents []byte Contents []byte
} }
func (f *NamedFileContentFlag) Decode(ctx *DecodeContext) error { // nolint: golint func (f *NamedFileContentFlag) Decode(ctx *DecodeContext) error { // nolint: revive
var filename string var filename string
err := ctx.Scan.PopValueInto("filename", &filename) err := ctx.Scan.PopValueInto("filename", &filename)
if err != nil { if err != nil {
@@ -772,7 +772,7 @@ func (f *NamedFileContentFlag) Decode(ctx *DecodeContext) error { // nolint: gol
// FileContentFlag is a flag value that loads a file's contents into its value. // FileContentFlag is a flag value that loads a file's contents into its value.
type FileContentFlag []byte type FileContentFlag []byte
func (f *FileContentFlag) Decode(ctx *DecodeContext) error { // nolint: golint func (f *FileContentFlag) Decode(ctx *DecodeContext) error { // nolint: revive
var filename string var filename string
err := ctx.Scan.PopValueInto("filename", &filename) err := ctx.Scan.PopValueInto("filename", &filename)
if err != nil { if err != nil {
+1
View File
@@ -205,6 +205,7 @@ func (n *Node) Path() (out string) {
out += " " + n.Name out += " " + n.Name
case ArgumentNode: case ArgumentNode:
out += " " + "<" + n.Name + ">" out += " " + "<" + n.Name + ">"
default:
} }
return strings.TrimSpace(out) return strings.TrimSpace(out)
} }
+3 -3
View File
@@ -19,7 +19,7 @@ type Option interface {
// OptionFunc is function that adheres to the Option interface. // OptionFunc is function that adheres to the Option interface.
type OptionFunc func(k *Kong) error type OptionFunc func(k *Kong) error
func (o OptionFunc) Apply(k *Kong) error { return o(k) } // nolint: golint func (o OptionFunc) Apply(k *Kong) error { return o(k) } // nolint: revive
// Vars sets the variables to use for interpolation into help strings and default values. // Vars sets the variables to use for interpolation into help strings and default values.
// //
@@ -198,7 +198,7 @@ func BindToProvider(provider interface{}) Option {
errv := out[1] errv := out[1]
var err error var err error
if !errv.IsNil() { if !errv.IsNil() {
err = errv.Interface().(error) err = errv.Interface().(error) // nolint
} }
return out[0], err return out[0], err
} }
@@ -254,7 +254,7 @@ func ConfigureHelp(options HelpOptions) Option {
// See also ExplicitGroups for a more structured alternative. // See also ExplicitGroups for a more structured alternative.
type Groups map[string]string type Groups map[string]string
func (g Groups) Apply(k *Kong) error { // nolint: golint func (g Groups) Apply(k *Kong) error { // nolint: revive
for key, info := range g { for key, info := range g {
lines := strings.Split(info, "\n") lines := strings.Split(info, "\n")
title := strings.TrimSpace(lines[0]) title := strings.TrimSpace(lines[0])
+1 -1
View File
@@ -28,7 +28,7 @@ func TestBindTo(t *testing.T) {
} }
saw := "" saw := ""
method := func(i iface) error { // nolint: unparam method := func(i iface) error {
saw = string(i.(impl)) saw = string(i.(impl))
return nil return nil
} }
+3 -3
View File
@@ -22,10 +22,10 @@ type ResolverFunc func(context *Context, parent *Path, flag *Flag) (interface{},
var _ Resolver = ResolverFunc(nil) var _ Resolver = ResolverFunc(nil)
func (r ResolverFunc) Resolve(context *Context, parent *Path, flag *Flag) (interface{}, error) { // nolint: golint func (r ResolverFunc) Resolve(context *Context, parent *Path, flag *Flag) (interface{}, error) { // nolint: revive
return r(context, parent, flag) return r(context, parent, flag)
} }
func (r ResolverFunc) Validate(app *Application) error { return nil } // nolint: golint func (r ResolverFunc) Validate(app *Application) error { return nil } // nolint: revive
// JSON returns a Resolver that retrieves values from a JSON source. // JSON returns a Resolver that retrieves values from a JSON source.
// //
@@ -37,7 +37,7 @@ func JSON(r io.Reader) (Resolver, error) {
return nil, err return nil, err
} }
var f ResolverFunc = func(context *Context, parent *Path, flag *Flag) (interface{}, error) { var f ResolverFunc = func(context *Context, parent *Path, flag *Flag) (interface{}, error) {
name := strings.Replace(flag.Name, "-", "_", -1) name := strings.ReplaceAll(flag.Name, "-", "_")
raw, ok := values[name] raw, ok := values[name]
if !ok { if !ok {
return nil, nil return nil, nil
-1
View File
@@ -192,7 +192,6 @@ func TestLastResolverWins(t *testing.T) {
} }
func TestResolverSatisfiesRequired(t *testing.T) { func TestResolverSatisfiesRequired(t *testing.T) {
// nolint: govet
var cli struct { var cli struct {
Int int `required` Int int `required`
} }
-3
View File
@@ -68,7 +68,6 @@ func TestEscapedQuote(t *testing.T) {
} }
func TestBareTags(t *testing.T) { func TestBareTags(t *testing.T) {
// nolint: govet
var cli struct { var cli struct {
Cmd struct { Cmd struct {
Arg string `arg` Arg string `arg`
@@ -84,7 +83,6 @@ func TestBareTags(t *testing.T) {
} }
func TestBareTagsWithJsonTag(t *testing.T) { func TestBareTagsWithJsonTag(t *testing.T) {
// nolint: govet
var cli struct { var cli struct {
Cmd struct { Cmd struct {
Arg string `json:"-" optional arg` Arg string `json:"-" optional arg`
@@ -100,7 +98,6 @@ func TestBareTagsWithJsonTag(t *testing.T) {
} }
func TestManySeps(t *testing.T) { func TestManySeps(t *testing.T) {
// nolint: govet
var cli struct { var cli struct {
Arg string `arg optional default:"hi"` Arg string `arg optional default:"hi"`
} }