Skip to content

Linter does not support go workspaces (go.work) #2666

@Chamuelm

Description

@Chamuelm

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go1.20 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.11.0
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.75.0
      e2816fe719a4026ffa1ee0189dc89bdfdbafb164
      x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.37.1
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: /go
GOROOT: /usr/local/go
PATH: /go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PATH (vscode launched with): /vscode/vscode-server/bin/linux-x64/e2816fe719a4026ffa1ee0189dc89bdfdbafb164/bin/remote-cli:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

	go:	/usr/local/go/bin/go: go version go1.20 linux/amd64

	gotests:	not installed
	gomodifytags:	/go/bin/gomodifytags	(version: v1.16.0 built with go: go1.20)
	impl:	not installed
	goplay:	not installed
	dlv:	/go/bin/dlv	(version: v1.20.1 built with go: go1.20)
	golangci-lint:	/go/bin/golangci-lint	(version: (devel) built with go: go1.20)
	gopls:	/go/bin/gopls	(version: v0.11.0 built with go: go1.20)

go env
Workspace Folder (activitylogs): /workspaces/activitylogs
	GO111MODULE=""
	GOARCH="amd64"
	GOBIN=""
	GOCACHE="/home/unbiased/.cache/go-build"
	GOENV="/home/unbiased/.config/go/env"
	GOEXE=""
	GOEXPERIMENT=""
	GOFLAGS=""
	GOHOSTARCH="amd64"
	GOHOSTOS="linux"
	GOINSECURE=""
	GOMODCACHE="/go/pkg/mod"
	GONOPROXY="github.com/unbiased-security"
	GONOSUMDB="github.com/unbiased-security"
	GOOS="linux"
	GOPATH="/go"
	GOPRIVATE="github.com/unbiased-security"
	GOPROXY="https://proxy.golang.org,direct"
	GOROOT="/usr/local/go"
	GOSUMDB="sum.golang.org"
	GOTMPDIR=""
	GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
	GOVCS=""
	GOVERSION="go1.20"
	GCCGO="gccgo"
	GOAMD64="v1"
	AR="ar"
	CC="gcc"
	CXX="g++"
	CGO_ENABLED="1"
	GOMOD="/dev/null"
	GOWORK="/workspaces/activitylogs/go.work"
	CGO_CFLAGS="-O2 -g"
	CGO_CPPFLAGS=""
	CGO_CXXFLAGS="-O2 -g"
	CGO_FFLAGS="-O2 -g"
	CGO_LDFLAGS="-O2 -g"
	PKG_CONFIG="pkg-config"
	GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2929876491=/tmp/go-build -gno-record-gcc-switches"

Share the Go related settings you have added/edited

Go settings
``` "go.buildOnSave": "off", "go.lintOnSave": "workspace", "go.vetOnSave": "workspace", "go.buildTags": "", "go.buildFlags": [], "go.lintTool": "golangci-lint", "go.lintFlags": [ "--fast" ], "go.vetFlags": [], "go.testOnSave": true, "go.coverOnSave": false, "go.useCodeSnippetsOnFunctionSuggest": true, "editor.formatOnSave": true, "go.formatTool": "goimports", "go.formatFlags": [], "go.goroot": "", "go.gopath": "", "go.inferGopath": false, "go.gocodeAutoBuild": false, "go.testFlags": [ "-v" ], "go.useLanguageServer": true, "go.docsTool": "gogetdoc", "go.liveErrors": { "enabled": true, "delay": 500, }, ```

Describe the bug

The lint feature does not work in a go-workspace (go.work) workspace, this also happens if you run the linter manually:

> golangci-lint run
ERRO [linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies

You have to run the linter separatly for each sub-module.
This is how I solved it in our CI:
go work edit -json | jq -r '.Use[].DiskPath' | xargs --verbose -I{} golangci-lint run {}/...

The "Lint Current Package" still works.

We use the repository as monorepo so we actually need all of the go tools for all of the submodules.

Steps to reproduce the behavior:

  1. Create a new workspace with submodules and a golangci-lint as a linter
  2. Trigger lint on whole workspace

Screenshots or recordings

The error message from the extension output:

Starting linting the current workspace at /workspaces/activitylogs
Error while running tool: /go/bin/golangci-lint run --fast --print-issued-lines=false --out-format=colored-line-number --issues-exit-code=0 ./...
level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies"

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions