v.fmt: drop newline in end comments for const (#20672)

This commit is contained in:
Pierre Curto 2024-01-27 17:18:33 +01:00 committed by GitHub
parent 75e906538f
commit 5a752c9a2d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 8 additions and 6 deletions

View file

@ -958,13 +958,13 @@ pub fn (mut f Fmt) const_decl(node ast.ConstDecl) {
if node.is_block && fidx < node.fields.len - 1 && node.fields.len > 1 {
// old style grouped consts, converted to the new style ungrouped const
f.writeln('')
} else {
} else if node.end_comments.len > 0 {
// Write out single line comments after const expr if present
// E.g.: `const x = 1 // <comment>`
if node.end_comments.len > 0 && node.end_comments[0].text.contains('\n') {
if node.end_comments[0].text.contains('\n') {
f.writeln('\n')
}
f.comments(node.end_comments, same_line: true)
f.comments(node.end_comments, same_line: true, has_nl: false)
}
prev_field = field
}

View file

@ -0,0 +1,3 @@
const a = 'a' // hello
const b = 'b' // comment
const c = 'c'

View file

@ -1,7 +1,6 @@
// leave
const one = 1 // leave
// move
// leave
const two = 2

View file

@ -1,6 +1,6 @@
// leave
const one = 1 // leave
// move
// leave
const two = 2 /* move
*/