-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: slice of structs not consistently formatted #34582
Comments
/cc @griesemer |
Both
and To make different styles fall to a single one in a single declaration, we would have to keep track of braces and their positions and then possibly go backwards and change token positions. Up to Robert to decide to do it or not. |
I personally think this would be nice to have, if it doesn't add a lot of complexity to gofmt. |
Nice to have, but complicated to get right, I suspect. In general, where multiple formats are accepted, we defer to the user. |
I've implemented a prototype at mvdan/gofumpt@5d37481 if anyone wants to play with it. The solution is pretty straightforward there, but I already had some logic to determine if a composite literal had any newlines between its elements. |
Thank you for working on this!
is applied in all cases. For example,
It is not obvious to me that the above literal gets reformatted into
What gets determined to be the consistent style? The only one I can think of is the style of the first element in the list gets applied to the subsequent elements. |
Thanks for the report, @smasher164. Let's take this to mvdan/gofumpt#36, since the bug doesn't concern gofmt. |
See https://play.golang.org/p/uwG_GFPiU13.
I expected the literal to be reformatted like this:
instead, it preserves the previous formatting.
Is this intentional? Or does it make sense to keep the formatting of structs in the slice the same?
The text was updated successfully, but these errors were encountered: