modfile: take into account that // indirect comments may not be well formatted

When there is an // indirect comment next to a dependency that is not actually indirect;
go mod tidy should remove it.
This was not the case when the //indirect comment was badly formatted.

We now check whether such a comment exists irrespective of the formatting.

Updates golang/go#45932

Change-Id: I6a7dca23059a0aca6f8f940da975a0d79f701571
GitHub-Last-Rev: b884ee1a3ecf821f9b6b68bf061bbe0c521c8143
GitHub-Pull-Request: golang/mod#3
Reviewed-by: Bryan C. Mills <>
Trust: Bryan C. Mills <>
Trust: Jay Conrod <>
2 files changed
tree: 54741f5e2605404d4d07ec194b421602a4be7ab5
  4. codereview.cfg
  5. go.mod
  6. go.sum
  7. gosumcheck/
  8. internal/
  9. modfile/
  10. module/
  11. semver/
  12. sumdb/
  13. zip/



This repository holds packages for writing tools that work directly with Go module mechanics. That is, it is for direct manipulation of Go modules themselves.

It is NOT about supporting general development tools that need to do things like load packages in module mode. That use case, where modules are incidental rather than the focus, should remain in x/tools, specifically x/tools/go/packages.

The specific case of loading packages should still be done by invoking the go command, which remains the single point of truth for package loading algorithms.