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: Invalid go fmt comment formatting after unicode string #73105

Closed
michaelchisari opened this issue Mar 30, 2025 · 2 comments
Closed
Labels
BugReport Issues describing a possible bug in the Go implementation.

Comments

@michaelchisari
Copy link

michaelchisari commented Mar 30, 2025

Go version

go version go1.24.1 darwin/arm64

Output of go env in your module/workspace:

R='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/mcc/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/mcc/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/vc/z1wsvwn129n_fg21ln0vn3bw0000gn/T/go-build146009728=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/Users/mcc/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/mcc/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.24.1/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/mcc/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Create a simple file with comments after unicode strings:

tmp.go

package main

import "fmt"

func main() {
	fmt.Println("Hello, World") // note
	fmt.Println("Hello, World!") // note
	fmt.Println("Hello, 世界") // note
}

Now run:

go fmt tmp.go

What did you see happen?

The output is aligned incorrectly:

  fmt.Println("Hello, World")  // note                                          
  fmt.Println("Hello, World!") // note                                          
  fmt.Println("Hello, 世界")     // note

What did you expect to see?

The output should format the comments to properly align, such as:

  fmt.Println("Hello, World")  // note                                          
  fmt.Println("Hello, World!") // note                                          
  fmt.Println("Hello, 世界")    // note
@michaelchisari michaelchisari changed the title import/path: Invalid go fmt formatting for unicode strings import/path: Invalid go fmt comment formatting after unicode string Mar 30, 2025
@michaelchisari michaelchisari changed the title import/path: Invalid go fmt comment formatting after unicode string cmd/gofmt: Invalid go fmt comment formatting after unicode string Mar 30, 2025
@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Mar 30, 2025
@robpike
Copy link
Contributor

robpike commented Mar 30, 2025

In general this would require knowing the widths of all the glyphs in your font, including what happens with combining characters, bidi characters, and so on. It's very hard and bordering on infeasible for a tool that does not control the display at pixel level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation.
Projects
None yet
Development

No branches or pull requests

4 participants