golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.3k stars 17.7k forks source link

go/printer: false positive for doc comment formatting on unindented input #52605

Open rsc opened 2 years ago

rsc commented 2 years ago

The added blank line in the comment shows that go/printer is treating this as a doc comment, even though it's not. It is being tricked by the lack of indentation, which I used as part of the signal for "top-level comment". Very minor, but should do better.

% cat /tmp/x.go
package p

type T struct {
// This is not
//  a doc comment.
X int
}
% gofmt /tmp/x.go
package p

type T struct {
    // This is not
    //
    //  a doc comment.
    X int
}
%
gopherbot commented 7 months ago

Change https://go.dev/cl/579978 mentions this issue: go/printer: fix false positive doc comment