Skip to content
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

Directive: unexpected auto space beetween slash and directive when saving #2477

Closed
matthieuzbo opened this issue Sep 23, 2022 · 2 comments
Closed

Comments

@matthieuzbo
Copy link

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.
    • go version go1.19.1 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.9.5
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.71.2
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.35.2
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: /home/matthieu/go
GOROOT: /usr/local/go
PATH: /home/matthieu/.nvm/versions/node/v16.13.0/bin:/home/matthieu/.local/share/umake/bin:/opt/firefox/firefox:/home/matthieu/.local/bin:/home/matthieu/.pyenv/shims:/home/matthieu/.pyenv/bin:/home/matthieu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/usr/local/go/bin:/home/matthieu/go/bin/cobra:/usr/local/go/bin:/usr/local/go/bin:/home/matthieu/go/bin/cobra:/usr/local/bin/python3

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

	gotests:	not installed
	gomodifytags:	not installed
	impl:	not installed
	goplay:	not installed
	dlv:	/home/matthieu/go/bin/dlv	(version: v1.9.1 built with go: go1.19.1)
	golangci-lint:	/home/matthieu/go/bin/golangci-lint	(version: v1.49.0 built with go: go1.19.1)
	gopls:	/home/matthieu/go/bin/gopls	(version: v0.9.5 built with go: go1.19.1)

go env
Workspace Folder (reactor): /home/matthieu/projects/reactor
	GO111MODULE="on"
	GOARCH="amd64"
	GOBIN=""
	GOCACHE="/home/matthieu/.cache/go-build"
	GOENV="/home/matthieu/.config/go/env"
	GOEXE=""
	GOEXPERIMENT=""
	GOFLAGS=""
	GOHOSTARCH="amd64"
	GOHOSTOS="linux"
	GOINSECURE=""
	GOMODCACHE="/home/matthieu/go/pkg/mod"
	GONOPROXY=""
	GONOSUMDB=""
	GOOS="linux"
	GOPATH="/home/matthieu/go"
	GOPRIVATE=""
	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.19.1"
	GCCGO="gccgo"
	GOAMD64="v1"
	AR="ar"
	CC="gcc"
	CXX="g++"
	CGO_ENABLED="1"
	GOMOD="/home/matthieu/projects/reactor/go.mod"
	GOWORK=""
	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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build724002419=/tmp/go-build -gno-record-gcc-switches"

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

  "[go]": {
    "editor.defaultFormatter": "golang.go",
  },
  "go.lintFlags": [
    "--fast"
  ],
  "go.lintTool": "golangci-lint",
  "go.testFlags": [
    "-v"
  ],
  "go.testTags": "json1",
  "go.testTimeout": "120s",
  "go.toolsEnvVars": {
    "GO111MODULE": "on"
  },
  "go.toolsManagement.autoUpdate": true,
  "go.useCodeSnippetsOnFunctionSuggest": true,
  "go.useLanguageServer": true,
  "gopls": {
    "formatting.gofumpt": true
  },

Describe the bug

When I write comment directive, a space is automatically added between slash and directive after save. This produces following lint message:

directive // nolint should be written without leading space as //nolint (nolintlint)go-golangci-lint

A clear and concise description of what the bug.
A clear and concise description of what you expected to happen.

Steps to reproduce the behavior:

To reproduce, just write following code:

//nolint
func init() {}

After saving, code is now:

// nolint
func init() {}
@gopherbot gopherbot added this to the Untriaged milestone Sep 23, 2022
@findleyr
Copy link
Member

Hi, thanks for reporting this. It looks like the problem is that gofmt started inserting this space in Go 1.19. For example, click 'Format' on this playground example: https://go.dev/play/p/rqHg9VRZkht

It is unfortunate that this gofmt change broke golangci-lint, but I don't think we can go against gofmt here. I'll chat with the team. If necessary, I'll file an issue with golangci-lint asking them to accomodate this change in gofmt. (gofmt is everywhere, so it's really not sustainable to have a tool that is incompatible with gofmt).

@findleyr
Copy link
Member

Per the discussion at golangci/golangci-lint#3201, they are aware of this issue and the solution is to use //nolint:all. I will follow up on golang/go#43776 to +1 that this should be better documented. In the meantime, I don't think there's anything we can do here, so closing.

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

No branches or pull requests

3 participants