echo icon indicating copy to clipboard operation
echo copied to clipboard

Golangci-lint is failing to find package import on latest version in Github Actions

Open jeffwalsh opened this issue 4 years ago • 4 comments

Issue Description

We have several microservices on v4.1.17 and it is running fine. We have one service on v4.2.1 andgolint fails with two complentary errors: undeclared name: echo (typecheck) and "github.com/labstack/echo/v4" imported but not used (typecheck). Locally everything works great. Rolling back from v4.2.1 to v4.1.17 resolves the issue.

I'm unsure of this is an echo issue, golangci-lint issue, or GH actions issue. Apologies if this doesn't belong here.

Checklist

  • [ Y] Dependencies installed
  • [Y ] No typos
  • [Y ] Searched existing issues and docs

Expected behaviour

Running golangci-lint will be fine.

Actual behaviour

undeclared name: echo (typecheck) and "github.com/labstack/echo/v4" imported but not used (typecheck)

Steps to reproduce

Paste working Code into app, set up Github Actions to run:

    steps:
      - name: Install golangci-lint
        run: |
          go get github.com/golangci/golangci-lint/cmd/golangci-lint

      - name: Run linters
        run: |
          export PATH=$PATH:$(go env GOPATH)/bin
          golangci-lint --config=.golangci_lint.yaml run

.golanci_lint.yaml:


output:
  format: colored-line-number

linters:
  enable:
    - funlen
    # - exportloopref
    - gocognit
    - gocritic
    - godox
    - gofmt
    - golint
    - gosec
    - lll
    - whitespace
    - wsl
    - depguard

linters-settings:
  funlen:
    lines: 100
    statements: 40
  gocognit:
    min-complexity: 25
issues:
  exclude-rules:
    # Exclude some linters from running on tests files.
    - path: _test\.go
      linters:
        - funlen
        - gocognit

Working code to debug

package main
import (
"github.com/labstack/echo/v4"
)

func main() {
   fmt.Println(echo.GET)
}

Version/commit

v4.2.1

jeffwalsh avatar Apr 09 '21 02:04 jeffwalsh

I think your import is wrong. Instead of "github.com/labstack.echo/v4" use "github.com/labstack/echo/v4"

mkdir testimport
cd testimport
go mod init testimport

cat > main.go << EOF
package main

import (
	"fmt"
	"github.com/labstack/echo/v4"
)

func main() {
	fmt.Println(echo.GET)
}
EOF

go get github.com/labstack/echo/v4
go build

Output:

x@x:~/code/test$ mkdir testimport
x@x:~/code/test$ cd testimport
x@x:~/code/test/testimport$ go mod init testimport
go: creating new go.mod: module testimport
x@x:~/code/test/testimport$ 
x@x:~/code/test/testimport$ cat > main.go << EOF
> package main
> 
> import (
> "fmt"
> "github.com/labstack/echo/v4"
> )
> 
> func main() {
> fmt.Println(echo.GET)
> }
> EOF

x@x:~/code/test/testimport$ 
x@x:~/code/test/testimport$ go get github.com/labstack/echo/v4
go get: added github.com/labstack/echo/v4 v4.2.2
x@x:~/code/test/testimport$ go build
x@x:~/code/test/testimport$ ./testimport 
GET
x@x:~/code/test/testimport$

aldas avatar Apr 09 '21 05:04 aldas

also you might want to run go mod tidy after you add golangci-lint

x@x:~/code/test/testimport$ go get github.com/golangci/golangci-lint/cmd/golangci-lint
go: downloading github.com/golangci/golangci-lint v1.39.0
...
...
...
go: downloading github.com/mattn/go-runewidth v0.0.9
go get: added github.com/golangci/golangci-lint v1.39.0


x@x:~/code/test/testimport$ golangci-lint run
main.go:9:13: undeclared name: `echo` (typecheck)
fmt.Println(echo.GET)
            ^
main.go:5:1: "github.com/labstack/echo/v4" imported but not used (typecheck)
"github.com/labstack/echo/v4"
^


x@x:~/code/test/testimport$ go build
../../../go/pkg/mod/github.com/labstack/echo/[email protected]/echo.go:60:2: missing go.sum entry for module providing package golang.org/x/crypto/acme (imported by github.com/labstack/echo/v4); to add:
        go get github.com/labstack/echo/[email protected]
../../../go/pkg/mod/github.com/labstack/echo/[email protected]/echo.go:61:2: missing go.sum entry for module providing package golang.org/x/crypto/acme/autocert (imported by github.com/labstack/echo/v4); to add:
        go get github.com/labstack/echo/[email protected]
../../../go/pkg/mod/github.com/labstack/echo/[email protected]/echo.go:62:2: missing go.sum entry for module providing package golang.org/x/net/http2 (imported by github.com/labstack/echo/v4); to add:
        go get github.com/labstack/echo/[email protected]
../../../go/pkg/mod/github.com/labstack/echo/[email protected]/echo.go:63:2: missing go.sum entry for module providing package golang.org/x/net/http2/h2c (imported by github.com/labstack/echo/v4); to add:
        go get github.com/labstack/echo/[email protected]


x@x:~/code/test/testimport$ cat main.go 
package main

import (
"fmt"
"github.com/labstack/echo/v4"
)

func main() {
fmt.Println(echo.GET)
}


x@x:~/code/test/testimport$ go mod tidy
go: downloading golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
go: downloading golang.org/x/net v0.0.0-20210226172049-e18ecbb05110


x@x:~/code/test/testimport$ go build
x@x:~/code/test/testimport$ golangci-lint run
x@x:~/code/test/testimport$ 

aldas avatar Apr 09 '21 05:04 aldas

sorry, that was a typo. im using the correct import path. it also builds and compiles fine locally and running golangci lint locally. you can ee from the error i get: "github.com/labstack/echo/v4" imported but not used (typecheck)

jeffwalsh avatar Apr 09 '21 14:04 jeffwalsh

Use 'go mod tidy' after adding linter dependency.

aldas avatar Apr 09 '21 14:04 aldas