I am trying to run golangci-lint on sourcegraph/sourcegraph but it is failing due to the presence of some Go code in one of our node_modules dependencies (weird but ¯\_(ツ)_/¯). I tried using --skip-dirs node_modules, but it seems to not have any effect.
Reproduce:
git clone https://github.com/sourcegraph/sourcegraph
cd sourcegraph
yarn
golangci-lint -v run --skip-dirs node_modules
Requested info:
golangci-lint --version (or git commit if you don't use binary distribution)Config file: cat .golangci.yml
None
Go environment: go version && go env
go version go1.11.2 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/nick/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/nick/dev/gopath"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/l6/djg_zw1j5lgbwz4h5q92lnwr0000gn/T/go-build800779018=/tmp/go-build -gno-record-gcc-switches -fno-common"
golangci-lint run -v$ golangci-lint -v run --skip-dirs node_modules
INFO [config_reader] Config search paths: [./ /Users/nick/dev/sourcegraph/node_modules /Users/nick/dev/sourcegraph /Users/nick/dev /Users/nick /Users /]
INFO Gocritic enabled checks: [appendAssign assignOp caseOrder dupArg dupBranchBody dupCase flagDeref ifElseChain regexpMust singleCaseSwitch sloppyLen switchTrue typeSwitchVar underef unlambda unslice defaultCaseOrder]
INFO [lintersdb] Active 8 linters: [deadcode errcheck govet ineffassign megacheck structcheck typecheck varcheck]
INFO [loader] Go packages loading at mode load deps types and syntax took 3.037896104s
ERRO Running error: context loading failed: failed to load program with go/packages: go [list -e -json -compiled -test=true -export=false -deps=true -- ./...]: exit status 1: build github.com/sourcegraph/sourcegraph/node_modules/snyk-go-plugin/gosrc: cannot find module for path _/Users/nick/dev/sourcegraph/node_modules/snyk-go-plugin/gosrc/resolver
INFO Memory: 32 samples, avg is 69.2MB, max is 69.2MB
INFO Execution took 3.13999768s
hi!
it's the restriction of go/packages (official library for loading packages for analysis): it uses go list and we just pass args (default are ./...) to it. We can't exclude any directory from go list ./.... Therefore skip-dirs analyzes set dirs and just skips issues from them.
You can use something like:
go list -f '{{.Dir}}' ./... | fgrep -v node_modules/ | xargs realpath --relative-to=. | xargs golangci-lint run -v
@jirfag
Looks this is still happening for v1.15.0, i totally cannot run the lining because our project depends on tensorflow project, and the --skip-dirs doesn't really skip it:
ERRO Running error: context loading failed: failed to load program with go/packages: go [list -e -json -compiled -test=true -export=false -deps=true -find=false -- ./...]: exit status 2: # ----------path/rmt_serving/tensorflow/tensorflow/go/genop/internal
ld: library not found for -ltensorflow
clang: error: linker command failed with exit code 1 (use -v to see invocation)
# github.com/tensorflow/tensorflow/tensorflow/go/genop/internal
ld: library not found for -ltensorflow
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@lnshi ld: library not found for -ltensorflow says that you need to install the tensorflow library, it's not installed.
@jirfag When does the filtering currently happen, on a per-file basis? Could not golangci-lint run the filter on go list output and not even consider ignored directories? (like the example with grep above)
One big problem if also if you have packages that do not compile (as detected by go list but are really not go packages). This prevents the whole megacheck from running, but linting still exits with exit code 0 (this is a separate issue but still related, #529).
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.
hi!
it's the restriction of go/packages (official library for loading packages for analysis): it usesgo listand we just pass args (default are./...) to it. We can't exclude any directory fromgo list ./.... Thereforeskip-dirsanalyzes set dirs and just skips issues from them.You can use something like:
go list -f '{{.Dir}}' ./... | fgrep -v node_modules/ | xargs realpath --relative-to=. | xargs golangci-lint run -v
hey @jirfag Thanks for that shell and I have skipped these dirs. But I have a question is that If I use the shell with fgrep -v, the skip-dirs in config will be invalid.
Most helpful comment
hi!
it's the restriction of go/packages (official library for loading packages for analysis): it uses
go listand we just pass args (default are./...) to it. We can't exclude any directory fromgo list ./.... Thereforeskip-dirsanalyzes set dirs and just skips issues from them.You can use something like: