Skip to content

go/doc: requires 2 pass for multiline comments with spacing #67020

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

Open
davewalker-wk opened this issue Apr 24, 2024 · 4 comments
Open

go/doc: requires 2 pass for multiline comments with spacing #67020

davewalker-wk opened this issue Apr 24, 2024 · 4 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@davewalker-wk
Copy link

davewalker-wk commented Apr 24, 2024

Go version

Go 1.22

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/davewalker/Library/Caches/go-build'
GOENV='/Users/davewalker/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/davewalker/src/go/pkg/mod'
GONOPROXY='github.com/Workiva'
GONOSUMDB='github.com/Workiva'
GOOS='darwin'
GOPATH='/Users/davewalker/src/go'
GOPRIVATE='github.com/Workiva'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/opt/go/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/opt/go/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/davewalker/src/go/src/github.com/Workiva/fmttest/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/mv/8cw5jx652lg0hyrqjn28dctc0000gs/T/go-build2871199811=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

package main

/*
    This is a multiline comment with
    things
  */
func A() {}

The file above needs to have go fmt run twice on it to be formatted properly. Discovered via go/format package with format.Source() where read in AST comments are improperly formatted after a single pass.

What did you see happen?

After the first go fmt

package main

/*
	This is a multiline comment with
	things
*/
func A() {}

After the second go fmt

package main

/*
This is a multiline comment with
things
*/
func A() {}

What did you expect to see?

An idempotent formatter that can format source in one pass.

@davewalker-wk davewalker-wk changed the title go/format: requires 2 pass for multiline comments with spacing go/format cmd/gofmt: requires 2 pass for multiline comments with spacing Apr 24, 2024
@seankhliao
Copy link
Member

seems to be single pass? https://go.dev/play/p/a1kbFn5Nn0Y

@davewalker-wk
Copy link
Author

davewalker-wk commented Apr 24, 2024

I am not seeing the behavior you show on go.dev (via format button), via the command line, or through format.Source on my mac.

davewalker@WK01450:~/src/go/src/github.com/Workiva/fmttest › cat example.go 
package main

/*
    This is a multiline comment with
    things
  */
func A() {}
davewalker@WK01450:~/src/go/src/github.com/Workiva/fmttest › go fmt example.go 
example.go
davewalker@WK01450:~/src/go/src/github.com/Workiva/fmttest › cat example.go 
package main

/*
        This is a multiline comment with
        things
*/
func A() {}
davewalker@WK01450:~/src/go/src/github.com/Workiva/fmttest › go fmt example.go 
example.go
davewalker@WK01450:~/src/go/src/github.com/Workiva/fmttest › cat example.go 
package main

/*
This is a multiline comment with
things
*/
func A() {}
davewalker@WK01450:~/src/go/src/github.com/Workiva/fmttest › 

@davewalker-wk
Copy link
Author

davewalker-wk commented Apr 25, 2024

See also, behavior of this issue

https://go.dev/play/p/Njt9xThTdes

@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 26, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/583235 mentions this issue: go/doc: Skip whitespace lines in common prefix calculation

@seankhliao seankhliao changed the title go/format cmd/gofmt: requires 2 pass for multiline comments with spacing go/doc: requires 2 pass for multiline comments with spacing May 4, 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

4 participants