mirror of
https://github.com/golang/go
synced 2024-11-25 06:47:56 -07:00
gofmt: make sure certain 2-line comments are stable
under repeated application of gofmt R=agl, agl1 CC=golang-dev https://golang.org/cl/212046
This commit is contained in:
parent
fb5506600f
commit
1cf6fdf8a1
@ -429,6 +429,7 @@ func stripCommonPrefix(lines [][]byte) {
|
||||
if len(lines) < 2 {
|
||||
return // at most one line - nothing to do
|
||||
}
|
||||
// len(lines) >= 2
|
||||
|
||||
// The heuristic in this function tries to handle a few
|
||||
// common patterns of /*-style comments: Comments where
|
||||
@ -441,19 +442,29 @@ func stripCommonPrefix(lines [][]byte) {
|
||||
// Compute maximum common white prefix of all but the first,
|
||||
// last, and blank lines, and replace blank lines with empty
|
||||
// lines (the first line starts with /* and has no prefix).
|
||||
// In case of two-line comments, consider the last line for
|
||||
// the prefix computation since otherwise the prefix would
|
||||
// be empty.
|
||||
//
|
||||
// Note that the first and last line are never empty (they
|
||||
// contain the opening /* and closing */ respectively) and
|
||||
// thus they can be ignored by the blank line check.
|
||||
var prefix []byte
|
||||
for i, line := range lines {
|
||||
if len(lines) > 2 {
|
||||
for i, line := range lines[1 : len(lines)-1] {
|
||||
switch {
|
||||
case i == 0 || i == len(lines)-1:
|
||||
// ignore
|
||||
case isBlank(line):
|
||||
lines[i] = nil
|
||||
lines[i+1] = nil
|
||||
case prefix == nil:
|
||||
prefix = commonPrefix(line, line)
|
||||
default:
|
||||
prefix = commonPrefix(prefix, line)
|
||||
}
|
||||
}
|
||||
} else { // len(lines) == 2
|
||||
line := lines[1]
|
||||
prefix = commonPrefix(line, line)
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for vertical "line of stars" and correct prefix accordingly.
|
||||
|
92
src/pkg/go/printer/testdata/comments.golden
vendored
92
src/pkg/go/printer/testdata/comments.golden
vendored
@ -217,6 +217,80 @@ func _() {
|
||||
aligned line */
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line */
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line */
|
||||
}
|
||||
|
||||
|
||||
func _() {
|
||||
/*
|
||||
freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/*
|
||||
freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/*
|
||||
freestanding comment
|
||||
aligned line */
|
||||
}
|
||||
|
||||
func _() {
|
||||
/*
|
||||
freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/*
|
||||
freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/*
|
||||
freestanding comment
|
||||
aligned line */
|
||||
}
|
||||
|
||||
/*
|
||||
* line
|
||||
@ -232,6 +306,24 @@ func _() {
|
||||
* of
|
||||
* stars */
|
||||
|
||||
/* a line of
|
||||
* stars */
|
||||
|
||||
/* and another line of
|
||||
* stars */
|
||||
|
||||
/* a line of stars
|
||||
*/
|
||||
|
||||
/* and another line of
|
||||
*/
|
||||
|
||||
/* a line of stars
|
||||
*/
|
||||
|
||||
/* and another line of
|
||||
*/
|
||||
|
||||
/*
|
||||
aligned in middle
|
||||
here
|
||||
|
92
src/pkg/go/printer/testdata/comments.input
vendored
92
src/pkg/go/printer/testdata/comments.input
vendored
@ -217,6 +217,80 @@ func _() {
|
||||
aligned line */
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line */
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line */
|
||||
}
|
||||
|
||||
|
||||
func _() {
|
||||
/*
|
||||
freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/*
|
||||
freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/*
|
||||
freestanding comment
|
||||
aligned line */
|
||||
}
|
||||
|
||||
func _() {
|
||||
/*
|
||||
freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/*
|
||||
freestanding comment
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/*
|
||||
freestanding comment
|
||||
aligned line */
|
||||
}
|
||||
|
||||
/*
|
||||
* line
|
||||
@ -232,6 +306,24 @@ func _() {
|
||||
* of
|
||||
* stars */
|
||||
|
||||
/* a line of
|
||||
* stars */
|
||||
|
||||
/* and another line of
|
||||
* stars */
|
||||
|
||||
/* a line of stars
|
||||
*/
|
||||
|
||||
/* and another line of
|
||||
*/
|
||||
|
||||
/* a line of stars
|
||||
*/
|
||||
|
||||
/* and another line of
|
||||
*/
|
||||
|
||||
/*
|
||||
aligned in middle
|
||||
here
|
||||
|
Loading…
Reference in New Issue
Block a user