From 689f9122a6a82b88b968349eb89f8cb02f5d0c7b Mon Sep 17 00:00:00 2001 From: Kyriacos Kyriacou Date: Wed, 4 Aug 2021 23:15:31 +0200 Subject: [PATCH] Update linter config and follow recommendations --- .golangci.yml | 10 ++++++++++ error_test.go | 3 +-- fig.go | 4 ++-- fig_test.go | 11 +++-------- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c8b537e..7479b4c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,6 +4,13 @@ linters: - wsl - gomnd - testpackage + - wrapcheck + - nlreturn + - goerr113 + - exhaustivestruct + - exhaustive + - cyclop + - funlen issues: exclude-rules: @@ -16,6 +23,9 @@ issues: - funlen - scopelint - gocognit + - paralleltest + - errorlint + - forcetypeassert - path: doc\.go linters: - lll \ No newline at end of file diff --git a/error_test.go b/error_test.go index 6f24233..5e885be 100644 --- a/error_test.go +++ b/error_test.go @@ -13,8 +13,7 @@ func Test_fieldErrors_Error(t *testing.T) { got := fe.Error() - want := "A: aerr, B: berr" - if want != got { + if want := "A: aerr, B: berr"; want != got { t.Fatalf("want %q, got %q", want, got) } diff --git a/fig.go b/fig.go index d690c3a..5fe8833 100644 --- a/fig.go +++ b/fig.go @@ -208,7 +208,7 @@ func (f *fig) processField(field *field) error { if f.useEnv { if err := f.setFromEnv(field.v, field.path()); err != nil { - return fmt.Errorf("unable to set from env: %v", err) + return fmt.Errorf("unable to set from env: %w", err) } } @@ -218,7 +218,7 @@ func (f *fig) processField(field *field) error { if field.setDefault && isZero(field.v) { if err := f.setDefaultValue(field.v, field.defaultVal); err != nil { - return fmt.Errorf("unable to set default: %v", err) + return fmt.Errorf("unable to set default: %w", err) } } diff --git a/fig_test.go b/fig_test.go index eba7d70..7d6ba28 100644 --- a/fig_test.go +++ b/fig_test.go @@ -497,8 +497,7 @@ func Test_fig_decodeMap(t *testing.T) { } `fig:"server"` } - err := fig.decodeMap(m, &cfg) - if err != nil { + if err := fig.decodeMap(m, &cfg); err != nil { t.Fatalf("unexpected err: %v", err) } @@ -1026,12 +1025,7 @@ func Test_fig_setValue(t *testing.T) { t.Fatalf("unexpected err: %v", err) } - want, err := regexp.Compile("[a-z]+") - if err != nil { - t.Fatalf("error parsing time: %v", err) - } - - if re.String() != want.String() { + if want := regexp.MustCompile("[a-z]+"); re.String() != want.String() { t.Fatalf("want %v, got %v", want, re) } }) @@ -1159,6 +1153,7 @@ func Test_fig_setSlice(t *testing.T) { } func setenv(t *testing.T, key, value string) { + t.Helper() if err := os.Setenv(key, value); err != nil { t.Fatalf("os.Setenv() unexpected error: %v", err) }