fmt: remove tail space when using multiline short arg (#9110)

pull/9111/head
zakuro 2021-03-04 19:44:50 +09:00 committed by GitHub
parent 8ce53b8b55
commit 6b2c7fd53e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 2 deletions

View File

@ -1734,7 +1734,7 @@ pub fn (mut f Fmt) if_expr(node ast.IfExpr) {
f.single_line_if = false
if node.post_comments.len > 0 {
f.writeln('')
f.comments(node.post_comments,
f.comments(node.post_comments,
has_nl: false
prev_line: node.branches.last().body_pos.last_line
)
@ -2176,6 +2176,14 @@ pub fn (mut f Fmt) struct_init(node ast.StructInit) {
fields_start := f.out.len
fields_loop: for {
if !single_line_fields {
if use_short_args && f.out.buf[f.out.buf.len - 1] == ` ` {
// v Remove space at tail of line
// f(a, b, c, \n
// f1: 0\n
// f2: 1\n
// )
f.out.go_back(1)
}
f.writeln('')
f.indent++
}

View File

@ -6,6 +6,7 @@ struct Bar {
struct Baz {
x int
y int
}
fn main() {
@ -18,8 +19,13 @@ fn main() {
x: 'some string'
b: Baz{
x: 0
y: 0
}
)
baz_func('foo', 'bar',
x: 0
y: 0
)
ui.row(
// stretch: true
margin: {
@ -33,3 +39,5 @@ fn main() {
fn bar_func(bar Bar) {
}
fn baz_func(a string, b string, baz Baz) {}

View File

@ -6,6 +6,7 @@ struct Bar {
struct Baz {
x int
y int
}
fn main() {
@ -13,7 +14,11 @@ fn main() {
bar_func(x: 'a very long content should cause vfmt to use multiple lines instead of one.', y: 123456789)
bar_func(x: 'some string', b: Baz{
x: 0
y: 0
})
baz_func('foo', 'bar', x: 0
y: 0
)
ui.row({
//stretch: true
margin: {top:10,left:10,right:10,bottom:10}
@ -22,3 +27,5 @@ fn main() {
fn bar_func(bar Bar) {
}
fn baz_func(a string, b string, baz Baz) {}

View File

@ -220,7 +220,7 @@ fn test_http_client_shutdown_does_not_work_without_a_cookie() {
fn testsuite_end() {
// This test is guaranteed to be called last.
// It sends a request to the server to shutdown.
x := http.fetch('http://127.0.0.1:$sport/shutdown',
x := http.fetch('http://127.0.0.1:$sport/shutdown',
method: .get
cookies: map{
'skey': 'superman'