Commit 1e984cb9 authored by Robert Griesemer's avatar Robert Griesemer

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
parent 09f42618
This diff is collapsed.
......@@ -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.
*/
}
......
......@@ -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.
*/
}
......
......@@ -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
......
......@@ -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 &&
......
......@@ -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 &&
......
......@@ -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:
}
}
......
......@@ -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:
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment