fmt: force empty lines after struct declarations and most functions (#9096)
parent
3e5a0dfc94
commit
0f8f8bd90d
|
@ -324,21 +324,22 @@ fn (f Fmt) should_insert_newline_before_node(node ast.Node, prev_node ast.Node)
|
||||||
if prev_stmt is ast.HashStmt && stmt !is ast.HashStmt && stmt !is ast.ExprStmt {
|
if prev_stmt is ast.HashStmt && stmt !is ast.HashStmt && stmt !is ast.ExprStmt {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// Force a newline after a block of function declarations
|
// Force a newline after function declarations
|
||||||
|
// The only exception is inside an block of no_body functions
|
||||||
if prev_stmt is ast.FnDecl {
|
if prev_stmt is ast.FnDecl {
|
||||||
if prev_stmt.no_body && stmt !is ast.FnDecl {
|
if stmt !is ast.FnDecl || !prev_stmt.no_body {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The stmt shouldn't have a newline before
|
// Force a newline after struct declarations
|
||||||
// if stmt.position().line_nr - prev_line_nr <= 1 {
|
if prev_stmt is ast.StructDecl {
|
||||||
// return false
|
return true
|
||||||
// }
|
}
|
||||||
// Imports are handled special hence they are ignored here
|
// Imports are handled special hence they are ignored here
|
||||||
if stmt is ast.Import || prev_stmt is ast.Import {
|
if stmt is ast.Import || prev_stmt is ast.Import {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// Attributes are not respected in the stmts position, so this requires a manual check
|
// Attributes are not respected in the stmts position, so this requires manual checking
|
||||||
if stmt is ast.StructDecl {
|
if stmt is ast.StructDecl {
|
||||||
if stmt.attrs.len > 0 && stmt.attrs[0].pos.line_nr - prev_line_nr <= 1 {
|
if stmt.attrs.len > 0 && stmt.attrs[0].pos.line_nr - prev_line_nr <= 1 {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
struct EmptyLineAfterStructs {}
|
||||||
|
|
||||||
|
fn empty_line_after_functions() {}
|
||||||
|
|
||||||
fn squash_multiple_empty_lines() {
|
fn squash_multiple_empty_lines() {
|
||||||
println('a')
|
println('a')
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
struct EmptyLineAfterStructs {}
|
||||||
|
fn empty_line_after_functions() {}
|
||||||
fn squash_multiple_empty_lines() {
|
fn squash_multiple_empty_lines() {
|
||||||
println('a')
|
println('a')
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,16 @@ fn (rp RoutePair) test() ?[]string {
|
||||||
route := rp.route.split('/').filter(it != '')
|
route := rp.route.split('/').filter(it != '')
|
||||||
return route_matches(url, route)
|
return route_matches(url, route)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (rp RoutePair) test_match() {
|
fn (rp RoutePair) test_match() {
|
||||||
rp.test() or { panic('should match: $rp') }
|
rp.test() or { panic('should match: $rp') }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (rp RoutePair) test_no_match() {
|
fn (rp RoutePair) test_no_match() {
|
||||||
rp.test() or { return }
|
rp.test() or { return }
|
||||||
panic('should not match: $rp')
|
panic('should not match: $rp')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (rp RoutePair) test_param(expected []string) {
|
fn (rp RoutePair) test_param(expected []string) {
|
||||||
res := rp.test() or { panic('should match: $rp') }
|
res := rp.test() or { panic('should match: $rp') }
|
||||||
assert res == expected
|
assert res == expected
|
||||||
|
|
Loading…
Reference in New Issue