golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.9k stars 17.65k forks source link

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

Open 0xmohit opened 5 years ago

0xmohit commented 5 years ago

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 commented 5 years ago

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.

0xmohit commented 5 years ago

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.

AndersonQ commented 5 years ago

As it looks stale I'll investigate

quantonganh commented 11 months ago

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 commented 11 months ago

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

gopherbot commented 11 months ago

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