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: bad indenting of map literals as chained method arguments #6409

Closed
gopherbot opened this issue Sep 17, 2013 · 10 comments
Closed

cmd/gofmt: bad indenting of map literals as chained method arguments #6409

gopherbot opened this issue Sep 17, 2013 · 10 comments
Assignees
Milestone

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 17, 2013

by cfbradford:

What steps will reproduce the problem?
Format this code: http://play.golang.org/p/GIcbfEeB5E


What is the expected output?
lines 22-25 should be indented one more level

This seems to have something to do with the combination of a map literal in the middle
of a set of chained method calls.


(There also seems to be something funky going on with the Playground. If you try to run
this code that does nothing you get an "out of memory" error message.)
@robpike
Copy link
Contributor

@robpike robpike commented Sep 17, 2013

Comment 1:

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.

@gopherbot
Copy link
Author

@gopherbot gopherbot commented Sep 17, 2013

Comment 2 by cfbradford:

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.
@gopherbot
Copy link
Author

@gopherbot gopherbot commented Sep 17, 2013

Comment 3 by cfbradford:

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
@rsc
Copy link
Contributor

@rsc rsc commented Nov 27, 2013

Comment 4:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

@rsc rsc commented Dec 4, 2013

Comment 5:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

@rsc rsc commented Dec 4, 2013

Comment 6:

Labels changed: added repo-main.

@gopherbot
Copy link
Author

@gopherbot gopherbot commented May 10, 2014

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!
@griesemer
Copy link
Contributor

@griesemer griesemer commented Sep 10, 2014

Comment 8:

Owner changed to @griesemer.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@agnivade
Copy link
Contributor

@agnivade agnivade commented May 2, 2018

What steps will reproduce the problem?
Format this code: http://play.golang.org/p/GIcbfEeB5E
What is the expected output?
lines 22-25 should be indented one more level

Seems fixed now. Please reopen if you think otherwise.

@agnivade agnivade closed this May 2, 2018
@griesemer
Copy link
Contributor

@griesemer griesemer commented May 2, 2018

@agnivade LGTM. Thanks for checking this!

@golang golang locked and limited conversation to collaborators May 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.