Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add staticcheck to CI flow #2343

Merged
merged 1 commit into from Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions .github/workflows/echo.yml
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion middleware/jwt.go
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions middleware/proxy_test.go
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions middleware/timeout_test.go
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!")
Expand Down