Skip to content

Golangci-lint does not work with go module #599

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

Closed
kindermoumoute opened this issue Jul 4, 2019 · 2 comments
Closed

Golangci-lint does not work with go module #599

kindermoumoute opened this issue Jul 4, 2019 · 2 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@kindermoumoute
Copy link

Pipeline

I just added the package golang.org/x/xerrors in my go.mod

Expected

golangci-lint to pass.

Actual

$ GOLANGCI_COM_RUN=1 golangci-lint run --out-format=json --issues-exit-code=0 --deadline=5m --new=false --new-from-rev= --new-from-patch=../changes.patch
    Running error: context loading failed: package github.com/scaleway/scaleway-sdk-go/api/instance/v1
    	imports golang.org/x/xerrors: cannot find package "golang.org/x/xerrors" in any of:
    	/go/src/github.com/scaleway/scaleway-sdk-go/vendor/golang.org/x/xerrors (vendor tree)
    	/usr/local/go/src/golang.org/x/xerrors (from $GOROOT)
    	/go/src/golang.org/x/xerrors (from $GOPATH): failed to analyze
@Helcaraxan
Copy link
Contributor

Helcaraxan commented Aug 8, 2019

I believe this is a Go environment setup issue rather than a golangci-lint issue.

From the pipeline link you gave, when unrolling the "Print environment" and "Prepare repo" steps, it seems that the go toolchain (which includes the go list that linters and other elements rely on to find packages) is not working in module-mode but rather in GOPATH-mode. It does not look like you are setting GO111MODULE=on and the code is checked out at the standard GOPATH location, which in Go 1.12.6 will default to GOPATH-mode despite there being a go.mod file available (in Go 1.13 this will be flipped and it should work as expected).

Furthermore you are using vendored dependencies which, in order to work with Go modules, requires you to add -mod=vendor to the GOFLAGS environment variable. Otherwise go list will prefer to resolve the dependencies located in the module cache over the ones in your vendor directory.

I might be completely off but I passed by this issue and thought I'd share the perspective. 🙂

@tpounds
Copy link
Contributor

tpounds commented Sep 29, 2019

@kindermoumoute This issue should be resolved in latest v1.19.1 release. Can you try again and see if that resolves your issue?

see:
#539
#730

@tpounds tpounds closed this as completed Sep 29, 2019
@tpounds tpounds added bug Something isn't working duplicate This issue or pull request already exists labels Sep 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants