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

cmd/gofmt: insert space between : and = when syntax error #27576

Closed
jingyugao opened this issue Sep 9, 2018 · 5 comments
Closed

cmd/gofmt: insert space between : and = when syntax error #27576

jingyugao opened this issue Sep 9, 2018 · 5 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@jingyugao
Copy link

jingyugao commented Sep 9, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.11 darwin/amd64

Does this issue reproduce with the latest release?

Yes,always.

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/gao/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/gao/go:/Users/gao/xng/xngo"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11/libexec/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/9m/_jx550mn55x8mjzz6tgtnjph0000gn/T/go-build384560299=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

format *.go which is like this

package utils

func init() {
	a := 1
	_ = 
}

Yes,there is an syntax error.

What did you expect to see?

I expect to see gofmt does nothing

What did you see instead?

package utils

func init() {
	a: = 1
	_ = 
}

gofmt insert a space between : and = .Sometimes when i open a big file with a syntax and press save,gofmt will change the code.Then i have to replace : = with := .

@ALTree
Copy link
Member

ALTree commented Sep 9, 2018

Mh, I can't reproduce this:

$ cat test.go
package utils

func init() {
a := 1
_ =
}

$ gofmt test.go
test.go:6:1: expected operand, found '}'
test.go:7:2: expected ';', found 'EOF'

$ cat test.go 
package utils

func init() {
a := 1
_ =
}

What am I missing? Are you sure it's gofmt that is doing this?

@ALTree ALTree changed the title insert space between : and = when syntax error cmd/gofmt: insert space between : and = when syntax error Sep 9, 2018
@ALTree ALTree added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 9, 2018
@dav-m85
Copy link

dav-m85 commented Sep 9, 2018

@ALTree I have this exact issue when using Visual Studio Code (Version 1.27.1) with ms-vscode.go extension installed. This extension advertise to be using gomft in the background.

However, the issue does not appear when using directly gofmt in the shell (I can run your example and everything is fine), so I suspect something on extension's side. I'll dig deeper.

@jingyugao Is that your use case as well ?

@dav-m85
Copy link

dav-m85 commented Sep 9, 2018

I resolved my issue: it was a conflict between two formatting extensions in Visual Studio Code: ryannaddy.vscode-format and ms-vscode.go. I opened an issue for the first.

@jingyugao
Copy link
Author

@dav-m85 Thank you for your hint,I got the annswer.I use vscode-format extension. Gofmt is running ok after I remove the vscode-format.Thanks!

@jingyugao
Copy link
Author

I got why. Because I use vscode-format which ii conflicted with gofmt. Now gofmt is runniing well after I remove vscode-format

@golang golang locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants