-
Notifications
You must be signed in to change notification settings - Fork 18.1k
cmd/go: 'go mod tidy' may delete comments on require blocks #47563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Change https://golang.org/cl/340349 mentions this issue: |
What happens if we also add other new modules in the same block, or delete some of the modules from the original block and retain the rest? If we add other new ones, we have no way to know whether the comment applies to them. I guess deletion should theoretically be ok, though. But what if the comment says something like Honestly, I would rather we just retain the empty
|
Or, another option might be to avoid moving a dependency between blocks if its existing That would potentially introduce mixed-dependency blocks where they were previously single-kind, but would always preserve the block comments that apply to a given dependency — even if its classification changes, and even if other requirements are added or removed in the same block at the same time. |
On balance, I think I prefer the latter approach. Let's just keep a dependency in the same |
Similarly, perhaps we shouldn't add new dependencies into an existing block with a block comment. |
I like the simplicity of not moving directives into or out of |
@bcmills In this case,What do we expect to see?
A:
B:
C:
D:
|
Change https://golang.org/cl/343431 mentions this issue: |
Change https://golang.org/cl/343432 mentions this issue: |
…ntly SetRequireSeparateIndirect now makes a stronger attempt to keep automatically added requirements in two blocks: one containing only direct requirements and one containing only indirect requirements. SetRequireSeparateIndirect will find or add these two blocks (commented blocks are left alone). New requirements are added to one of these two blocks. Existing requirements may be moved between these two blocks if their markings change. SetRequireSeparateIndirect attempts to preserve existing structure in the file by not adding requirements to or moving requirements from blocks with block-level comments and blocks other than the last uncommented direct-only and indirect-only block. As an exception to aid with migration, if the file contains a single uncommented block of requirements (as would the be the case if the user started with a 1.16 go.mod file, changed the go directive to 1.17, then ran 'go mod tidy'), SetRequireSeparateIndirect will split the block into direct-only and indirect-only blocks. This is a change in behavior, but it has no semantic effect, and it should result in cleaner, more stable go.mod files. For golang/go#47563 For golang/go#47733 Change-Id: Ifa20bb084c6bdaf1e00140600380857de8afa320 Reviewed-on: https://go-review.googlesource.com/c/mod/+/343431 Trust: Jay Conrod <[email protected]> Trust: Bryan C. Mills <[email protected]> Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
1.17+ only, in a module with
go 1.17
or higherWhat operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have a
go.mod
file with some manual edits. Arequire
block contains requirements are all either lacking an// indirect
comment when they should have it, or vice versa. Therequire
block itself has a comment.go mod tidy
moves all the requirements to a new block that does not have the comment above it.What did you expect to see?
In the example above, the
// don't delete me
comment is preserved.What did you see instead?
The new
go.mod
file does not contain the// don't delete me
comment.This happens in
modfile.SetRequireSeparateIndirect
.I think it makes sense to delete the block-level comments if the
require
directives are moved to other existing blocks. However, if all of the requirements in a block are moved to a new block, and the old block is delete, the new block should inherit the comments from the old block.cc @bcmills @matloob
The text was updated successfully, but these errors were encountered: