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

go/format: line comment not indented properly after indented statement #67005

Open
willfaught opened this issue Apr 23, 2024 · 1 comment
Open
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@willfaught
Copy link
Contributor

willfaught commented Apr 23, 2024

Go version

go version go1.22.2 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/will/Library/Caches/go-build'
GOENV='/Users/will/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/will/Library/Application Support/go/pkg/mod'
GONOPROXY='github.com/FrontRowXP,github.com/frontrowxp'
GONOSUMDB='github.com/FrontRowXP,github.com/frontrowxp'
GOOS='darwin'
GOPATH='/Users/will/Library/Application Support/go'
GOPRIVATE='github.com/FrontRowXP,github.com/frontrowxp'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.2/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.2/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/will/Developer/work/backend/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/bx/qk0phsxd265fqj512dnnpg080000gp/T/go-build2316146393=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

https://go.dev/play/p/R-pGjxggfGk

Press Format.

What did you see happen?

// You can edit this code!
// Click here and start typing.
package main

import "fmt"

func main() {
	// PageContainer
	pageContainerFull := client.PageContainer.Create().
		SetChannelID(channelID).
		SetLanguage(pagecontainer.LanguageEN).
		SetTitle("Page Container Title").
		SaveX(ctx)

		// LocalPageContainer
	client.LocalPageContainer.Create().
		SetChannelID(channelID).
		SetPageContainerID(pageContainerFull.ID).
		SetLanguage(localpagecontainer.LanguageDE).
		SetTitle("Lokaler Seitentitel").
		ExecX(ctx)

	fmt.Println("Hello, 世界")
}

Note the extra indent before // LocalPageContainer.

What did you expect to see?

// You can edit this code!
// Click here and start typing.
package main

import "fmt"

func main() {
	// PageContainer
	pageContainerFull := client.PageContainer.Create().
		SetChannelID(channelID).
		SetLanguage(pagecontainer.LanguageEN).
		SetTitle("Page Container Title").
		SaveX(ctx)

	// LocalPageContainer
	client.LocalPageContainer.Create().
		SetChannelID(channelID).
		SetPageContainerID(pageContainerFull.ID).
		SetLanguage(localpagecontainer.LanguageDE).
		SetTitle("Lokaler Seitentitel").
		ExecX(ctx)

	fmt.Println("Hello, 世界")
}
@dmitshur
Copy link
Contributor

dmitshur commented Apr 24, 2024

This is similar to (or the same as) #12822 and likely some more gofmt issues. Also consider this instance:

switch {
case true:
	// comment 1
	// comment 2
	// comment 3
// comment 4
// comment 5
// comment 6
case false:
}

gofmt can't know that comments 1, 2, 3 are a part of the first case on the inside, while comments 4, 5, 6 are attached to the second case on top. So it just accepts both positions and doesn't change them.

@joedian joedian added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants