golangci-lint icon indicating copy to clipboard operation
golangci-lint copied to clipboard

ERRO [linters_context] typechecking error: pattern ./...: main module (gitlab.com/fleetspace/monoverse) does not contain package <git submodule directory goes here>

Open jdgordon opened this issue 3 years ago • 12 comments

Welcome

  • [X] Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • [X] Yes, I've searched similar issues on GitHub and didn't find any.
  • [X] Yes, I've included all information below (version, config, etc).
  • [X] Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)

Description of the problem

Apologies for the terrible title. We have added a new git submodule to our repo, golangci-lint is now throwing this nonsensical error.

I have managed to create a minimal reproduction, available at https://github.com/jdgordon/golangcilint-testrepo The entire contents of that repro:

$ ls -la .
total 304
drwxrwxr-x  4 jonathan jonathan   4096 Nov  1 19:33 .
drwxrwxr-x 32 jonathan jonathan   4096 Nov  1 19:36 ..
drwxrwxr-x  3 jonathan jonathan   4096 Nov  1 19:30 external
drwxrwxr-x  9 jonathan jonathan   4096 Nov  1 20:11 .git
-rw-rw-r--  1 jonathan jonathan    118 Nov  1 19:30 .gitmodules
-rw-rw-r--  1 jonathan jonathan   2506 Nov  1 19:33 .golangci.yml
-rw-rw-r--  1 jonathan jonathan  23006 Nov  1 19:30 go.mod
-rw-rw-r--  1 jonathan jonathan 259191 Nov  1 19:30 go.sum

the go.mod/sum and the .golangci.yml files have been copied unmodified from out actual repo but still show the issue.

jonathan@fleetlaptop:~/git/testrepo$ ~/go/go1.17.13/bin/golangci-lint run 
ERRO [linters_context] typechecking error: pattern ./...: main module (gitlab.com/fleetspace/monoverse) does not contain package gitlab.com/fleetspace/monoverse/external/loramac-node/src/boards/NAMote72/cmsis/arm-std 


jonathan@fleetlaptop:~/git/testrepo$ ~/go/go1.17.13/bin/golangci-lint run --skip-dirs=external
ERRO [linters_context] typechecking error: pattern ./...: main module (gitlab.com/fleetspace/monoverse) does not contain package gitlab.com/fleetspace/monoverse/external/loramac-node/src/boards/NAMote72/cmsis/arm-std

there doesnt appear to be anything go related in that git submodule whch might trigger this issue

jonathan@fleetlaptop:~/git/testrepo/external$ find -iname *.go
jonathan@fleetlaptop:~/git/testrepo/external$ find -iname go.*
jonathan@fleetlaptop:~/git/testrepo/external$ 

Version of golangci-lint

$ golangci-lint --version
# Paste output here

Configuration file

jonathan@fleetlaptop:~/git/testrepo$ cat .golangci.yml 
linters-settings:
  contextcheck:
    disable-fact: true
  gci:
    sections:
      - standard
      - default
      - prefix(gitlab.com/fleetspace/monoverse)
  gocognit:
    min-complexity: 50
  loggercheck:
    kitlog: false
    klog: false
    logr: false
    zap: true
  paralleltest:
    ignore-missing: true
  stylecheck:
    dot-import-whitelist:
      - github.com/onsi/ginkgo/v2
      - github.com/onsi/gomega

linters:
  disable-all: true
  enable:
    - "asciicheck"
    - "bodyclose"
    - "contextcheck"
    - "depguard"
    - "dogsled"
    - "dupl"
    - "errcheck"
    - "errchkjson"
    - "errorlint"
    - "exhaustive"
    - "exportloopref"
    - "gci"
    - "gochecknoglobals"
    - "gochecknoinits"
    - "gocognit"
    - "goconst"
    - "gocritic"
    - "gocyclo"
    - "goerr113"
    - "gofmt"
    - "gofumpt"
    - "goheader"
    - "goimports"
    - "gomodguard"
    - "goprintffuncname"
    - "gosec"
    - "gosimple"
    - "govet"
    - "ineffassign"
    - "interfacebloat"
    - "loggercheck"
    - "misspell"
    - "nakedret"
    - "nestif"
    - "noctx"
    - "nolintlint"
    - "nosprintfhostport"
    - "paralleltest"
    - "prealloc"
    - "reassign"
    - "revive"
    - "rowserrcheck"
    - "sqlclosecheck"
    - "staticcheck"
    - "stylecheck"
    - "tparallel"
    - "unconvert"
    - "unparam"
    - "unused"
    - "usestdlibvars"
    - "whitespace"

  # don't enable:
  # - "dupword"
  # - "exhaustivestruct"
  # - "funlen"
  # - "godot"
  # - "godox"
  # - "gomnd"
  # - "lll"
  # - "nlreturn"
  # - "testableexamples"
  # - "testpackage"
  # - "wrapcheck"
  # - "wsl"

issues:
  exclude-rules:
    - path: '(.+)_test\.go'
      linters:
        - "dupl"             # we have a lot of duplicate code in tests
        - "gochecknoglobals" # we use globals in tests
        - "gocognit"         # we have a lot of bloated code in tests
        - "goerr113"
    - path: 'eros/(.+)/tests?/'
      linters:
        - "gochecknoglobals" # ginkgo encourages using globals
        - "gochecknoinits"   # ginkgo encourages using init
        - "gocognit"         # we have a lot of bloated code in tests
    - path: 'eros/(.+)/tests?/'
      text: "dot-imports: should not use dot imports" # whitelist ginkgo dot imports in revive

run:
  timeout: 15m
  go: "1.17"
  max-same-issues: 0
  skip-dirs:
    - eros/external/lora-gateway-bridge
    - exosphere/gopkg/swagger
    - node_modules
    - external
  skip-files:
    - schema.resolvers.go # because this is semi-generated

Go environment

$ go version && go env
golangci-lint has version 1.50.0 built from 704109c6 on 2022-10-04T10:25:07Z
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jonathan/.cache/go-build"
GOENV="/home/jonathan/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/jonathan/go/pkg/mod"
GONOPROXY="gitlab.com/fleetspace"
GONOSUMDB="gitlab.com/fleetspace"
GOOS="linux"
GOPATH="/home/jonathan/go"
GOPRIVATE="gitlab.com/fleetspace"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/jonathan/go/go1.17.13"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/jonathan/go/go1.17.13/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.13"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/jonathan/git/testrepo/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-build86573678=/tmp/go-build -gno-record-gcc-switches"

Verbose output of running

$ ~/go/go1.17.13/bin/golangci-lint run --skip-dirs=external -v
INFO [config_reader] Config search paths: [./ /home/jonathan/git/testrepo /home/jonathan/git /home/jonathan /home /] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 51 linters: [asciicheck bodyclose contextcheck depguard dogsled dupl errcheck errchkjson errorlint exhaustive exportloopref gci gochecknoglobals gochecknoinits gocognit goconst gocritic gocyclo goerr113 gofmt gofumpt goheader goimports gomodguard goprintffuncname gosec gosimple govet ineffassign interfacebloat loggercheck misspell nakedret nestif noctx nolintlint nosprintfhostport paralleltest prealloc reassign revive rowserrcheck sqlclosecheck staticcheck stylecheck tparallel unconvert unparam unused usestdlibvars whitespace] 
INFO [loader] Go packages loading at mode 575 (imports|name|types_sizes|compiled_files|exports_file|files|deps) took 72.559111ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 23.588µs 
ERRO [linters_context] typechecking error: pattern ./...: main module (gitlab.com/fleetspace/monoverse) does not contain package gitlab.com/fleetspace/monoverse/external/loramac-node/src/boards/NAMote72/cmsis/arm-std 
INFO [linters_context/goanalysis] analyzers took 3.935632ms with top 10 stages: copylocks: 401.127µs, buildir: 365.054µs, SA4004: 198.997µs, fact_deprecated: 170.779µs, the_only_name: 90.528µs, inspect: 84.245µs, stdmethods: 80.959µs, buildtag: 59.038µs, loggercheck: 57.921µs, gofmt: 47.068µs 
INFO [runner] processing took 3.929µs with stages: max_same_issues: 561ns, nolint: 419ns, exclude-rules: 349ns, skip_dirs: 344ns, max_from_linter: 277ns, cgo: 188ns, uniq_by_line: 176ns, exclude: 174ns, path_prettifier: 167ns, skip_files: 162ns, autogenerated_exclude: 159ns, filename_unadjuster: 157ns, source_code: 151ns, max_per_file_from_linter: 142ns, diff: 139ns, identifier_marker: 87ns, severity-rules: 75ns, sort_results: 73ns, path_shortener: 68ns, path_prefixer: 61ns 
INFO [runner] linters took 438.867869ms with stages: goanalysis_metalinter: 438.814846ms 
INFO File cache stats: 0 entries of total size 0B 
INFO Memory: 7 samples, avg is 48.4MB, max is 61.4MB 
INFO Execution took 518.141292ms                 

Code example or link to a public repository

https://github.com/jdgordon/golangcilint-testrepo

jdgordon avatar Nov 01 '22 09:11 jdgordon

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

boring-cyborg[bot] avatar Nov 01 '22 09:11 boring-cyborg[bot]

Hello,

golangci-lint has mainly the same behavior as the go compiler but there are some differences in the way to display errors.

$ go build      
no Go files in /home/ldez/sources/experimental/golangcilint-testrepo
$ go build ./...
go: warning: "./..." matched no packages

Nothing seems unexpected in your issue.

ldez avatar Nov 01 '22 09:11 ldez

The lack of go files is only to minimize the big report.

Does golangci-lint directly call the go build to find it's files? It that is the case then I could see how it may be a big there. However as it stands, the linter tool is not failing with no found files, it is failing because it has incorrectly attempted to walk a non-go directory.

Please note that this directory is supplied with both the yaml config file and with --skip-dirs command line argument.

jdgordon avatar Nov 01 '22 09:11 jdgordon

Does golangci-lint directly call the go build to find it's files?

No, but golangci-lint uses some shared pieces with go build.

Please note that this directory is supplied with both the yaml config file and with --skip-dirs command line argument.

--skip-dirs is applied to the output but not before the analysis.

ldez avatar Nov 01 '22 10:11 ldez

Just to reinforce that this is a golangci-lint bug. I have done a clone of this repo, validated that it passes lint, added the problem git submodule and can easily reproduce the bug.

xxx:~$ cd git/
xxx:~/git$ git clone https://github.com/golangci/golangci-lint.git
Cloning into 'golangci-lint'...
remote: Enumerating objects: 22754, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 22754 (delta 14), reused 17 (delta 8), pack-reused 22730
Receiving objects: 100% (22754/22754), 39.55 MiB | 5.99 MiB/s, done.
Resolving deltas: 100% (13907/13907), done.
xxx:~/git$ cd golangci-lint/
xxx:~/git/golangci-lint$ ~/go/go1.17.13/bin/go
go             gofmt          golangci-lint  
xxx:~/git/golangci-lint$ ~/go/go1.17.13/bin/golangci-lint run
xxx:~/git/golangci-lint$ git submodule add https://github.com/lora-net/loramac-node.git
Cloning into '/home/jonathan/git/golangci-lint/loramac-node'...
remote: Enumerating objects: 28497, done.
remote: Counting objects: 100% (321/321), done.
remote: Compressing objects: 100% (144/144), done.
remote: Total 28497 (delta 190), reused 266 (delta 171), pack-reused 28176
Receiving objects: 100% (28497/28497), 27.37 MiB | 6.29 MiB/s, done.
Resolving deltas: 100% (18361/18361), done.
xxx:~/git/golangci-lint$ ~/go/go1.17.13/bin/golangci-lint run
ERRO [linters_context] typechecking error: pattern ./...: main module (github.com/golangci/golangci-lint) does not contain package github.com/golangci/golangci-lint/loramac-node/src/boards/NAMote72/cmsis/arm-std
xxx:~/git/golangci-lint$ git diff
xxx:~/git/golangci-lint$ git diff --staged
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 00000000..0aad7827
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "loramac-node"]
+       path = loramac-node
+       url = https://github.com/lora-net/loramac-node.git
diff --git a/loramac-node b/loramac-node
new file mode 160000
index 00000000..7f25f7ad
--- /dev/null
+++ b/loramac-node
@@ -0,0 +1 @@
+Subproject commit 7f25f7adb5b9bf7142f98f77c68363e8b1f7e8ee
xxx:~/git/golangci-lint$ 

Clearly there is something going on with this submodule that is tripping up the linter.

jdgordon avatar Nov 01 '22 12:11 jdgordon

I never said that is Go tooling problem: I said that is not unexpected behavior.

So please close your issue in the Go repository.

ldez avatar Nov 01 '22 12:11 ldez

Your example is a bad example because a repo without any Go file is not a Go project.

If I just add a simple Go file, there is no problem.

So you will have to create a better example of your real issue.

ldez avatar Nov 01 '22 12:11 ldez

EDIT: Looks like something else changed or the go1.19.3 docker image is busted as I'm getting weirdness elsewhere as well - so ignore this for now - sorry


I just updated my build image because of 1.19.3 being released and getting 100s to typecheck errors all the sudden, a small selection:

udprunner/udprunner_test.go:44:7: opts.QPS undefined (type RunnerOptions has no field or method QPS) (typecheck)
	opts.QPS = 100
	     ^
udprunner/udprunner_test.go:20:2: "net" imported but not used (typecheck)
	"net"
	^
dflag/dyngeneric.go:274:6: invalid operation: cannot compare value > toInclusive (type parameter T is not comparable with >) (typecheck)
		if value > toInclusive || value < fromInclusive {
		   ^

something is broken - this is

golangci-lint has version 1.50.1 built from 8926a95f on 2022-10-22T10:50:47Z
golangci-lint --timeout 120s  run ./...

on https://github.com/fortio/fortio

I can file a separate issue if you want but I was looking for "typecheck" open issue before filling a dup

ldemailly avatar Nov 01 '22 21:11 ldemailly

@ldemailly it's off-topic, golangci-lint has not been built with 1.19.3.

Please open another issue.

ldez avatar Nov 01 '22 21:11 ldez

sorry, it's my bad, somehow by installing something else in the image, permissions in /go changed causing the above weird errors. ignore it. I jumped the gun as linting was first in my CI.

(random data point: current latest golangci-lint (1.50.1) works fine along go1.19.3 / with that as base image. and you don't really need to rebuild urgently as the security issue with windows + exec only)

ldemailly avatar Nov 01 '22 22:11 ldemailly

Your example is a bad example because a repo without any Go file is not a Go project.

If I just add a simple Go file, there is no problem.

So you will have to create a better example of your real issue.

Please refer to my previous comment. Adding this troublesome git submodule to the golangci-lint repo breaks both tools. I will add a single go file to my test repo today if it helps.

I'm also not sure why you had the golang bug report closed. Given your statement of shared code, and that adding the submodule breaks go build ./... in this repo, I suspect it is far more likely a go tooling bug than here. Worst case more eyes on the issue is always better

jdgordon avatar Nov 01 '22 22:11 jdgordon

In my case, this error went away when I stopped trying to lint submodules and removed dead code from my tree.

dkegel-fastly avatar Apr 05 '24 22:04 dkegel-fastly

The problem seems to be fixed now, I used the same test commands as https://github.com/golangci/golangci-lint/issues/3339#issuecomment-1298429246

$ docker run --rm -it golang:1.23-alpine sh
/go # cd ..; mkdir foo && cd $_
/foo # apk add -q git curl
/foo # git clone -q https://github.com/golangci/golangci-lint.git; cd golangci-lint/
/foo/golangci-lint # curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.62.2
golangci/golangci-lint info checking GitHub for tag 'v1.62.2'
golangci/golangci-lint info found version: 1.62.2 for v1.62.2/linux/amd64
golangci/golangci-lint info installed /go/bin/golangci-lint
/foo/golangci-lint # golangci-lint run --show-stats
0 issues.
/foo/golangci-lint # git submodule add -q https://github.com/lora-net/loramac-node.git
/foo/golangci-lint # golangci-lint run --show-stats
0 issues.
/foo/golangci-lint # 

ldez avatar Dec 22 '24 00:12 ldez