1
0
mirror of https://github.com/golang/go synced 2024-11-25 12:57:58 -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:
Robert Griesemer 2009-10-30 13:17:14 -07:00
parent 09f4261841
commit 1e984cb913
8 changed files with 637 additions and 168 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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.
*/
}

View File

@ -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.
*/
}

View File

@ -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

View File

@ -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 &&

View File

@ -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 &&

View File

@ -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:
}
}

View File

@ -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:
}
}