Open dmitshur opened 9 years ago
I probably went overboard trying to recognize the "Line of stars".
This might be easily fixable by recognizing the "Line of stars" only if stars followed by text have a blank after the star. Of course, for "* p = 0" this would still fail, but people tend to write "p" rather than " p".
Another option might be to simply remove the "Line of stars" logic.
Not urgent.
This might be easily fixable by recognizing the "Line of stars" only if stars followed by text have a blank after the star. Of course, for "* p = 0" this would still fail, but people tend to write "p" rather than " p".
Yep.
Another option might be to simply remove the "Line of stars" logic.
I was thinking that too, and if possible, I think it's a better solution because it's a chance to make Go a little simpler. I've seen a lot of Go code, and line of stars is exceedingly rare. It seems it'd be better not to have it.
Not urgent.
Agreed. I filed this simply to track the issue, since I had encountered it just recently.
What version of Go are you using (go version)?
What operating system and processor architecture are you using?
OS X 10.10.5, amd64.
What did you do?
Consider the following program:
If you comment out the first block of code and run
gofmt
on it, you get:However, if you comment out the second block of code like this:
What did you expect to see?
After formatting the above code with
gofmt
, I would expect it to be formatted similarly to when any other piece of code is commented out, so it should be:What did you see instead?
Which is not consistent with anything.
I'm pretty sure I know why it happens. It has to do with go/printer detecting a so called "line of stars" style of comments, which normally look like this:
See relevant code at https://github.com/golang/go/blob/467a2cb73ca867ccdb1dd22be220fa51b6d52491/src/go/printer/printer.go#L529-L539.
However, in this case, it's not a comment block because there is no space after the * as in normally formatted comments, it's just commented out code that happens to falsely trigger the line of stars comment block handling.