Skip to content

golangci-lint builds skipped packages even when they aren't being analyzed #489

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
xanderflood opened this issue Apr 9, 2019 · 9 comments
Labels
bug Something isn't working stale No recent correspondence or work activity

Comments

@xanderflood
Copy link

xanderflood commented Apr 9, 2019

Not sure if this is an issue with megacheck or golangci-lint. Hoping to get some clarity on where to look!

Please include the following information:

  1. Version of golangci-lint: golangci-lint --version (or git commit if you don't use binary distribution)
    git commit de1d1ad903cdfdfc577ecb08d5027576e70ed2f0
  2. Config file: cat .golangci.yml
run:
  deadline: 5m
  skip-dirs:
    - ./tmp

linters:
  disable-all: true
  enable:
    - megacheck
  1. Go environment: go version && go env
go version go1.12.1 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/newuser/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/newuser/go"
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/dp/770q0w1x747fs2kz3x9hnbxw0000gp/T/go-build830244029=/tmp/go-build -gno-record-gcc-switches -fno-common"
  1. Verbose output of running: golangci-lint run -v
INFO [config_reader] Used config file .golang-ci.yml
INFO [lintersdb] Active 3 linters: [gosimple staticcheck unused]
INFO [lintersdb] Optimized sublinters [staticcheck gosimple unused] into metalinter megacheck
INFO [loader] Go packages loading at mode load deps types and syntax took 4.458968448s
INFO [loader] SSA repr building timing: packages building 64.325419ms, total 1.008877796s
INFO [loader] Packages that do not compile: [github.com/GetTerminus/ads-ttd/tmp]
INFO [runner] worker.3 took 2.524µs
INFO [runner] worker.2 took 7.047µs
INFO [runner] worker.1 took 2.726µs
INFO [runner] worker.8 took 1.485µs
INFO [runner] worker.5 took 2.252µs
INFO [runner] worker.6 took 1.222µs
INFO [runner] worker.7 took 2.934µs
WARN [runner] Panic stack trace: goroutine 10597 [running]:
runtime/debug.Stack(0x191fe00, 0xc03f482ae0, 0xc02fed28f8)
        /usr/local/go/src/runtime/debug/stack.go:24 +0x9d
github.com/golangci/golangci-lint/pkg/lint.(*Runner).runLinterSafe.func1(0xc02fed3ce8, 0xc02fed3ee0)
        /Users/newuser/go/src/github.com/golangci/golangci-lint/pkg/lint/runner.go:106 +0xfd
panic(0x18f67a0, 0xc061994f90)
        /usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/golangci/golangci-lint/vendor/github.com/golangci/go-tools/lint.(*Linter).Lint(0xc02fed3658, 0xc0243aa800, 0xee, 0x100, 0xc02fed3620, 0x0, 0x0, 0x7ed38c0)
        /Users/newuser/go/src/github.com/golangci/golangci-lint/vendor/github.com/golangci/go-tools/lint/lint.go:477 +0x343c
github.com/golangci/golangci-lint/pkg/golinters.runMegacheckCheckers(0xc01a3e7d00, 0x3, 0x4, 0xc00007c870, 0xc0243aa800, 0xee, 0x100, 0x4, 0x0, 0x0, ...)
        /Users/newuser/go/src/github.com/golangci/golangci-lint/pkg/golinters/megacheck.go:349 +0x1f3
github.com/golangci/golangci-lint/pkg/golinters.megacheck.runMegacheck(0xc000010101, 0xc0243aa800, 0xee, 0x100, 0x0, 0xc00007c9f8, 0x100db99, 0xc0399b6060, 0x30, 0x30)
        /Users/newuser/go/src/github.com/golangci/golangci-lint/pkg/golinters/megacheck.go:303 +0x182
github.com/golangci/golangci-lint/pkg/golinters.megacheck.Run(0x10101, 0x1bdf720, 0xc0000d3500, 0xc010f74000, 0xc037129170, 0x1, 0x1, 0x1be66c0, 0xc043083b80)
        /Users/newuser/go/src/github.com/golangci/golangci-lint/pkg/golinters/megacheck.go:243 +0xe8
github.com/golangci/golangci-lint/pkg/lint.(*Runner).runLinterSafe(0xc00007cee0, 0x1bdf720, 0xc0000d3500, 0xc057349730, 0xc000178a80, 0x0, 0x0, 0x0, 0x1bc8dc0, 0xc03f482ae0)
        /Users/newuser/go/src/github.com/golangci/golangci-lint/pkg/lint/runner.go:112 +0x16a
github.com/golangci/golangci-lint/pkg/lint.Runner.runWorker.func1()
        /Users/newuser/go/src/github.com/golangci/golangci-lint/pkg/lint/runner.go:146 +0x64
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc03cb88e60, 0x1a217bc, 0x9, 0xc001303640)
        /Users/newuser/go/src/github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:75 +0x50
github.com/golangci/golangci-lint/pkg/lint.Runner.runWorker(0xc01b68d0e0, 0x11, 0x11, 0x1be97e0, 0xc0399f22d0, 0x1bdf720, 0xc0000d3500, 0xc057349730, 0xc0224bb4a0, 0xc0224bb500, ...)
        /Users/newuser/go/src/github.com/golangci/golangci-lint/pkg/lint/runner.go:145 +0x23b
github.com/golangci/golangci-lint/pkg/lint.(*Runner).runWorkers.func1(0xc035db0bd0, 0xc0399d0b10, 0x1bdf720, 0xc0000d3500, 0xc057349730, 0xc0224bb4a0, 0xc0224bb500, 0xc021472240, 0x8, 0x8, ...)
        /Users/newuser/go/src/github.com/golangci/golangci-lint/pkg/lint/runner.go:200 +0x163
created by github.com/golangci/golangci-lint/pkg/lint.(*Runner).runWorkers
        /Users/newuser/go/src/github.com/golangci/golangci-lint/pkg/lint/runner.go:197 +0x1ab

INFO [runner] worker.4 took 3.888218347s with stages: megacheck: 3.888199813s
INFO [runner] Workers idle times: #1: 3.888124635s, #2: 3.888134341s, #3: 3.888141873s, #5: 3.888066174s, #6: 3.888058407s, #7: 3.888049372s, #8: 3.888094445s
WARN [runner] Can't run linter megacheck: panic occurred: panic: interface conversion: types.Object is nil, not *types.Func: goroutine 11305 [running]:
runtime/debug.Stack(0xc087cbf908, 0x190d860, 0xc08da4ced0)
        /usr/local/go/src/runtime/debug/stack.go:24 +0x9d
github.com/golangci/golangci-lint/vendor/github.com/golangci/go-tools/lint.(*Linter).Lint.func1.1(0xc04f9cddc0)
        /Users/newuser/go/src/github.com/golangci/golangci-lint/vendor/github.com/golangci/go-tools/lint/lint.go:458 +0x60
panic(0x190d860, 0xc08da4ced0)
        /usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/golangci/golangci-lint/vendor/github.com/golangci/go-tools/staticcheck.(*Checker).CheckDeprecated.func1(0x1bd3e20, 0xc00a2c2900, 0x1bd4401)
        /Users/newuser/go/src/github.com/golangci/golangci-lint/vendor/github.com/golangci/go-tools/staticcheck/lint.go:2336 +0x647
go/ast.inspector.Visit(0xc036bec6f0, 0x1bd3e20, 0xc00a2c2900, 0x1bca7a0, 0xc036bec6f0)
        /usr/local/go/src/go/ast/walk.go:373 +0x3a
go/ast.Walk(0x1bca7a0, 0xc036bec6f0, 0x1bd3e20, 0xc00a2c2900)
        /usr/local/go/src/go/ast/walk.go:52 +0x66
go/ast.walkDeclList(0x1bca7a0, 0xc036bec6f0, 0xc00a6f7140, 0x3, 0x4)
        /usr/local/go/src/go/ast/walk.go:38 +0x9e
go/ast.Walk(0x1bca7a0, 0xc036bec6f0, 0x1bd3da0, 0xc00f96ce80)
        /usr/local/go/src/go/ast/walk.go:353 +0x2659
go/ast.Inspect(...)
        /usr/local/go/src/go/ast/walk.go:385
github.com/golangci/golangci-lint/vendor/github.com/golangci/go-tools/staticcheck.(*Checker).CheckDeprecated(0xc043196220, 0xc04f9cddc0)
        /Users/newuser/go/src/github.com/golangci/golangci-lint/vendor/github.com/golangci/go-tools/staticcheck/lint.go:2377 +0xf3
github.com/golangci/golangci-lint/vendor/github.com/golangci/go-tools/lint.(*Linter).Lint.func1(0xc03ed30150, 0xc002ae6180, 0xc04f9cddc0)
        /Users/newuser/go/src/github.com/golangci/golangci-lint/vendor/github.com/golangci/go-tools/lint/lint.go:469 +0x102
created by github.com/golangci/golangci-lint/vendor/github.com/golangci/go-tools/lint.(*Linter).Lint
        /Users/newuser/go/src/github.com/golangci/golangci-lint/vendor/github.com/golangci/go-tools/lint/lint.go:455 +0x1d6e

INFO [runner] processing took 8.039µs with stages: nolint: 3.311µs, max_same_issues: 1.047µs, skip_dirs: 556ns, path_prettifier: 534ns, replacement_builder: 444ns, max_from_linter: 265ns, skip_files: 253ns, cgo: 226ns, identifier_marker: 217ns, autogenerated_exclude: 214ns, uniq_by_line: 158ns, path_shortener: 156ns, diff: 149ns, exclude: 149ns, source_code: 148ns, max_per_file_from_linter: 140ns, exclude-rules: 72ns
INFO File cache stats: 0 entries of total size 0B
INFO Memory: 83 samples, avg is 1156.8MB, max is 2500.6MB
INFO Execution took 9.521527807s

Here's the situation for reproducing: I have a (.gitignored) folder tmp/ in my repository, where I keep a number of sample go programs. There are many files in the same directory with package main and func main(). You can see early in the verbose output a message that:

INFO [loader] Packages that do not compile: [github.com/GetTerminus/ads-ttd/tmp]

meaning that golangci-lint is attempting and failing to compile the tmp folder even though it's been ignored. Later, megacheck panics. All other linters I've tried work fine regardless of the contents of my tmp folder (although they do all print the does not compile message.

If I change the contents of tmp to be a valid compilable go package, the linter runs fine. If I change the contents to contain invalid go code, but for a reason other than multiple declarations of func main(), I still see the "does not compile" message, but megacheck does not panic. Only when one of my folders contains a redeclared function does the megacheck panic occur, but it occurs even when the problem package is ignored.

I have not been able to reproduce any of this behavior using megacheck directly, although the verbose logging doesn't tell me what megacheck command is actually be executed, so that's hardly surprising. I also noticed after writing this issue report that megacheck is currently deprecated, but it remains among the default linters for golangci-lint. Since it's officially deprecated, shouldn't it be disabled by default?

@xanderflood
Copy link
Author

xanderflood commented Apr 9, 2019

Correction: this issue is not restricted to megacheck, similar behavior is observed with govet, but not with other linters I've tried.

When I run golangci-lint run --config .golang-ci.yml -v, I either see or do not see the following block of error messages depending on whether I've inserted a compiler error into my skipped tmp directory. Unlike with megacheck, it doesn't depend on which type of compiler error:

WARN [runner/govet] govet error: assign: analysis skipped due to errors in package
WARN [runner/govet] govet error: atomicalign: analysis skipped due to errors in package
WARN [runner/govet] govet error: bools: analysis skipped due to errors in package
WARN [runner/govet] govet error: buildtag: analysis skipped due to errors in package
WARN [runner/govet] govet error: httpresponse: analysis skipped due to errors in package
WARN [runner/govet] govet error: loopclosure: analysis skipped due to errors in package
WARN [runner/govet] govet error: ctrlflow: analysis skipped due to errors in package
WARN [runner/govet] govet error: lostcancel: failed prerequisites: [email protected]/GetTerminus/ads-ttd/tmp
WARN [runner/govet] govet error: nilfunc: analysis skipped due to errors in package
WARN [runner/govet] govet error: printf: analysis skipped due to errors in package
WARN [runner/govet] govet error: shift: analysis skipped due to errors in package
WARN [runner/govet] govet error: stdmethods: analysis skipped due to errors in package
WARN [runner/govet] govet error: tests: analysis skipped due to errors in package
WARN [runner/govet] govet error: unmarshal: analysis skipped due to errors in package
WARN [runner/govet] govet error: unsafeptr: analysis skipped due to errors in package
WARN [runner/govet] govet error: unusedresult: analysis skipped due to errors in package
WARN [runner/govet] govet error: buildssa: analysis skipped due to errors in package
WARN [runner/govet] govet error: nilness: failed prerequisites: [email protected]/GetTerminus/ads-ttd/tmp
WARN [runner/govet] govet error: shadow: analysis skipped due to errors in package
WARN [runner] Can't run linter govet: asmdecl: analysis skipped due to errors in package

It appears that govet is attempting to analyze my tmp directory no matter what. When I change tmp to be perfectly compilable but to contain issues that govet will complain about, those issues don't appear in the output, which is expected. It appears that golangci-lint is treating tmp like any other directory, building and linting it, and then simply suppressing the output unless it's a serious error.

I've also checked staticcheck, deadcode, and structcheck. These linters do not show any error output if tmp fails to compile. They do always log a package does not compile message, though.

@xanderflood
Copy link
Author

xanderflood commented Apr 9, 2019

It would also be helpful if the WARNs that I'm getting here gave an indication of which package was being analyzed when the problems occurred, and even what the errors in package are. As it stands, the only way to narrow down the problem package was to run the command repeatedly on subsets of the directory to figure out when the error appears and when it doesn't.

@guusvw
Copy link

guusvw commented Apr 17, 2019

Any updates on this issue? We're running in the same issue, golangci-lint version 1.12.5 is working for us.

jirfag added a commit that referenced this issue Apr 21, 2019
The bug was introduced in golangci-lint when migrating staticcheck to go/packages.
Also, thanks to pkg.IllTyped we can analyze as max as we can by
staticcheck.

Relates: #418, #369, #429, #489
jirfag added a commit that referenced this issue Apr 21, 2019
The bug was introduced in golangci-lint when migrating staticcheck to go/packages.
Also, thanks to pkg.IllTyped we can analyze as max as we can by
staticcheck.

Relates: #418, #369, #429, #489
@jirfag
Copy link
Contributor

jirfag commented Apr 21, 2019

Hi, thank you for the issue!

  1. I've fixed panic of staticcheck in Fix staticcheck panic on packages that do not compile #507, please, check.
  2. We can't not build skipped packages: it's the limitation of go/packages library.

@ptman
Copy link

ptman commented Aug 23, 2019

I'm getting a long error like:

level=error msg="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 -- ./...]: exit status 1:
go: directory drone-cache/gopkg/mod/github.com/!burnt!sushi/[email protected] outside available modules
go: directory drone-cache/gopkg/mod/github.com/!burnt!sushi/[email protected]/cmd/toml-test-decoder outside available modules
go: directory drone-cache/gopkg/mod/github.com/!burnt!sushi/[email protected]/cmd/toml-test-encoder outside available modules
go: directory drone-cache/gopkg/mod/github.com/!burnt!sushi/[email protected]/cmd/tomlv outside available modules
...

@tpounds tpounds added the bug Something isn't working label Sep 29, 2019
@ptman
Copy link

ptman commented Oct 3, 2019

Now I got a total failure to lint anything with the newest version. Using v1.8.1 works fine. Seems to fail on our tools/ -directory with several script-like .go -files that I run using go run. tools/ cannot be built as a package, but do I really need to put each file in their own directory since tools/ cannot be skipped?

@stale
Copy link

stale bot commented Mar 31, 2020

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.

@stale stale bot added the stale No recent correspondence or work activity label Mar 31, 2020
@stale stale bot closed this as completed Apr 14, 2020
@ptman
Copy link

ptman commented Apr 14, 2020

adding stale label is good and prudent, but closing unfixed issues feels wrong

@xanderflood
Copy link
Author

2. We can't not build skipped packages: it's the limitation of go/packages library.

@jirfag could you clarify what you meant by this? I've tried a few times to find out what you meant here and to look at that library to see if there's a way to build individual packages, but I can't find anything about a module named go/packages, and nothing by that name is imported in the go.mod for this module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale No recent correspondence or work activity
Projects
None yet
Development

No branches or pull requests

5 participants