Skip to content

Typechecking failes using go 1.11 modules #237

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
bbatha opened this issue Oct 2, 2018 · 7 comments
Closed

Typechecking failes using go 1.11 modules #237

bbatha opened this issue Oct 2, 2018 · 7 comments

Comments

@bbatha
Copy link

bbatha commented Oct 2, 2018

When migrating to go 1.11 modules I move our git repo outside of GOPATH and ran go mod init then go mod vendor. Unfortunately golangci-lint has a few errors that crop up from the typecheck lint. Disabling that lint results in errors:

golangci-lint run --no-config --disable-all -E megacheck ./config
WARN [runner/megacheck] Can't run megacheck because of compilation errors in packages [github.com/evalphobia/logrus_sentry github.com/stretchr/testify/assert]: ../../../go/pkg/mod/github.com/evalphobia/[email protected]/sentry.go:341: invalid operation: hook.client (variable of type *github.com/getsentry/raven-go.Client) has no field or method SetEnvironment and 2 more errors: run `golangci-lint run --no-config --disable-all -E typecheck` to see all errors

Please include the following information:

  1. Version of golangci-lint: golangci-lint --version (or git commit if you don't use binary distribution)
golangci-lint has version 1.10.2 built from dbfcf63 on 2018-09-02T12:30:29Z
  1. Go environment: go version && go env
go version go1.11 linux/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/bbatha/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/bbatha/go"
GOPROXY=""
GORACE=""
GOROOT="/home/user/bbatha/.linuxbrew/Cellar/go/1.11/libexec"
GOTMPDIR=""
GOTOOLDIR="/home/user/bbatha/.linuxbrew/Cellar/go/1.11/libexec/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc-5"
CXX="g++-5"
CGO_ENABLED="1"
GOMOD="/home/user/bbatha/projects/cid/api/go.mod"
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-build379815753=/tmp/go-build -gno-record-gcc-switches"
  1. Verbose output of running: golangci-lint run -v
level=info msg="[config_reader] Config search paths: [./ /home/user/bbatha/projects/cid/api/config /home/user/bbatha/projects/cid/api /home/user/bbatha/projects/cid /home/user/bbatha/projects /home/user/bbatha /home/user /home /]"
level=info msg="[lintersdb] Active 8 linters: [deadcode errcheck govet ineffassign megacheck structcheck typecheck varcheck]"
level=info msg="[load/path_resolver] Paths resolving took 1.554678ms: [config]"
level=info msg="[load] pkg ./config files: [/home/user/bbatha/projects/cid/api/config/config.go /home/user/bbatha/projects/cid/api/config/config_test.go]"
level=info msg="[load] Program loading took 4.321976021s"
level=info msg="[load] SSA repr building took 348.547362ms"
level=info msg="[load] Not compiling packages: [github.com/evalphobia/logrus_sentry github.com/stretchr/testify/assert]"
level=info msg="[runner] worker.9 took 74.243µs"
level=info msg="[runner] worker.39 took 39.322µs"
level=info msg="[runner] worker.21 took 3.655µs"
level=info msg="[runner] worker.20 took 2.603µs"
level=info msg="[runner] worker.8 took 100.832µs"
level=info msg="[runner] worker.32 took 3.173µs"
level=info msg="[runner] worker.4 took 85.955µs"
level=info msg="[runner] worker.30 took 3.472µs"
level=info msg="[runner] worker.34 took 2.259µs"
level=info msg="[runner] worker.29 took 3.771µs"
level=info msg="[runner] worker.10 took 26.971µs"
level=info msg="[runner] worker.22 took 2.62µs"
level=info msg="[runner] worker.24 took 2.845µs"
level=info msg="[runner] worker.5 took 2.621µs"
level=info msg="[runner] worker.52 took 4.605µs"
level=info msg="[runner] worker.42 took 2.646µs"
level=info msg="[runner] worker.41 took 15.747µs"
level=info msg="[runner] worker.11 took 3.779µs"
level=info msg="[runner] worker.53 took 2.653µs"
level=info msg="[runner] worker.46 took 2.584µs"
level=info msg="[runner] worker.48 took 6.17µs"
level=info msg="[runner] worker.47 took 216.5µs"
level=info msg="[runner] worker.56 took 27.674µs"
level=info msg="[runner] worker.55 took 110.568µs"
level=info msg="[runner] worker.54 took 2.68µs"
level=info msg="[runner] worker.50 took 2.788µs"
level=info msg="[runner] worker.37 took 2.352µs"
level=info msg="[runner] worker.33 took 2.842µs"
level=info msg="[runner] worker.19 took 149.708µs"
level=info msg="[runner] worker.44 took 3.067µs"
level=info msg="[runner] worker.49 took 29.337µs"
level=info msg="[runner] worker.40 took 2.834µs"
level=info msg="[runner] worker.38 took 2.308µs"
level=info msg="[runner] worker.17 took 176.556µs"
level=info msg="[runner] worker.28 took 2.531µs"
level=info msg="[runner] worker.31 took 347.946µs"
level=info msg="[runner] worker.18 took 241.574µs"
level=info msg="[runner] worker.12 took 88.733µs"
level=info msg="[runner] worker.43 took 49.066µs"
level=info msg="[runner] worker.51 took 140.372µs"
level=info msg="[runner] worker.25 took 253.699µs"
level=info msg="[runner] worker.27 took 158.651µs"
level=info msg="[runner] worker.36 took 240.571µs"
level=info msg="[runner] worker.23 took 113.738µs"
level=info msg="[runner] worker.26 took 230.043µs"
level=info msg="[runner] worker.16 took 104.483µs"
level=info msg="[runner] worker.45 took 211.278µs"
level=info msg="[runner] worker.35 took 238.203µs"
level=info msg="[runner] worker.7 took 656.855µs with stages: structcheck: 354.447µs"
level=warning msg="[runner/megacheck] Can't run megacheck because of compilation errors in packages [github.com/evalphobia/logrus_sentry github.com/stretchr/testify/assert]: ../../../go/pkg/mod/github.com/evalphobia/[email protected]/sentry.go:341: invalid operation: hook.client (variable of type *github.com/getsentry/raven-go.Client) has no field or method SetEnvironment and 2 more errors: run `golangci-lint run --no-config --disable-all -E typecheck` to see all errors"
level=info msg="[runner] worker.3 took 877.65µs with stages: megacheck: 604.072µs"
level=info msg="[runner] worker.13 took 829.241µs with stages: typecheck: 577.045µs"
level=info msg="[runner] worker.15 took 852.894µs with stages: deadcode: 479.979µs"
level=info msg="[runner] worker.6 took 882.796µs with stages: varcheck: 571.297µs"
level=info msg="[load/astcache] Parse AST for file ../../../go/pkg/mod/github.com/evalphobia/[email protected]/sentry.go on demand"
level=info msg="[runner] worker.14 took 1.026588ms with stages: errcheck: 727.99µs"
level=info msg="[runner] worker.2 took 1.734569ms with stages: ineffassign: 1.441806ms"
level=info msg="[load/astcache] Parse AST for file ../../../go/pkg/mod/github.com/stretchr/[email protected]/assert/assertions.go on demand"
level=info msg="[runner] worker.1 took 4.111376ms with stages: govet: 3.791312ms"
level=info msg="[runner] Workers idle times: #2: 2.36655ms, #3: 3.282503ms, #4: 3.894105ms, #5: 3.84802ms, #6: 3.206191ms, #7: 3.419685ms, #8: 3.917798ms, #9: 3.961705ms, #10: 3.864392ms, #11: 3.817398ms, #12: 3.650995ms, #13: 3.244052ms, #14: 3.051371ms, #15: 3.236744ms, #16: 3.52607ms, #17: 3.677818ms, #18: 3.654834ms, #19: 3.759409ms, #20: 3.926031ms, #21: 3.930404ms, #22: 3.859721ms, #23: 3.560468ms, #24: 3.857224ms, #25: 3.617151ms, #26: 3.553067ms, #27: 3.588621ms, #28: 3.672849ms, #29: 3.869525ms, #30: 3.880071ms, #31: 3.667625ms, #32: 3.907945ms, #33: 3.766698ms, #34: 3.876633ms, #35: 3.495574ms, #36: 3.565574ms, #37: 3.769276ms, #38: 3.701828ms, #39: 3.944722ms, #40: 3.706569ms, #41: 3.831537ms, #42: 3.83881ms, #43: 3.640974ms, #44: 3.743333ms, #45: 3.509682ms, #46: 3.81012ms, #47: 3.796973ms, #48: 3.800181ms, #49: 3.728472ms, #50: 3.772569ms, #51: 3.630271ms, #52: 3.839661ms, #53: 3.812483ms, #54: 3.783277ms, #55: 3.785571ms, #56: 3.792137ms"
level=info msg="[runner] processing took 4.624425ms with stages: autogenerated_exclude: 3.832747ms, source_code: 502.357µs, exclude: 107.358µs, path_prettifier: 98.412µs, nolint: 69.212µs, max_same_issues: 3.624µs, uniq_by_line: 3.444µs, max_per_file_from_linter: 3.14µs, cgo: 1.69µs, max_from_linter: 1.46µs, diff: 678ns, skip_files: 303ns"
../../../go/pkg/mod/github.com/evalphobia/[email protected]/sentry.go:341:14: invalid operation: hook.client (variable of type *github.com/getsentry/raven-go.Client) has no field or method SetEnvironment (typecheck)
	hook.client.SetEnvironment(environment)
	            ^
../../../go/pkg/mod/github.com/stretchr/[email protected]/assert/assertions.go:1387:2: unknown field DisablePointerAddresses in struct literal (typecheck)
	DisablePointerAddresses: true,
	^
../../../go/pkg/mod/github.com/stretchr/[email protected]/assert/assertions.go:1388:2: unknown field DisableCapacities in struct literal (typecheck)
	DisableCapacities:       true,
	^
level=info msg="Memory: 47 samples, avg is 303.3MB, max is 549.0MB"
level=info msg="Execution took 4.689654555s"

Here is the import list of the files I'm attempting to lint:

config/config.go

package config

import (
    "flag"
    "fmt"
    "os"
    "strings"

    logsentry "github.com/evalphobia/logrus_sentry"
    log "github.com/sirupsen/logrus"

    "io/ioutil"
    "strconv"

    "github.factset.com/FactSet/cid-api/errors"
    "gopkg.in/yaml.v2"
)

config/config_test.go

package config

import (
    "os"
    "testing"

    "github.com/stretchr/testify/assert"
)
@euskadi31
Copy link

I have exactly the same problem.

@nezorflame
Copy link

Looks like the same as the reason for #178

My current temporary solution is to manually skip these files with this config:

run:
  skip-files:
    - ".*/pkg/mod/.*$"

@franzwilhelm
Copy link

franzwilhelm commented Oct 9, 2018

@nezorflame That did not work for us :/ What does work for us is targeting our specific packages when running golangci-lint, like this (example from our app):

golangci-lint run db/model/... controllers/... cmd/... request/... response/... util/...

That being said, it is not optimal, as you will have to add new arguments to your command if new pacakges or files are added

@nezorflame
Copy link

@franzwilhelm yeah, both of these workarounds are suboptimal, hope that real fix is coming soon.

@mrsinham
Copy link

Any news ? This prevents us to use go modules. Thx !

@jirfag
Copy link
Contributor

jirfag commented Oct 22, 2018

Hi!
I've almost implemented it, but I have some troubles with cgo. I need some time to investigate it, maybe go/packages has bugs. I hope to finish within a week

jirfag added a commit that referenced this issue Oct 25, 2018
Use go/packages instead of x/tools/loader: it allows to work
with go modules and speedups loading of packages with the help
of build cache.

A lot of linters became "fast": they are enabled by --fast now and
work in 1-2 seconds. Only unparam, interfacer and megacheck
are "slow" linters now.

Average project is analyzed 20-40% faster than before if all linters are
enabled! If we enable all linters except unparam, interfacer and
megacheck analysis is 10-20x faster!
jirfag added a commit that referenced this issue Oct 28, 2018
Use go/packages instead of x/tools/loader: it allows to work
with go modules and speedups loading of packages with the help
of build cache.

A lot of linters became "fast": they are enabled by --fast now and
work in 1-2 seconds. Only unparam, interfacer and megacheck
are "slow" linters now.

Average project is analyzed 20-40% faster than before if all linters are
enabled! If we enable all linters except unparam, interfacer and
megacheck analysis is 10-20x faster!
jirfag added a commit that referenced this issue Oct 28, 2018
Use go/packages instead of x/tools/loader: it allows to work
with go modules and speedups loading of packages with the help
of build cache.

A lot of linters became "fast": they are enabled by --fast now and
work in 1-2 seconds. Only unparam, interfacer and megacheck
are "slow" linters now.

Average project is analyzed 20-40% faster than before if all linters are
enabled! If we enable all linters except unparam, interfacer and
megacheck analysis is 10-20x faster!
jirfag added a commit that referenced this issue Oct 28, 2018
Use go/packages instead of x/tools/loader: it allows to work
with go modules and speedups loading of packages with the help
of build cache.

A lot of linters became "fast": they are enabled by --fast now and
work in 1-2 seconds. Only unparam, interfacer and megacheck
are "slow" linters now.

Average project is analyzed 20-40% faster than before if all linters are
enabled! If we enable all linters except unparam, interfacer and
megacheck analysis is 10-20x faster!
jirfag added a commit that referenced this issue Oct 28, 2018
Use go/packages instead of x/tools/loader: it allows to work
with go modules and speedups loading of packages with the help
of build cache.

A lot of linters became "fast": they are enabled by --fast now and
work in 1-2 seconds. Only unparam, interfacer and megacheck
are "slow" linters now.

Average project is analyzed 20-40% faster than before if all linters are
enabled! If we enable all linters except unparam, interfacer and
megacheck analysis is 10-20x faster!
@jirfag jirfag closed this as completed in 0421bac Oct 28, 2018
@jirfag
Copy link
Contributor

jirfag commented Oct 28, 2018

go/packages are supported in release v1.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants