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
cn007b opened this issue Oct 1, 2018 · 5 comments

Comments

Projects
None yet
7 participants
@cn007b
Copy link
Contributor

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

@gopherbot gopherbot added the Proposal label Oct 1, 2018

@cznic

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Contributor

commented Oct 1, 2018

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

This comment has been minimized.

Copy link
Contributor

commented Oct 3, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.