Skip to content

Commit

Permalink
modfile: do not collapse if there are unattached comments within blocks
Browse files Browse the repository at this point in the history
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 <cherryyz@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
quantonganh authored and gopherbot committed Mar 15, 2024
1 parent 87140ec commit aa51b25
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modfile/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (x *FileSyntax) Cleanup() {
if ww == 0 {
continue
}
if ww == 1 {
if ww == 1 && len(stmt.RParen.Comments.Before) == 0 {
// Collapse block into single line.
line := &Line{
Comments: Comments{
Expand Down
18 changes: 18 additions & 0 deletions modfile/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ var addRequireTests = []struct {
)
`,
},
{
`unattached_comments`,
`
module m
require (
foo v0.0.0-00010101000000-000000000000
// bar v0.0.0-00010101000000-000000000000
)
`,
"foo", "v0.0.0-00010101000000-000000000000",
`
module m
require (
foo v0.0.0-00010101000000-000000000000
// bar v0.0.0-00010101000000-000000000000
)
`,
},
}

type require struct {
Expand Down

0 comments on commit aa51b25

Please sign in to comment.