diff --git a/modfile/read.go b/modfile/read.go index 5b5bb5e..2205682 100644 --- a/modfile/read.go +++ b/modfile/read.go @@ -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{ diff --git a/modfile/rule_test.go b/modfile/rule_test.go index 96e0bfe..ca11d17 100644 --- a/modfile/rule_test.go +++ b/modfile/rule_test.go @@ -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 {