fmt: respect user choice of empty lines between type declarations (#9135)
parent
fdcfe397d4
commit
053d6870d2
|
@ -334,6 +334,10 @@ fn (f Fmt) should_insert_newline_before_node(node ast.Node, prev_node ast.Node)
|
||||||
if prev_stmt is ast.StructDecl {
|
if prev_stmt is ast.StructDecl {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
// Empty line after an block of type declarations
|
||||||
|
if prev_stmt is ast.TypeDecl && stmt !is ast.TypeDecl {
|
||||||
|
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
|
||||||
|
@ -481,6 +485,7 @@ pub fn (mut f Fmt) type_decl(node ast.TypeDecl) {
|
||||||
ast.FnTypeDecl { f.fn_type_decl(node) }
|
ast.FnTypeDecl { f.fn_type_decl(node) }
|
||||||
ast.SumTypeDecl { f.sum_type_decl(node) }
|
ast.SumTypeDecl { f.sum_type_decl(node) }
|
||||||
}
|
}
|
||||||
|
f.writeln('')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut f Fmt) alias_type_decl(node ast.AliasTypeDecl) {
|
pub fn (mut f Fmt) alias_type_decl(node ast.AliasTypeDecl) {
|
||||||
|
@ -491,7 +496,6 @@ pub fn (mut f Fmt) alias_type_decl(node ast.AliasTypeDecl) {
|
||||||
f.write('type $node.name = $ptype')
|
f.write('type $node.name = $ptype')
|
||||||
|
|
||||||
f.comments(node.comments, has_nl: false)
|
f.comments(node.comments, has_nl: false)
|
||||||
f.writeln('\n')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut f Fmt) fn_type_decl(node ast.FnTypeDecl) {
|
pub fn (mut f Fmt) fn_type_decl(node ast.FnTypeDecl) {
|
||||||
|
@ -539,7 +543,6 @@ pub fn (mut f Fmt) fn_type_decl(node ast.FnTypeDecl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
f.comments(node.comments, has_nl: false)
|
f.comments(node.comments, has_nl: false)
|
||||||
f.writeln('\n')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut f Fmt) sum_type_decl(node ast.SumTypeDecl) {
|
pub fn (mut f Fmt) sum_type_decl(node ast.SumTypeDecl) {
|
||||||
|
@ -563,7 +566,6 @@ pub fn (mut f Fmt) sum_type_decl(node ast.SumTypeDecl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
f.comments(node.comments, has_nl: false)
|
f.comments(node.comments, has_nl: false)
|
||||||
f.writeln('\n')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
type MyInt = int
|
||||||
|
type EmptyLineAfterLastType = fn () int
|
||||||
|
|
||||||
struct EmptyLineAfterStructs {}
|
struct EmptyLineAfterStructs {}
|
||||||
|
|
||||||
fn empty_line_after_functions() {}
|
fn empty_line_after_functions() {}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
type MyInt = int
|
||||||
|
type EmptyLineAfterLastType = fn() int
|
||||||
struct EmptyLineAfterStructs {}
|
struct EmptyLineAfterStructs {}
|
||||||
fn empty_line_after_functions() {}
|
fn empty_line_after_functions() {}
|
||||||
fn squash_multiple_empty_lines() {
|
fn squash_multiple_empty_lines() {
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
// Keep empty lines between types
|
||||||
|
type Expr = IfExpr | IntegerLiteral
|
||||||
|
|
||||||
|
type Node2 = Expr | string
|
||||||
|
type MyInt = int
|
||||||
|
|
||||||
// Keep empty lines in const blocks
|
// Keep empty lines in const blocks
|
||||||
const (
|
const (
|
||||||
_ = SomeStruct{
|
_ = SomeStruct{
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// Sumtype
|
// Sumtype
|
||||||
type FooBar = Bar | Foo
|
type FooBar = Bar | Foo
|
||||||
|
|
||||||
pub type PublicBar = Bar | Foo | FooBar
|
pub type PublicBar = Bar | Foo | FooBar
|
||||||
|
|
||||||
type Uint = byte | u16 | u32 | u64 // This should stay on the same line
|
type Uint = byte | u16 | u32 | u64 // This should stay on the same line
|
||||||
|
@ -15,7 +14,6 @@ pub type Abc = f32
|
||||||
// Fn type decl
|
// Fn type decl
|
||||||
|
|
||||||
type EmptyFn = fn ()
|
type EmptyFn = fn ()
|
||||||
|
|
||||||
type OneArgFn = fn (i int)
|
type OneArgFn = fn (i int)
|
||||||
|
|
||||||
type TwoDiffArgs = fn (i int, s string) bool
|
type TwoDiffArgs = fn (i int, s string) bool
|
||||||
|
|
Loading…
Reference in New Issue