mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
v.fmt: drop newline in end comments for const (#20672)
This commit is contained in:
parent
75e906538f
commit
5a752c9a2d
4 changed files with 8 additions and 6 deletions
|
@ -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
|
||||
}
|
||||
|
|
3
vlib/v/fmt/tests/consts_with_comments_end_keep.vv
Normal file
3
vlib/v/fmt/tests/consts_with_comments_end_keep.vv
Normal file
|
@ -0,0 +1,3 @@
|
|||
const a = 'a' // hello
|
||||
const b = 'b' // comment
|
||||
const c = 'c'
|
|
@ -1,7 +1,6 @@
|
|||
// leave
|
||||
const one = 1 // leave
|
||||
|
||||
// move
|
||||
// leave
|
||||
|
||||
const two = 2
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// leave
|
||||
const one = 1 // leave
|
||||
// move
|
||||
// leave
|
||||
|
||||
const two = 2 /* move
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue