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

proposal: cmd/go: go fmt - align all labels #27949

Closed
cn0047 opened this issue Oct 1, 2018 · 5 comments
Closed

proposal: cmd/go: go fmt - align all labels #27949

cn0047 opened this issue Oct 1, 2018 · 5 comments

Comments

@cn0047
Copy link
Contributor

cn0047 commented Oct 1, 2018

Does it make sense to improve go fmt and align all struct's labels not only first one:

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

go version go1.11 darwin/amd64

Does this issue reproduce with the latest release?

yes

What did you do?

go fmt

What did you expect to see?

type MyData struct {
  ID        string `json:"id"         datastore:"id"`
  FirstName string `json:"first_name" datastore:"first_name"`
}

What did you see instead?

type MyData struct {
  ID        string `json:"id" datastore:"id"`
  FirstName string `json:"first_name" datastore:"first_name"`
}
@gopherbot gopherbot added this to the Proposal milestone Oct 1, 2018
@cznic
Copy link
Contributor

cznic commented Oct 1, 2018

The string field tag has no defined format. gofmt has no idea what the content of the struct tag will be used for and it is never safe to modify it in any way by a program which purpose is to canonicalize white space between tokens.

@agnivade
Copy link
Contributor

agnivade commented Oct 1, 2018

Yes, technically the entire text between `` is a single tag. Anything inside that is free-form text. So gofmt should not perform anything inside that.

I think there are several proposals to make tags typed. Before that, I don't think we should do any sort of parsing of tags.

@mvdan
Copy link
Member

mvdan commented Oct 1, 2018

I'll leave it to @griesemer to make the final decision, but I agree that this is not a job for gofmt. It works on syntax alone, and the program is not supposed to modify arbitrary literals.

@griesemer
Copy link
Contributor

The language spec doesn't say anything about the contents of field tags; thus gofmt cannot make assumptions about their content.

It's fine if someone wants to use a tool that does this alignment, but it should be separate and must be used with knowledge of the tag's content.

@rsc
Copy link
Contributor

rsc commented Oct 3, 2018

Agree that this is not gofmt's job. Declining per @griesemer's comment.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants