From f3efa40cbf5835cb7c5c40f259a3ac84ec5c0406 Mon Sep 17 00:00:00 2001 From: George Blue Date: Thu, 17 Oct 2019 13:20:44 +0100 Subject: [PATCH] Introduce staticcheck static analysis Staticcheck is a tool that is highly recommended by the Go tools team, so let's give it a go. https://staticcheck.io/ --- .travis.yml | 4 +++- catalog_test.go | 2 +- domain/apiresponses/failure_responses.go | 3 +-- domain/service_plan_metadata_test.go | 2 +- fakes/staticcheck.conf | 1 + staticcheck.conf | 4 ++++ tools/tools.go | 1 + 7 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 fakes/staticcheck.conf create mode 100644 staticcheck.conf diff --git a/.travis.yml b/.travis.yml index 0fd8df77..f9d2f7a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,4 +8,6 @@ go: env: - GO111MODULE=on -script: go run github.com/onsi/ginkgo/ginkgo -r +script: +- go run honnef.co/go/tools/cmd/staticcheck ./... +- go run github.com/onsi/ginkgo/ginkgo -r diff --git a/catalog_test.go b/catalog_test.go index 79346736..812fc301 100644 --- a/catalog_test.go +++ b/catalog_test.go @@ -222,7 +222,7 @@ var _ = Describe("Catalog", func() { Bullets: []string{"hello", "its me"}, DisplayName: "name", AdditionalMetadata: map[string]interface{}{ - "foo": make(chan int, 0), + "foo": make(chan int), }, } _, err := json.Marshal(metadata) diff --git a/domain/apiresponses/failure_responses.go b/domain/apiresponses/failure_responses.go index f6bf8a3a..d27d2169 100644 --- a/domain/apiresponses/failure_responses.go +++ b/domain/apiresponses/failure_responses.go @@ -1,7 +1,6 @@ package apiresponses import ( - "errors" "fmt" "net/http" @@ -64,7 +63,7 @@ func (f *FailureResponse) LoggerAction() string { // AppendErrorMessage returns an error with the message updated. All other properties are preserved. func (f *FailureResponse) AppendErrorMessage(msg string) *FailureResponse { return &FailureResponse{ - error: errors.New(fmt.Sprintf("%s %s", f.Error(), msg)), + error: fmt.Errorf("%s %s", f.Error(), msg), statusCode: f.statusCode, loggerAction: f.loggerAction, emptyResponse: f.emptyResponse, diff --git a/domain/service_plan_metadata_test.go b/domain/service_plan_metadata_test.go index 54a99d7a..215dbde4 100644 --- a/domain/service_plan_metadata_test.go +++ b/domain/service_plan_metadata_test.go @@ -80,7 +80,7 @@ var _ = Describe("ServicePlanMetadata", func() { Bullets: []string{"hello", "its me"}, DisplayName: "name", AdditionalMetadata: map[string]interface{}{ - "foo": make(chan int, 0), + "foo": make(chan int), }, } _, err := json.Marshal(metadata) diff --git a/fakes/staticcheck.conf b/fakes/staticcheck.conf new file mode 100644 index 00000000..e7e254ff --- /dev/null +++ b/fakes/staticcheck.conf @@ -0,0 +1 @@ +checks = [] diff --git a/staticcheck.conf b/staticcheck.conf new file mode 100644 index 00000000..7feb2a23 --- /dev/null +++ b/staticcheck.conf @@ -0,0 +1,4 @@ +# When adding staticcheck, we thought it was better to get it working with some checks disabled +# rather than fixing all the problems in one go. Some problems cannot be fixed without making +# breaking changes. +checks = ["all", "-SA1019", "-ST1000", "-ST1003", "-ST1005", "-ST1012", "-ST1021", "-SA1029", "-ST1020"] diff --git a/tools/tools.go b/tools/tools.go index 680587bc..268b253e 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -5,6 +5,7 @@ package tools import ( _ "github.com/maxbrunsfeld/counterfeiter/v6" _ "github.com/onsi/ginkgo" + _ "honnef.co/go/tools/cmd/staticcheck" ) // This file imports packages that are used when running go generate, or used