diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..011c8610 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,64 @@ +linters-settings: + errcheck: + check-type-assertions: true + goconst: + min-len: 2 + min-occurrences: 3 + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + govet: + check-shadowing: true + enable: + - fieldalignment + nolintlint: + require-explanation: true + require-specific: true + staticcheck: + checks: + - all + - '-SA5008' + +linters: + disable-all: true + enable: + - bodyclose + - depguard + - dogsled + - dupl + - errcheck + - exportloopref + - exhaustive + - goconst + - gocritic + - gofmt + - goimports + - gomnd + - gocyclo + - gosec + - gosimple + - govet + - ineffassign + - misspell + - nolintlint + - nakedret + - prealloc + - predeclared + - revive + - staticcheck + - stylecheck + - thelper + - tparallel + - typecheck + - unconvert + - unparam + - unused + - whitespace + - wsl + +run: + issues-exit-code: 1 diff --git a/core/conf/config_test.go b/core/conf/config_test.go index 83928bb3..b0f5077b 100644 --- a/core/conf/config_test.go +++ b/core/conf/config_test.go @@ -105,7 +105,6 @@ d = "abcd!@#112" assert.Equal(t, 1, val.B) assert.Equal(t, "2", val.C) assert.Equal(t, "abcd!@#112", val.D) - } func TestConfigJsonEnv(t *testing.T) { diff --git a/core/limit/tokenlimit.go b/core/limit/tokenlimit.go index a0f48f31..aeb52f9a 100644 --- a/core/limit/tokenlimit.go +++ b/core/limit/tokenlimit.go @@ -60,8 +60,8 @@ type TokenLimiter struct { timestampKey string rescueLock sync.Mutex redisAlive uint32 - rescueLimiter *xrate.Limiter monitorStarted bool + rescueLimiter *xrate.Limiter } // NewTokenLimiter returns a new TokenLimiter that allows events up to rate and permits diff --git a/core/logx/writer.go b/core/logx/writer.go index deeb1c84..8a7774b2 100644 --- a/core/logx/writer.go +++ b/core/logx/writer.go @@ -361,7 +361,6 @@ func writePlainText(writer io.Writer, level, msg string, fields ...string) { if _, err := writer.Write(buf.Bytes()); err != nil { log.Println(err.Error()) } - } func writePlainValue(writer io.Writer, level string, val interface{}, fields ...string) { diff --git a/core/mapping/unmarshaler.go b/core/mapping/unmarshaler.go index 2cd1b93e..02490646 100644 --- a/core/mapping/unmarshaler.go +++ b/core/mapping/unmarshaler.go @@ -139,7 +139,6 @@ func (u *Unmarshaler) processAnonymousFieldOptional(field reflect.StructField, v filled = true maybeNewValue(field, value) indirectValue = reflect.Indirect(value) - } if err = u.processField(subField, indirectValue.Field(i), m, fullName); err != nil { return err diff --git a/rest/chain/chain_test.go b/rest/chain/chain_test.go index f5973c46..1aeb7895 100644 --- a/rest/chain/chain_test.go +++ b/rest/chain/chain_test.go @@ -86,7 +86,7 @@ func TestThenOrdersHandlersCorrectly(t *testing.T) { chained := New(t1, t2, t3).Then(testApp) w := httptest.NewRecorder() - r, err := http.NewRequest("GET", "/", nil) + r, err := http.NewRequest("GET", "/", http.NoBody) if err != nil { t.Fatal(err) } @@ -103,7 +103,7 @@ func TestAppendAddsHandlersCorrectly(t *testing.T) { h := c.Then(testApp) w := httptest.NewRecorder() - r, err := http.NewRequest("GET", "/", nil) + r, err := http.NewRequest("GET", "/", http.NoBody) assert.Nil(t, err) h.ServeHTTP(w, r) diff --git a/rest/engine_test.go b/rest/engine_test.go index b8633d88..2aeef9a9 100644 --- a/rest/engine_test.go +++ b/rest/engine_test.go @@ -238,7 +238,7 @@ func TestEngine_notFoundHandler(t *testing.T) { client := ts.Client() err := func(ctx context.Context) error { - req, err := http.NewRequest("GET", ts.URL+"/bad", nil) + req, err := http.NewRequest("GET", ts.URL+"/bad", http.NoBody) assert.Nil(t, err) res, err := client.Do(req) assert.Nil(t, err) @@ -261,7 +261,7 @@ func TestEngine_notFoundHandlerNotNil(t *testing.T) { client := ts.Client() err := func(ctx context.Context) error { - req, err := http.NewRequest("GET", ts.URL+"/bad", nil) + req, err := http.NewRequest("GET", ts.URL+"/bad", http.NoBody) assert.Nil(t, err) res, err := client.Do(req) assert.Nil(t, err) @@ -285,8 +285,8 @@ func TestEngine_notFoundHandlerNotNilWriteHeader(t *testing.T) { defer ts.Close() client := ts.Client() - err := func(ctx context.Context) error { - req, err := http.NewRequest("GET", ts.URL+"/bad", nil) + err := func(_ context.Context) error { + req, err := http.NewRequest("GET", ts.URL+"/bad", http.NoBody) assert.Nil(t, err) res, err := client.Do(req) assert.Nil(t, err) diff --git a/rest/httpx/responses_test.go b/rest/httpx/responses_test.go index dcd08a8a..8e8a882e 100644 --- a/rest/httpx/responses_test.go +++ b/rest/httpx/responses_test.go @@ -200,7 +200,7 @@ func (w *tracedResponseWriter) Write(bytes []byte) (n int, err error) { n, err = w.builder.Write(bytes) if w.lessWritten { - n -= 1 + n-- } w.hasBody = true