From b048109077a3eff5f60f316ff60ef2403ab17bc4 Mon Sep 17 00:00:00 2001 From: Michael Weber Date: Wed, 26 Jun 2019 15:00:51 -0700 Subject: [PATCH] Switch to golangci-lint * fix warnings/adapt suppression TODO: * enable more linters --- Makefile | 10 +++------- clients/splunk/error.go | 5 +---- clients/splunk/testing.go | 1 + clients/splunk/user_test.go | 6 +++++- cmd/vault-plugin-splunk/main.go | 1 + conn.go | 1 + util.go | 1 + 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index d68c5ed..bed6f4c 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +GOLANGCI_LINT_ARGS := --enable=gosec --enable=dupl TESTREPORT := test-results.xml # XXX BUG(mweber) "go env GOBIN" is empty? @@ -34,17 +35,12 @@ test: build .PHONY: lint lint: dep - go list ./... | grep -v vendor | xargs go vet - go list ./... | grep -v vendor | xargs golint - ineffassign . - gosec -quiet ./... + golangci-lint run $(GOLANGCI_LINT_ARGS) .PHONY: prereq prereq: go get github.com/golang/dep/cmd/dep - go get golang.org/x/lint/golint - go get github.com/gordonklaus/ineffassign - go get github.com/securego/gosec/cmd/gosec/... + go get github.com/golangci/golangci-lint/cmd/golangci-lint go get gotest.tools/gotestsum .PHONY: clean diff --git a/clients/splunk/error.go b/clients/splunk/error.go index 3a6d8cc..58d6210 100644 --- a/clients/splunk/error.go +++ b/clients/splunk/error.go @@ -27,10 +27,7 @@ func (e APIError) Error() string { // Empty returns true if empty. Otherwise, at least 1 error message is // present and false is returned. func (e APIError) Empty() bool { - if len(e.Messages) == 0 { - return true - } - return false + return len(e.Messages) == 0 } // relevantError returns any non-nil http-related error (creating the request, diff --git a/clients/splunk/testing.go b/clients/splunk/testing.go index 58339bd..c76a86e 100644 --- a/clients/splunk/testing.go +++ b/clients/splunk/testing.go @@ -203,6 +203,7 @@ func NewTestSplunkServiceWithTempAdmin() (cleanup func(), conn *API, err error) clConn := conn clCleanup := cleanup cleanup = func() { + // nolint:errcheck // #nosec G104 clConn.AccessControl.Authentication.Users.Delete(testUser) clCleanup() diff --git a/clients/splunk/user_test.go b/clients/splunk/user_test.go index e6ce4e8..78ca530 100644 --- a/clients/splunk/user_test.go +++ b/clients/splunk/user_test.go @@ -31,6 +31,7 @@ func TestUserService_Create(t *testing.T) { user, _, err := userSvc.Create(params) assert.NilError(t, err) + // nolint:errcheck defer userSvc.Delete(user.Name) assert.Equal(t, user.Name, params.Name) assert.Equal(t, user.Content.Email, params.Email) @@ -53,6 +54,7 @@ func TestUserService_Update_Email(t *testing.T) { user, _, err := userSvc.Create(params) assert.NilError(t, err) + // nolint:errcheck defer userSvc.Delete(user.Name) assert.Equal(t, user.Name, params.Name) @@ -69,11 +71,12 @@ func TestUserService_Update_Password(t *testing.T) { user, _, err := userSvc.Create(params) assert.NilError(t, err) + // nolint:errcheck defer userSvc.Delete(user.Name) assert.NilError(t, err) assert.Equal(t, user.Name, params.Name) - user, _, err = userSvc.Update(user.Name, &UpdateUserOptions{ + _, _, err = userSvc.Update(user.Name, &UpdateUserOptions{ Password: "changed1234", }) assert.NilError(t, err) @@ -95,6 +98,7 @@ func TestUserService_Update_OwnPassword(t *testing.T) { params := testUserParams("") user, _, err := userSvc.Create(params) assert.NilError(t, err) + // nolint:errcheck defer userSvc.Delete(user.Name) _, _, err = userSvc.Update(user.Name, &UpdateUserOptions{ diff --git a/cmd/vault-plugin-splunk/main.go b/cmd/vault-plugin-splunk/main.go index 734630f..34a1117 100644 --- a/cmd/vault-plugin-splunk/main.go +++ b/cmd/vault-plugin-splunk/main.go @@ -26,6 +26,7 @@ func main() { // all plugins ignore Parse errors // #nosec G104 + // nolint:errcheck flags.Parse(os.Args[1:]) printField := func(field, value string) { diff --git a/conn.go b/conn.go index bf6df83..76bc22e 100644 --- a/conn.go +++ b/conn.go @@ -78,6 +78,7 @@ func (config *splunkConfig) store(ctx context.Context, s logical.Storage, name s if err != nil { // config was not stored => cancel cleanup // #nosec G104 + // nolint:errcheck framework.DeleteWAL(ctx, s, walID) } }() diff --git a/util.go b/util.go index bd5ccc3..8ac674b 100644 --- a/util.go +++ b/util.go @@ -19,6 +19,7 @@ func getValue(data *framework.FieldData, op logical.Operation, key string) (inte return nil, false } +// nolint:deadcode,unused func decodeValue(data *framework.FieldData, op logical.Operation, key string, v interface{}) error { raw, ok := getValue(data, op, key) if ok {