golang / go

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

cmd/go: `go mod tidy` leaves trailing empty lines in `require` blocks #70632

Open thaJeztah opened 1 day ago

thaJeztah commented 1 day ago

Go version

go version go1.23.3 linux/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.23.3'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/root/.config/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2955114020=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Ran go mod tidy with a go.mod that contained a stray empty line in a require block

Reproduction steps

Create a minimal module with at least one dependency

mkdir tidy && cd tidy

cat > main.go <<'EOF'
package main

import (
    "fmt"

    "golang.org/x/time/rate"
)
var Foo = rate.Limit

func main() {
    fmt.Println("hello")
}
EOF

Create a go.mod with trailing empty lines in the require section;

cat > go.mod <<'EOF'
module tidy

go 1.23.0

require (
    "golang.org/x/time" v0.8.0

)
EOF

Run go mod tidy;

go mod tidy

Check the content of go.mod, and observe that an empty line is left behind in the require section;

cat go.mod
module tidy

go 1.23.0

require (
    golang.org/x/time v0.8.0

)

What did you see happen?

The empty line was kept even after running go mod tidy

What did you expect to see?

The empty line to be removed.

gabyhelp commented 1 day ago

Related Issues

Related Code Changes

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

mknyszek commented 22 hours ago

CC @golang/tools-team