From ffa0f45399df66e28b5976791993f5dc9c54ad06 Mon Sep 17 00:00:00 2001 From: Frederic BIDON Date: Wed, 26 Sep 2018 09:54:02 +0200 Subject: [PATCH] Fixed golangci-lint reported linting issues Signed-off-by: Frederic BIDON --- .golangci.yml | 19 +++++++++++++++++++ api.go | 10 +++++----- headers.go | 4 ++-- schema_test.go | 4 ++-- 4 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..0305d9f --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,19 @@ +linters-settings: + govet: + check-shadowing: true + golint: + min-confidence: 0 + gocyclo: + min-complexity: 30 + maligned: + suggest-new: true + dupl: + threshold: 100 + goconst: + min-len: 2 + min-occurrences: 4 +linters: + enable-all: true + disable: + - maligned + - lll diff --git a/api.go b/api.go index d1a752c..3372e14 100644 --- a/api.go +++ b/api.go @@ -134,26 +134,26 @@ func ServeError(rw http.ResponseWriter, r *http.Request, err error) { rw.Header().Add("Allow", strings.Join(err.(*MethodNotAllowedError).Allowed, ",")) rw.WriteHeader(asHTTPCode(int(e.Code()))) if r == nil || r.Method != head { - rw.Write(errorAsJSON(e)) + _, _ = rw.Write(errorAsJSON(e)) } case Error: value := reflect.ValueOf(e) if value.Kind() == reflect.Ptr && value.IsNil() { rw.WriteHeader(http.StatusInternalServerError) - rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error"))) + _, _ = rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error"))) return } rw.WriteHeader(asHTTPCode(int(e.Code()))) if r == nil || r.Method != head { - rw.Write(errorAsJSON(e)) + _, _ = rw.Write(errorAsJSON(e)) } case nil: rw.WriteHeader(http.StatusInternalServerError) - rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error"))) + _, _ = rw.Write(errorAsJSON(New(http.StatusInternalServerError, "Unknown error"))) default: rw.WriteHeader(http.StatusInternalServerError) if r == nil || r.Method != head { - rw.Write(errorAsJSON(New(http.StatusInternalServerError, err.Error()))) + _, _ = rw.Write(errorAsJSON(New(http.StatusInternalServerError, err.Error()))) } } } diff --git a/headers.go b/headers.go index a80ddc9..0360c09 100644 --- a/headers.go +++ b/headers.go @@ -54,7 +54,7 @@ const ( // InvalidContentType error for an invalid content type func InvalidContentType(value string, allowed []string) *Validation { - var values []interface{} + values := make([]interface{}, 0, len(allowed)) for _, v := range allowed { values = append(values, v) } @@ -70,7 +70,7 @@ func InvalidContentType(value string, allowed []string) *Validation { // InvalidResponseFormat error for an unacceptable response format request func InvalidResponseFormat(value string, allowed []string) *Validation { - var values []interface{} + values := make([]interface{}, 0, len(allowed)) for _, v := range allowed { values = append(values, v) } diff --git a/schema_test.go b/schema_test.go index 53093f0..e327aef 100644 --- a/schema_test.go +++ b/schema_test.go @@ -293,10 +293,10 @@ func TestSchemaErrors(t *testing.T) { assert.EqualValues(t, CompositeErrorCode, err2.Code()) assert.Equal(t, "validation failure list", err2.Error()) - err2 = CompositeValidationError(fmt.Errorf("First error"), fmt.Errorf("Second error")) + err2 = CompositeValidationError(fmt.Errorf("first error"), fmt.Errorf("second error")) assert.Error(t, err2) assert.EqualValues(t, CompositeErrorCode, err2.Code()) - assert.Equal(t, "validation failure list:\nFirst error\nSecond error", err2.Error()) + assert.Equal(t, "validation failure list:\nfirst error\nsecond error", err2.Error()) //func MultipleOfMustBePositive(name, in string, factor interface{}) *Validation { err = MultipleOfMustBePositive("path", "body", float64(-10))