fmt: keep new line at both ends of block comment (#8003)
parent
8f4238e76a
commit
2103d9a6c4
|
@ -1372,7 +1372,7 @@ pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) {
|
|||
x := node.text.trim_left('\x01')
|
||||
if x.contains('\n') {
|
||||
f.writeln('/*')
|
||||
f.writeln(x)
|
||||
f.writeln(x.trim_space())
|
||||
f.write('*/')
|
||||
} else {
|
||||
f.write('/* ${x.trim(' ')} */')
|
||||
|
@ -1397,7 +1397,7 @@ pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) {
|
|||
f.write(out_s)
|
||||
return
|
||||
}
|
||||
lines := node.text.split_into_lines()
|
||||
lines := node.text.trim_space().split_into_lines()
|
||||
f.writeln('/*')
|
||||
for line in lines {
|
||||
f.writeln(line)
|
||||
|
|
|
@ -10,6 +10,15 @@ fn mr_fun() (int, int) {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
/*
|
||||
block1
|
||||
*/
|
||||
/*
|
||||
block2
|
||||
*/
|
||||
/*
|
||||
block3
|
||||
*/
|
||||
// this is a comment
|
||||
a := 1
|
||||
// and another comment
|
||||
|
|
|
@ -7,6 +7,15 @@ fn mr_fun() (int, int) {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
/* block1
|
||||
*/
|
||||
/*
|
||||
block2 */
|
||||
/*
|
||||
|
||||
block3
|
||||
|
||||
*/
|
||||
a := /* this is a comment */ 1
|
||||
b, c := /* and another comment */ a, /* just to make it worse */ 2
|
||||
d := c // and an extra one
|
||||
|
|
|
@ -43,5 +43,8 @@ fn main() {
|
|||
//////
|
||||
// /
|
||||
// 123
|
||||
/*
|
||||
block
|
||||
*/
|
||||
println('hello world')
|
||||
}
|
||||
|
|
|
@ -959,7 +959,7 @@ fn (mut s Scanner) text_scan() token.Token {
|
|||
}
|
||||
s.pos++
|
||||
if s.should_parse_comment() {
|
||||
comment := s.text[start..(s.pos - 1)].trim_space()
|
||||
comment := s.text[start..(s.pos - 1)].trim(' ')
|
||||
return s.new_token(.comment, comment, comment.len + 4)
|
||||
}
|
||||
// Skip if not in fmt mode
|
||||
|
|
Loading…
Reference in New Issue