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/gofmt: align struct tag of embedded type with surrounding fields #51598

Open
dolmen opened this issue Mar 10, 2022 · 3 comments
Open

cmd/gofmt: align struct tag of embedded type with surrounding fields #51598

dolmen opened this issue Mar 10, 2022 · 3 comments
Labels
NeedsInvestigation

Comments

@dolmen
Copy link
Contributor

@dolmen dolmen commented Mar 10, 2022

Struct tag of embedded types is not aligned with tags of surrounding struct fields.

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

$ go version
go version go1.17.8 darwin/amd64

Does this issue reproduce with the latest release?

Yes (1.17.8).

Also gotip on the Go Playground.

What did you do?

Apply gofmt to the following code.

type B string

type _ struct {
	A string `json:"a"`
	B `json:"b"`
	C int     `json:"c"`
	D float32 `json:"d"`
}

Use the 'Format' button on the Go Playground.

What did you expect to see?

type _ struct {
	A string  `json:"a"`
	B         `json:"b"`
	C int     `json:"c"`
	D float32 `json:"d"`
}

What did you see instead?

No change in formatting.

type _ struct {
	A string `json:"a"`
	B `json:"b"`
	C int     `json:"c"`
	D float32 `json:"d"`
}
@dolmen dolmen changed the title gofmt: align tag of embedded type with surrounding fields gofmt: align struct tag of embedded type with surrounding fields Mar 10, 2022
@mengzhuo mengzhuo added the NeedsInvestigation label Mar 11, 2022
@mengzhuo
Copy link
Contributor

@mengzhuo mengzhuo commented Mar 11, 2022

CC @griesemer @mvdan per owner

@mvdan
Copy link
Member

@mvdan mvdan commented Mar 11, 2022

I think this makes sense. One could think that breaking the alignment draws attention to the embedded field, making it stand out more, but I don't imagine that was intentional.

Beware that the vertical alignment, such as with inline comments, is based on a heuristic and may be broken if there's a sudden change in the amount of needed whitespace. I don't think that's happening here, but still worth keeping in mind.

@heavenisme

This comment was marked as off-topic.

@seankhliao seankhliao changed the title gofmt: align struct tag of embedded type with surrounding fields cmd/gofmt: align struct tag of embedded type with surrounding fields Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

4 participants