Open acanalis opened 3 years ago
As you have correctly pointed out, https://github.com/golang/go/issues/5128 is the overall issue that tracks this. It is a problem that we've had for quite a while, and unfortunately, using inline comments are the only available workaround as of now.
As you have correctly pointed out, #5128 is the overall issue that tracks this. It is a problem that we've had for quite a while, and unfortunately, using inline comments are the only available workaround as of now.
That issue is about whether or not block comments should be formatted. The topic shifted during the years and it's now 8 years old. Some code examples don't apply any more. In general I'm not against formatting block comments because the use is almost always within documentation headers.
This issue in turn is about allowing go fmt
and go test
to work together in a way that allows writing longer examples.
I'd rather keep them separate from each other, if possible.
I'll defer to @griesemer on whether to track this separately or merge with the parent.
Fine to leave as a separate issue. At some point (maybe when doing whatever is needed to fine-tune generics gofmt output) we need to look at all these gofmt
issues.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
As per the guide "Testable examples in Go", I wrote a test file
example_test.go
inside an empty directory as the following:Run
go fmt
and thengo test
:What did you expect to see?
What did you see instead?
After running
go fmt
(see on playground) , the program becomes:The change of indentation of the line
A*
seems to make the test fail:Relevant issues & workarounds:
https://github.com/golang/go/issues/41980 https://github.com/golang/go/issues/5128#issuecomment-708940093 https://github.com/golang/go/issues/6416
The problem can be worked around by using inline comments (
//
), which don't depend on formatting. This runs ok before and after gofmt:However, this isn't satisfactory because it would make very difficult to check output longer that a couple of lines.