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/go: go.mod formatting drops unattached comments within blocks #33280

Open
0xmohit opened this issue Jul 25, 2019 · 6 comments
Open

cmd/go: go.mod formatting drops unattached comments within blocks #33280

0xmohit opened this issue Jul 25, 2019 · 6 comments
Labels
help wanted modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@0xmohit
Copy link
Contributor

0xmohit commented Jul 25, 2019

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

$ go version
go version go1.13beta1 linux/amd64

Does this issue reproduce with the latest release?

Yes, happens with 1.12.6 too. Not tried with tip.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mohit/.cache/go-build"
GOENV="/home/mohit/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mohit/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go-1.13beta1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go-1.13beta1/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/exp/go.mod"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build485779267=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Executed go mod edit -fmt on the following. (The following is a minimal reproducible example of the actual go.mod file.)

module exp

go 1.13

require (
	foo v0.0.0-00010101000000-000000000000
	// bar v0.0.0-00010101000000-000000000000
)

What did you expect to see?

Perhaps no change.

What did you see instead?

The commented disappeared after formatting.

module exp

go 1.13

require foo v0.0.0-00010101000000-000000000000
@agnivade
Copy link
Contributor

Btw, your What did you do? section is wrong. The command is go mod edit -fmt, not go mod tidy -fmt as you have correctly mentioned in the title.

@agnivade agnivade added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 25, 2019
@0xmohit
Copy link
Contributor Author

0xmohit commented Jul 25, 2019

Btw, your What did you do? section is wrong. The command is go mod edit -fmt, not go mod tidy -fmt as you have correctly mentioned in the title.

It was a typo and was meant to be go mod edit -fmt.

@bcmills bcmills added this to the Go1.14 milestone Jul 25, 2019
@bcmills bcmills changed the title cmd/go: go mod edit -fmt can result in lost comments cmd/go: go.mod formatting drops unattached comments within blocks Sep 16, 2019
@bcmills bcmills modified the milestones: Go1.14, Unplanned Sep 16, 2019
@AndersonQ
Copy link
Contributor

As it looks stale I'll investigate

@quantonganh
Copy link
Contributor

Given the following go.mod:

module exp

go 1.13

require (
	// bar v0.0.0-00010101000000-000000000000
	foo v0.0.0-00010101000000-000000000000
)

Should we leave it as it is instead of collapsing into single line?

module exp

go 1.13

// bar v0.0.0-00010101000000-000000000000
require foo v0.0.0-00010101000000-000000000000

@quantonganh
Copy link
Contributor

I've created a CL to fix this: https://go-review.googlesource.com/c/mod/+/541815

@gopherbot
Copy link

Change https://go.dev/cl/545695 mentions this issue: modfile: do not collapse if there are unattached comments within blocks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted modules 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

6 participants