Skip to content

Commit

Permalink
fmt: add linebreak after const decl (fix #20157) (#20162)
Browse files Browse the repository at this point in the history
  • Loading branch information
shove70 committed Dec 13, 2023
1 parent 17bf8d1 commit aef3643
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions vlib/v/fmt/fmt.v
Expand Up @@ -422,6 +422,11 @@ fn (f Fmt) should_insert_newline_before_node(node ast.Node, prev_node ast.Node)
ast.Import {
return false
}
ast.ConstDecl {
if node !is ast.ConstDecl && !(node is ast.ExprStmt && node.expr is ast.Comment) {
return true
}
}
else {}
}
match node {
Expand Down
18 changes: 18 additions & 0 deletions vlib/v/fmt/tests/consts_after_linebreak_expected.vv
@@ -0,0 +1,18 @@
import os

const foo = 'foo'
const bar = 1
// ...
const a = 1

fn baz() {
}

const b = ''

fn foobar() {
}

const c = '' // ...

struct Struct {}
15 changes: 15 additions & 0 deletions vlib/v/fmt/tests/consts_after_linebreak_input.vv
@@ -0,0 +1,15 @@
import os

const foo = 'foo'
const bar = 1
// ...
const a = 1
fn baz() {
}

const b = ''
fn foobar() {
}

const c = '' // ...
struct Struct {}
1 change: 1 addition & 0 deletions vlib/v/fmt/tests/donut_card_expected.vv
Expand Up @@ -4,6 +4,7 @@ import strings
import time { sleep }

const alt = '.,-~:;=!*#$@'

fn rd(cs int, ls int, a f64, b f64) {
tt_spacing, p_spacing := 0.07, 0.02
r1, r2, k2 := 1, 2, 5
Expand Down

0 comments on commit aef3643

Please sign in to comment.