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

go/printer: wonky alignment when mixing embedded and typed fields along with struct tags in a struct definition #7199

Open
gopherbot opened this issue Jan 23, 2014 · 2 comments
Milestone

Comments

@gopherbot
Copy link

by cudmore.mb:

*What steps will reproduce the problem?*
1. Format http://play.golang.org/p/jzmwwldMwt
2. Format 

*What is the expected output?*
{{{
type Field struct {
    ID       `json:"UID"` // comment
    Label ID `json:"Lbl"` // comment
    *N                    // comment

    Value string `json:"Val"`
    Inheritable  `json:"Inh"` // comment

    a int // comment
    b string
    c int // comment
}
}}}

*What do you see instead?*
{{{
type Field struct {
    ID    `json:"UID"` // comment
    Label ID           `json:"Lbl"` // comment
    *N                 // comment

    Value       string       `json:"Val"`
    Inheritable `json:"Inh"` // comment

    a int // comment
    b string
    c int // comment
}
}}}

*Which version are you using?*
go1.2

I opened a discussion on this here:
https://groups.google.com/d/topic/golang-nuts/5RlC11J7XNE/discussion

It would be great if go fmt would align the parts of field definitions by kind (type,
tag, comment), rather than by index (first parts align, second parts), across contiguous
field definitions until an intermittent newline or comment.

The type of anonymous fields would be regarded as the field name, and would not
contribute to computing the alignment of the types. All types in a contiguous list of
fields would align to the rightmost, and then all tags, and then all comments.

However, this does get tricky: http://play.golang.org/p/Z_OPEbej-v
@gopherbot
Copy link
Author

Comment 1 by cudmore.mb:

Turns out the Wiki formatting doesn't apply here. Sorry about that.

@minux
Copy link
Member

minux commented Jan 24, 2014

Comment 2:

Labels changed: added release-none, repo-main.

Owner changed to @griesemer.

Status changed to Accepted.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@griesemer griesemer modified the milestones: Unplanned, Go1.11 Apr 4, 2018
@agnivade agnivade changed the title go/printer: wonky alignment of the parts of struct field definitions go/printer: wonky alignment when mixing embedded and typed fields along with struct tags in a struct definition May 7, 2018
@griesemer griesemer modified the milestones: Go1.11, Go1.12 Jun 27, 2018
@griesemer griesemer modified the milestones: Go1.12, Go1.13 Dec 11, 2018
@griesemer griesemer modified the milestones: Go1.13, Go1.14 May 6, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants