fmt: only insert a space after // if the 3rd char is alphanumeric (#7330)
parent
8ab59c5f0f
commit
c922565525
|
@ -1204,16 +1204,19 @@ pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) {
|
|||
if !node.text.contains('\n') {
|
||||
is_separate_line := !options.inline || node.text.starts_with('\x01')
|
||||
mut s := if node.text.starts_with('\x01') { node.text[1..] } else { node.text }
|
||||
if s == '' {
|
||||
s = '//'
|
||||
} else {
|
||||
s = '// ' + s
|
||||
mut out_s := '//'
|
||||
if s != '' {
|
||||
match s[0] {
|
||||
`a`...`z`, `A`...`Z`, `0`...`9` { out_s += ' ' }
|
||||
else {}
|
||||
}
|
||||
out_s += s
|
||||
}
|
||||
if !is_separate_line && f.indent > 0 {
|
||||
f.remove_new_line() // delete the generated \n
|
||||
f.write(' ')
|
||||
}
|
||||
f.write(s)
|
||||
f.write(out_s)
|
||||
return
|
||||
}
|
||||
lines := node.text.split_into_lines()
|
||||
|
|
|
@ -30,6 +30,9 @@ fn main() {
|
|||
a := 123 // comment after assign
|
||||
b := 'foo' // also comment after assign
|
||||
c := true
|
||||
// between two assigns
|
||||
// Between two assigns
|
||||
d := false
|
||||
//////
|
||||
// /
|
||||
// 123
|
||||
}
|
||||
|
|
|
@ -926,7 +926,7 @@ fn (mut s Scanner) text_scan() token.Token {
|
|||
}
|
||||
if s.should_parse_comment() {
|
||||
s.line_comment = s.text[start + 1..comment_line_end]
|
||||
mut comment := s.line_comment.trim_space()
|
||||
mut comment := s.line_comment
|
||||
// Find out if this comment is on its own line (for vfmt)
|
||||
mut is_separate_line_comment := true
|
||||
for j := start - 2; j >= 0 && s.text[j] != `\n`; j-- {
|
||||
|
|
Loading…
Reference in New Issue