Skip to content

Commit aa51b25

Browse files
quantonganhgopherbot
authored andcommitted
modfile: do not collapse if there are unattached comments within blocks
The existing implementation drops unattached comments when collapsing block into single line. Fixes #33280 Change-Id: I388e1468657d461cba771e90d5e328746d927ae2 Reviewed-on: https://go-review.googlesource.com/c/mod/+/541815 Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 87140ec commit aa51b25

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

modfile/read.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func (x *FileSyntax) Cleanup() {
225225
if ww == 0 {
226226
continue
227227
}
228-
if ww == 1 {
228+
if ww == 1 && len(stmt.RParen.Comments.Before) == 0 {
229229
// Collapse block into single line.
230230
line := &Line{
231231
Comments: Comments{

modfile/rule_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ var addRequireTests = []struct {
9090
)
9191
`,
9292
},
93+
{
94+
`unattached_comments`,
95+
`
96+
module m
97+
require (
98+
foo v0.0.0-00010101000000-000000000000
99+
// bar v0.0.0-00010101000000-000000000000
100+
)
101+
`,
102+
"foo", "v0.0.0-00010101000000-000000000000",
103+
`
104+
module m
105+
require (
106+
foo v0.0.0-00010101000000-000000000000
107+
// bar v0.0.0-00010101000000-000000000000
108+
)
109+
`,
110+
},
93111
}
94112

95113
type require struct {

0 commit comments

Comments
 (0)