go: cmd/gofmt: reformats block comments
by borman@google.com:
What steps will reproduce the problem? Use /* */ for block comments. Example: func f() { /* * don't do this right now fmt.Printf(`a multi-line string`) */ return } Gofmt alters the content of the comment (which includes the /* and */). The first time gofmt is called it produces: func f() { /* * don't do this right now fmt.Printf(`a multi-line string`) */ return } and if called again it produces: func f() { /* * don't do this right now fmt.Printf(`a multi-line string`) */ return } gofmt should not have altered the comment in the first place. The /* was indented correctly up front.
About this issue
- Original URL
- State: open
- Created 11 years ago
- Reactions: 3
- Comments: 29 (23 by maintainers)
Commits related to this issue
- Add a failing test for golang/go#5128. — committed to shurcooL/play by dmitshur 9 years ago
- Add example test (#13) What: - Add example test. That test example is kind of blocked on; 1. https://github.com/golang/go/issues/41980 2. https://github.com/golang/go/issues/5128#issuecom... — committed to komuw/kama by komuw 4 years ago
It seems impossible, at least for me, to get the following reproducer test to pass; if you run
gofmt
before runninggo test
. Becausegofmt
will always reformat the// output
comment. And hence this sounds like a bug to me rather than a feature request.I have an Example test case:
The test case is passing, it’s no problem
but when I run go fmt, it constantly change the block comment to this style
and causing test case to FAIL;
wonder is it the same case here, is there any way to let go fmt not touching my block comment?
I just spent 1 hour trying to get gofmt to leave alone the
// output:
of a test example I was working on(https://github.com/golang/go/issues/41980), to no avail; until I searched and came across this issue.I feel like gofmt re-formatting block comments in the specific case of
// output:
of a test example should be a separate issue that should be decided on independent of this one. But maybe this is just my frustration showing.It is a real pain to work with multi-line
// output:
in example tests. I’m trying to assertYAML
value./* ... */
gets broken bygofmt
.//
per-line is unmanageable, I useGoland
to comment multiple lines with hotkey, but it does not add space between//
and line content.Currently I have to paste expected content, add
//
with hotkey and then replace//
to//
to make things work.I would appreciate that
gofmt
does not touch comments following// output:
.