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: bad indenting of map literals as chained method arguments #6409
Labels
Milestone
Comments
I admit that the formatting is ugly, but so is the code. Don't fight the system, use it. Build the template then call parse. http://play.golang.org/p/v5v6gLwNXi Chained calls are rare in Go outside of the template packages. Labels changed: added priority-someday, removed priority-triage. Status changed to Accepted. |
Even then, if the line breaks are changed back to the original code the problem persists: http://play.golang.org/p/uMLabL_UO5 When chained calls are used, breaking between calls seems like the most logical way to format code. If the template.FuncMap literal starts a line, then all is well: http://play.golang.org/p/6ZIbLjZfng As you say, chained calls aren't that common, and wouldn't even be needed here if there was a way to initialize a "common" object with a FuncMap before calling ParseFiles that didn't require creating a dummy template. (The way the template packages handle groups of templates seems very unintuitive to me. Having an explicit TemplateGroup object would make more sense I think and provide an easy way to setup a FuncMap and delimiters before parsing happens without needing any empty Template objects.) So, not a huge deal, just something I noticed while messing with my code. |
I suppose the best way to avoid the issue is to just pull the map literal out of the arguments list: http://play.golang.org/p/hX_Rxqhaev |
Comment 7 by sam@ward.io: Hi, I'm interested in seeing this issue fixed. I'm writing an application that uses chained calls with maps and funcs passed into them, and gofmt breaks their indentation. Chained calls themselves might be uncommon, but they can be justified, and in those cases the code should still be readable. I hope the Go team agrees! |
Owner changed to @griesemer. |
Seems fixed now. Please reopen if you think otherwise. |
@agnivade LGTM. Thanks for checking this! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by cfbradford:
The text was updated successfully, but these errors were encountered: