mirror of
https://github.com/golang/go
synced 2024-11-22 00:14:42 -07:00
improved comment formatting:
- print comments line by line, strip common prefix but do not modify comment contents otherwise - align comments with subsequent keyword if indicated (e.g. case labels) - terminate "column section" after multi-line expressions for better alignment R=rsc http://go/go-review/1017002
This commit is contained in:
parent
09f4261841
commit
1e984cb913
File diff suppressed because it is too large
Load Diff
89
src/pkg/go/printer/testdata/comments.go
vendored
89
src/pkg/go/printer/testdata/comments.go
vendored
@ -124,7 +124,94 @@ func typeswitch(x interface{}) {
|
||||
default:
|
||||
// this comment should be indented
|
||||
}
|
||||
// this comment should be indented
|
||||
// this comment should not be indented
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
aligned line */
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
aligned line */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* line
|
||||
* of
|
||||
* stars
|
||||
*/
|
||||
|
||||
/* another line
|
||||
* of
|
||||
* stars */
|
||||
|
||||
/* and another line
|
||||
* of
|
||||
* stars */
|
||||
|
||||
/*
|
||||
aligned in middle
|
||||
here
|
||||
not here
|
||||
*/
|
||||
|
||||
/*
|
||||
blank line in middle:
|
||||
|
||||
with no leading spaces on blank line.
|
||||
*/
|
||||
|
||||
func _() {
|
||||
/*
|
||||
* line
|
||||
* of
|
||||
* stars
|
||||
*/
|
||||
|
||||
/*
|
||||
aligned in middle
|
||||
here
|
||||
not here
|
||||
*/
|
||||
|
||||
/*
|
||||
blank line in middle:
|
||||
|
||||
with no leading spaces on blank line.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
89
src/pkg/go/printer/testdata/comments.golden
vendored
89
src/pkg/go/printer/testdata/comments.golden
vendored
@ -122,7 +122,94 @@ func typeswitch(x interface{}) {
|
||||
default:
|
||||
// this comment should be indented
|
||||
}
|
||||
// this comment should be indented
|
||||
// this comment should not be indented
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
aligned line */
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
aligned line
|
||||
*/
|
||||
}
|
||||
|
||||
func _() {
|
||||
/* freestanding comment
|
||||
aligned line
|
||||
aligned line */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* line
|
||||
* of
|
||||
* stars
|
||||
*/
|
||||
|
||||
/* another line
|
||||
* of
|
||||
* stars */
|
||||
|
||||
/* and another line
|
||||
* of
|
||||
* stars */
|
||||
|
||||
/*
|
||||
aligned in middle
|
||||
here
|
||||
not here
|
||||
*/
|
||||
|
||||
/*
|
||||
blank line in middle:
|
||||
|
||||
with no leading spaces on blank line.
|
||||
*/
|
||||
|
||||
func _() {
|
||||
/*
|
||||
* line
|
||||
* of
|
||||
* stars
|
||||
*/
|
||||
|
||||
/*
|
||||
aligned in middle
|
||||
here
|
||||
not here
|
||||
*/
|
||||
|
||||
/*
|
||||
blank line in middle:
|
||||
|
||||
with no leading spaces on blank line.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
18
src/pkg/go/printer/testdata/expressions.go
vendored
18
src/pkg/go/printer/testdata/expressions.go
vendored
@ -159,12 +159,24 @@ func _() {
|
||||
c;
|
||||
_ = a < b ||
|
||||
b < a;
|
||||
_ = "1234567890"
|
||||
"1234567890";
|
||||
// this comment should be indented
|
||||
_ = "933262154439441526816992388562667004907159682643816214685929"
|
||||
"638952175999932299156089414639761565182862536979208272237582"
|
||||
"51185210916864000000000000000000000000"; // 100!
|
||||
_ = "170141183460469231731687303715884105727"; // prime
|
||||
}
|
||||
|
||||
|
||||
// Alignment after overlong lines
|
||||
const (
|
||||
_ = "991";
|
||||
_ = "2432902008176640000"; // 20!
|
||||
_ = "933262154439441526816992388562667004907159682643816214685929"
|
||||
"638952175999932299156089414639761565182862536979208272237582"
|
||||
"51185210916864000000000000000000000000"; // 100!
|
||||
_ = "170141183460469231731687303715884105727"; // prime
|
||||
)
|
||||
|
||||
|
||||
func same(t, u *Time) bool {
|
||||
// respect source lines in multi-line expressions
|
||||
return t.Year == u.Year
|
||||
|
18
src/pkg/go/printer/testdata/expressions.golden
vendored
18
src/pkg/go/printer/testdata/expressions.golden
vendored
@ -151,12 +151,24 @@ func _() {
|
||||
c;
|
||||
_ = a < b ||
|
||||
b < a;
|
||||
_ = "1234567890"
|
||||
"1234567890";
|
||||
// this comment should be indented
|
||||
_ = "933262154439441526816992388562667004907159682643816214685929"
|
||||
"638952175999932299156089414639761565182862536979208272237582"
|
||||
"51185210916864000000000000000000000000"; // 100!
|
||||
_ = "170141183460469231731687303715884105727"; // prime
|
||||
}
|
||||
|
||||
|
||||
// Alignment after overlong lines
|
||||
const (
|
||||
_ = "991";
|
||||
_ = "2432902008176640000"; // 20!
|
||||
_ = "933262154439441526816992388562667004907159682643816214685929"
|
||||
"638952175999932299156089414639761565182862536979208272237582"
|
||||
"51185210916864000000000000000000000000"; // 100!
|
||||
_ = "170141183460469231731687303715884105727"; // prime
|
||||
)
|
||||
|
||||
|
||||
func same(t, u *Time) bool {
|
||||
// respect source lines in multi-line expressions
|
||||
return t.Year == u.Year &&
|
||||
|
18
src/pkg/go/printer/testdata/expressions.raw
vendored
18
src/pkg/go/printer/testdata/expressions.raw
vendored
@ -151,12 +151,24 @@ func _() {
|
||||
c;
|
||||
_ = a < b ||
|
||||
b < a;
|
||||
_ = "1234567890"
|
||||
"1234567890";
|
||||
// this comment should be indented
|
||||
_ = "933262154439441526816992388562667004907159682643816214685929"
|
||||
"638952175999932299156089414639761565182862536979208272237582"
|
||||
"51185210916864000000000000000000000000"; // 100!
|
||||
_ = "170141183460469231731687303715884105727"; // prime
|
||||
}
|
||||
|
||||
|
||||
// Alignment after overlong lines
|
||||
const (
|
||||
_ = "991";
|
||||
_ = "2432902008176640000"; // 20!
|
||||
_ = "933262154439441526816992388562667004907159682643816214685929"
|
||||
"638952175999932299156089414639761565182862536979208272237582"
|
||||
"51185210916864000000000000000000000000"; // 100!
|
||||
_ = "170141183460469231731687303715884105727"; // prime
|
||||
)
|
||||
|
||||
|
||||
func same(t, u *Time) bool {
|
||||
// respect source lines in multi-line expressions
|
||||
return t.Year == u.Year &&
|
||||
|
26
src/pkg/go/printer/testdata/statements.go
vendored
26
src/pkg/go/printer/testdata/statements.go
vendored
@ -62,6 +62,32 @@ func _() {
|
||||
case 1: // this comment should have no effect on the previous or next line
|
||||
use(x);
|
||||
}
|
||||
|
||||
switch x := 0; x {
|
||||
case 1:
|
||||
x = 0;
|
||||
// this comment should be indented
|
||||
case 2:
|
||||
x = 0;
|
||||
// this comment should not be indented, it is aligned with the next case
|
||||
case 3:
|
||||
x = 0;
|
||||
/* indented comment
|
||||
aligned
|
||||
aligned
|
||||
*/
|
||||
// bla
|
||||
/* and more */
|
||||
case 4:
|
||||
x = 0;
|
||||
/* not indented comment
|
||||
aligned
|
||||
aligned
|
||||
*/
|
||||
// bla
|
||||
/* and more */
|
||||
case 5:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
26
src/pkg/go/printer/testdata/statements.golden
vendored
26
src/pkg/go/printer/testdata/statements.golden
vendored
@ -69,6 +69,32 @@ func _() {
|
||||
case 1: // this comment should have no effect on the previous or next line
|
||||
use(x);
|
||||
}
|
||||
|
||||
switch x := 0; x {
|
||||
case 1:
|
||||
x = 0;
|
||||
// this comment should be indented
|
||||
case 2:
|
||||
x = 0;
|
||||
// this comment should not be indented, it is aligned with the next case
|
||||
case 3:
|
||||
x = 0;
|
||||
/* indented comment
|
||||
aligned
|
||||
aligned
|
||||
*/
|
||||
// bla
|
||||
/* and more */
|
||||
case 4:
|
||||
x = 0;
|
||||
/* not indented comment
|
||||
aligned
|
||||
aligned
|
||||
*/
|
||||
// bla
|
||||
/* and more */
|
||||
case 5:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user