modfile: replace empty comments when adding indirect

When we add an "indirect" token to a line with an empty comment (only
whitespace after //), we should replace the comment text.

In CL 208273, we inserted "indirect;". The isIndirect predicate returns
false for "// indirect;" because there's only one word. When
modload.WriteGoMod is called multiple times (as it is in
'go mod tidy'), this caused us to write "// indirect; indirect".

Updates golang/go#35737

Change-Id: Ic2531a61ab15df7a0d4462ea3b1d25753d06d1d1
Reviewed-on: https://go-review.googlesource.com/c/mod/+/208671
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2 files changed