-
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: unexpected formatting of comments #22334
Comments
This is just how it works. I don't think gofmt is anybody's favorite formatter. It's just good enough to be something that everyone can agree on. |
Interesting. This is actually working as intended. The problem is that the usual alignment computation breaks down when there's more then one entry per line. For comparison, see the result of this example where I made the lines all have one entry but have the same overall length: https://play.golang.org/p/4qanGJEhr1 . This time it works. @ianlancetaylor is correct, this is working as intended, even though it's unexpected. I will leave this open for now, perhaps there's a not too difficult way to fix this. |
Hey, That makes sense, I wouldn't normally do two things per line like this, but felt like it made sense for this code. Filed the bug purely because I thought the output looked like badly formatted code. When I get a free chunk of time I'll take a look at how it does it and see whether there is an easy and sane way to make it look nicer. Cheers, Hugh |
Also, what about the normal code formatting as below? Currently,
What is expected,
Is this type of formatting possible with |
@yogesh-desai gofmt doesn't do this now. It's possible to do it, but it requires a change. It's not a high priority. |
@griesemer I would like to help to solve it. Please let me know so can take care of this change. |
@yogesh-desai Thanks for your offer, but not now. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.9.1 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
The following code (https://play.golang.org/p/yWr8ET9ZUg) is laid out with comments as I would expect:
However, the output of
gofmt
gives the following (https://play.golang.org/p/My_W9bkZrY):It seems to appear that the first two lines are treated as one block, the third line by itself, and the last three lines are treated as another block.
What did you expect to see?
I would expect no change in the formating of the comments
What did you see instead?
The comments changed, as shown above.
First time bug for me, so hopefully this is OK. Let me know if there is anything more you need. I'm also keen to help fix it, but I'm also new to go so may take a while :)
Cheers,
Hugh
The text was updated successfully, but these errors were encountered: