Skip to content

Commit eb3647b

Browse files
committed
Resolve comments
1 parent 9cdc3b8 commit eb3647b

File tree

4 files changed

+22
-59
lines changed

4 files changed

+22
-59
lines changed

modfile/read.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -877,14 +877,12 @@ func (in *input) parseLineBlock(start Position, token []string, lparen token) *L
877877
in.Error(fmt.Sprintf("syntax error (unterminated block started at %s:%d:%d)", in.filename, x.Start.Line, x.Start.LineRune))
878878
case ')':
879879
rparen := in.lex()
880-
// Filter out comments with Start.Line == 0
881-
var filteredComments []Comment
882-
for _, c := range comments {
883-
if c.Start.Line > 0 {
884-
filteredComments = append(filteredComments, c)
885-
}
880+
// Don't preserve blank lines (denoted by a single empty comment, added above)
881+
// at the end of the block.
882+
if len(comments) == 1 && comments[0] == (Comment{}) {
883+
comments = nil
886884
}
887-
x.RParen.Before = filteredComments
885+
x.RParen.Before = comments
888886
x.RParen.Pos = rparen.pos
889887
if !in.peek().isEOL() {
890888
in.Error("syntax error (expected newline after closing paren)")

modfile/read_test.go

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -734,55 +734,3 @@ func TestCleanupMaintainsRefs(t *testing.T) {
734734
t.Errorf("got:\n%v\nwant:\n%v", syntax.Stmt[0], lineB)
735735
}
736736
}
737-
738-
func TestCleanupRemoveRequireBlockBlankLines(t *testing.T) {
739-
syntax := &FileSyntax{
740-
Stmt: []Expr{
741-
&Line{
742-
Token: []string{"module", "a"},
743-
},
744-
&LineBlock{
745-
Token: []string{"require"},
746-
Line: []*Line{
747-
{
748-
Token: []string{"golang.org/x/time", "v0.8.0"},
749-
InBlock: true,
750-
},
751-
{
752-
Token: nil, // Blank line
753-
InBlock: true,
754-
},
755-
{
756-
Token: []string{"golang.org/x/other", "v0.1.0"},
757-
InBlock: true,
758-
},
759-
},
760-
},
761-
},
762-
}
763-
syntax.Cleanup()
764-
765-
buf := &bytes.Buffer{}
766-
for _, stmt := range syntax.Stmt {
767-
switch stmt := stmt.(type) {
768-
case *Line:
769-
fmt.Fprintf(buf, "line: %v\n", strings.Join(stmt.Token, " "))
770-
case *LineBlock:
771-
fmt.Fprintf(buf, "block: %v\n", strings.Join(stmt.Token, " "))
772-
for _, line := range stmt.Line {
773-
fmt.Fprintf(buf, "blockline: %v\n", strings.Join(line.Token, " "))
774-
}
775-
}
776-
}
777-
778-
got := strings.TrimSpace(buf.String())
779-
want := strings.TrimSpace(`
780-
line: module a
781-
block: require
782-
blockline: golang.org/x/time v0.8.0
783-
blockline: golang.org/x/other v0.1.0
784-
`)
785-
if got != want {
786-
t.Errorf("got:\n%s\nwant:\n%s", got, want)
787-
}
788-
}

modfile/testdata/issue70632.golden

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module tidy
2+
3+
go 1.23.0
4+
5+
require golang.org/x/time v0.8.0

modfile/testdata/issue70632.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module tidy
2+
3+
go 1.23.0
4+
5+
require (
6+
7+
"golang.org/x/time" v0.8.0
8+
9+
10+
11+
12+
)

0 commit comments

Comments
 (0)