Skip to content

modfile: fix trailing empty lines in require blocks #22

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modfile/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,11 @@ func (in *input) parseLineBlock(start Position, token []string, lparen token) *L
in.Error(fmt.Sprintf("syntax error (unterminated block started at %s:%d:%d)", in.filename, x.Start.Line, x.Start.LineRune))
case ')':
rparen := in.lex()
// Don't preserve blank lines (denoted by a single empty comment, added above)
// at the end of the block.
if len(comments) == 1 && comments[0] == (Comment{}) {
comments = nil
}
x.RParen.Before = comments
x.RParen.Pos = rparen.pos
if !in.peek().isEOL() {
Expand Down
7 changes: 7 additions & 0 deletions modfile/testdata/issue70632.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module tidy

go 1.23.0

require (
golang.org/x/time v0.8.0
)
12 changes: 12 additions & 0 deletions modfile/testdata/issue70632.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module tidy

go 1.23.0

require (

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




)