Skip to content
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

cmd/go: align comments in go.mod files #28513

Open
jerome-laforge opened this issue Oct 31, 2018 · 6 comments
Open

cmd/go: align comments in go.mod files #28513

jerome-laforge opened this issue Oct 31, 2018 · 6 comments
Labels
modules NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@jerome-laforge
Copy link

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

Go 1.11

Does this issue reproduce with the latest release?

yes

What did you do?

go mod init
go mod tidy

What did you expect to see?

Into go.mod, is it possible to have (like into comment into source code) align of // indirect

module myModule

require (
	github.com/something v1.0.0
	github.com/foo v1.0.0       // indirect
	github.com/foo/bar v1.0.0   // indirect	
)

What did you see instead?

module myModule

require (
	github.com/something v1.0.0
	github.com/foo v1.0.0  // indirect
	github.com/foo/bar v1.0.0 // indirect	
)
@katiehockman katiehockman changed the title go.mod: Align // indirect as coment into source code cmd/go: Align // indirect as coment into source code Oct 31, 2018
@katiehockman katiehockman added this to the Unplanned milestone Oct 31, 2018
@mvdan mvdan added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Oct 31, 2018
@mvdan
Copy link
Member

mvdan commented Oct 31, 2018

/cc @bcmills @rsc to see if we actually want to do this.

@rogpeppe
Copy link
Contributor

rogpeppe commented Oct 31, 2018

Personally, I'm not a big fan of alignment like that. it messes up diffs - what would be a single-line addition or removal of a dependency becomes a change to every line with a // indirect comment on.

Also, hopefully, we'll see many less // indirect comments as time goes on and more and more repositories get go.mod files, so this will become less of an issue over time.

@jerome-laforge
Copy link
Author

Also, hopefully, we'll see many less // indirect comments as time goes on and more and more repositories get go.mod files, so this will become less of an issue over time.

It is appear to be acceptable.
Thx

@bcmills
Copy link
Contributor

bcmills commented Jan 17, 2019

As @rogpeppe notes, // indirect requirements should decrease over time.

(It's true that alignment add spurious diffs, but arguably diff -b — a.k.a. diff --ignore-space-change is a good default for Go development anyway, given gofmt.)

@bcmills bcmills changed the title cmd/go: Align // indirect as coment into source code cmd/go: align comments in go.mod files Jan 17, 2019
tbg added a commit to tbg/etcd that referenced this issue May 30, 2019
go-resty is imported under its old import path by grpc-gateway.
This works around that problem until we pick up a version of
grpc-gateway that has the imports fixed.

See: golang/go#28513
@Zsar
Copy link

Zsar commented Jan 17, 2022

FWIW: This does not only affect modules or "indirect" comments but in general all kinds of enumeration:

Before:

func notAnElementName(name string) bool {    
	return strings.HasSuffix(name, ",attr") ||  // names an attribute    
	       strings.HasSuffix(name, ",chardata") // not actually a name    
}

(first comment aligned by one space; second line indented by 1 tab and aligned by 7 spaces)

After:

func notAnElementName(name string) bool {
	return strings.HasSuffix(name, ",attr") || // names an attribute
		strings.HasSuffix(name, ",chardata") // not actually a name
}

(second line indented by 2 tabs; no alignment)

Now that's just two lines, but every other year one might have to handle a dozen+. Lack of alignment really hurts here. Struct tags do get alignment, so apparently someone had the same idea.
(... Of course, in the general case one probably does not want comments on adjacent lines to align - namely if the comments are not actually related.)

@mvdan
Copy link
Member

mvdan commented Jan 17, 2022

@Zsar that sounds like it should be a separate issue; the syntax and formatting of .go and .mod files are not related, even if they can look similar at times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modules NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

6 participants