diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 6994c3bce226ba..163d234c63bd7e 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -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 { diff --git a/vlib/v/fmt/tests/consts_after_linebreak_expected.vv b/vlib/v/fmt/tests/consts_after_linebreak_expected.vv new file mode 100644 index 00000000000000..b2f358682ab88e --- /dev/null +++ b/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 {} diff --git a/vlib/v/fmt/tests/consts_after_linebreak_input.vv b/vlib/v/fmt/tests/consts_after_linebreak_input.vv new file mode 100644 index 00000000000000..08a740f8c8a73d --- /dev/null +++ b/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 {} diff --git a/vlib/v/fmt/tests/donut_card_expected.vv b/vlib/v/fmt/tests/donut_card_expected.vv index 53c92f84aef83c..c184a01e4df840 100644 --- a/vlib/v/fmt/tests/donut_card_expected.vv +++ b/vlib/v/fmt/tests/donut_card_expected.vv @@ -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