From d4653433d43da68fc96eac954880b5aba1abbdfd Mon Sep 17 00:00:00 2001 From: toimtoimtoim Date: Mon, 21 Nov 2022 16:05:30 +0200 Subject: [PATCH] Add staticcheck to CI flow --- .github/workflows/echo.yml | 16 +++++++++++----- Makefile | 2 ++ middleware/jwt.go | 2 +- middleware/proxy_test.go | 3 +-- middleware/timeout_test.go | 6 +++--- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.github/workflows/echo.yml b/.github/workflows/echo.yml index c2bd41e1b..e35e7f107 100644 --- a/.github/workflows/echo.yml +++ b/.github/workflows/echo.yml @@ -44,13 +44,19 @@ jobs: with: go-version: ${{ matrix.go }} - - name: Install Dependencies - run: go install golang.org/x/lint/golint@latest - - name: Run Tests + run: go test -race --coverprofile=coverage.coverprofile --covermode=atomic ./... + + - name: Install dependencies for checks run: | - golint -set_exit_status ./... - go test -race --coverprofile=coverage.coverprofile --covermode=atomic ./... + go install golang.org/x/lint/golint@latest + go install honnef.co/go/tools/cmd/staticcheck@latest + + - name: Run golint + run: golint -set_exit_status ./... + + - name: Run staticcheck + run: staticcheck ./... - name: Upload coverage to Codecov if: success() && matrix.go == 1.19 && matrix.os == 'ubuntu-latest' diff --git a/Makefile b/Makefile index 3b7651983..6aff6a89f 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,10 @@ check: lint vet race ## Check project init: @go install golang.org/x/lint/golint@latest + @go install honnef.co/go/tools/cmd/staticcheck@latest lint: ## Lint the files + @staticcheck ${PKG_LIST} @golint -set_exit_status ${PKG_LIST} vet: ## Vet the files diff --git a/middleware/jwt.go b/middleware/jwt.go index bec5167e2..ef6ad4ebc 100644 --- a/middleware/jwt.go +++ b/middleware/jwt.go @@ -262,7 +262,7 @@ func JWTWithConfig(config JWTConfig) echo.MiddlewareFunc { } func (config *JWTConfig) defaultParseToken(auth string, c echo.Context) (interface{}, error) { - token := new(jwt.Token) + var token *jwt.Token var err error // Issue #647, #656 if _, ok := config.Claims.(jwt.MapClaims); ok { diff --git a/middleware/proxy_test.go b/middleware/proxy_test.go index 4b1dbef92..a1b7f2cae 100644 --- a/middleware/proxy_test.go +++ b/middleware/proxy_test.go @@ -384,10 +384,9 @@ func TestProxyError(t *testing.T) { e := echo.New() e.Use(Proxy(rb)) req := httptest.NewRequest(http.MethodGet, "/", nil) - rec := httptest.NewRecorder() // Remote unreachable - rec = httptest.NewRecorder() + rec := httptest.NewRecorder() req.URL.Path = "/api/users" e.ServeHTTP(rec, req) assert.Equal(t, "/api/users", req.URL.Path) diff --git a/middleware/timeout_test.go b/middleware/timeout_test.go index dbac3fbc3..6f60753c6 100644 --- a/middleware/timeout_test.go +++ b/middleware/timeout_test.go @@ -129,7 +129,7 @@ func TestTimeoutOnTimeoutRouteErrorHandler(t *testing.T) { e := echo.New() c := e.NewContext(req, rec) - stopChan := make(chan struct{}, 0) + stopChan := make(chan struct{}) err := m(func(c echo.Context) error { <-stopChan return errors.New("error in route after timeout") @@ -245,7 +245,7 @@ func TestTimeoutWithErrorMessage(t *testing.T) { e := echo.New() c := e.NewContext(req, rec) - stopChan := make(chan struct{}, 0) + stopChan := make(chan struct{}) err := m(func(c echo.Context) error { // NOTE: when difference between timeout duration and handler execution time is almost the same (in range of 100microseconds) // the result of timeout does not seem to be reliable - could respond timeout, could respond handler output @@ -275,7 +275,7 @@ func TestTimeoutWithDefaultErrorMessage(t *testing.T) { e := echo.New() c := e.NewContext(req, rec) - stopChan := make(chan struct{}, 0) + stopChan := make(chan struct{}) err := m(func(c echo.Context) error { <-stopChan return c.String(http.StatusOK, "Hello, World!")