golangci / golangci-lint

Fast linters runner for Go
https://golangci-lint.run
GNU General Public License v3.0
15.79k stars 1.39k forks source link

Build failed with vendored modules on golangci.com #579

Closed sashayakovtseva closed 4 years ago

sashayakovtseva commented 5 years ago
  1. Version of golangci-lint: According to logs: golangci-lint has version 1.17.1 built from 4ba2155 on 2019-06-10T09:06:49Z

  2. Config file:

    
    run:
    deadline: 3m
    
    build-tags:
    - selinux
    - seccomp
    
    modules-download-mode: vendor

linters: enable-all: true disable:

linters-settings: govet: settings: printf: funcs:

issues: exclude-rules:

Exclude some linters from running on tests files.

- path: _test\.go
  linters:
    - errcheck
    - dupl
    - gosec
    - lll
    - scopelint

- path: pkg/server/runtime/streaming.go
  linters:
    - gocyclo

- text: "vendor/github.com/kubernetes-sigs/cri-o/pkg/seccomp/seccomp.go"
  linters:
    - typecheck

- path: pkg/server
  linters:
    - lll

max-issues-per-linter: 0 max-same-issues: 0


3. Go environment: `go version && go env`

$ go version go version go1.11.5 linux/amd64 $ go env GOARCH="amd64" GOBIN="" GOCACHE="/root/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/go" GOPROXY="" GORACE="" GOROOT="/usr/local/go" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build543853952=/tmp/go-build -gno-record-gcc-switches"


4. Verbose output of running: `golangci-lint run -v`

$ 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: failed to load program with go/packages: go [list -e -json -compiled=true -test=true -export=false -deps=true -find=false -tags selinux seccomp -mod=vendor -- ./...]: exit status 1: build flag -mod=vendor only valid when using modules


Is there a way to configure how golangci.com stores repo, or at least set envs? I found `project-path` option in service config, but that will still put repo under $GOPATH. Have you considered absolute paths  there? How to make it work with vendored modules?
sashayakovtseva commented 5 years ago

Had to use two distinct configs: one for golangci.com and one when running locally from Makefile :(

gdbelvin commented 5 years ago

What did the new config look like?

sashayakovtseva commented 5 years ago

Hello @gdbelvin! I saw your issue #578, it is pretty similar to what I have here. After attempts to tune golangci service I found out there is no way to do that. So in singularity-cri repo we decided to have two configs: one for golangci.com without modules-download-mode: vendor (can be found here) and another one for local run during make lint (config is here).

gdbelvin commented 5 years ago

Thanks for linking to your configs - very helpful.

ice4026 commented 5 years ago

Hi, is the issue solved? I'm trying to integrate golangci-lint with Goland. I use go mod without vendor, run golangci-lint with run --print-issued-lines=false -E golint -E gofmt -E goimports $FileDir$, get the message:

Running error: context loading failed: package git.ice.org/aa/bb/cc/dd
    imports git.ice.org/data/databus_client: cannot find package "git.ice.org/data/databus_client" in any of:
    /usr/local/Cellar/go/1.12.7/libexec/src/git.ice.org/data/databus_client (from $GOROOT)
    /Users/ice/Workspace/Go/src/git.ice.org/data/databus_client (from $GOPATH): failed to analyze

I also tried export GO111MODULE=on before running golangci-lint, got message:

Running error: context loading failed: failed to load program with go/packages: go [list -e -json -compiled=true -test=true -export=false -deps=true -find=false -- /Users/ice/Workspace/Go/src/git.ice.org/aa/bb/cc/dd]: exit status 1: go: cannot find main module; see 'go help modules'
ice4026 commented 5 years ago

oh sorry, I get the solution, just set working directory = $FileDir$.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.