Skip to content

Commit

Permalink
fmt: recognize or blocks in call args (#19690)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm authored Oct 29, 2023
1 parent b9d0aed commit 5c2eafc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/tools/vcreate/vcreate_input_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import v.vmod

const (
// Expect has to be installed for the test.
expect_exe = os.quoted_path(os.find_abs_path_of_executable('expect') or {
expect_exe = os.quoted_path(os.find_abs_path_of_executable('expect') or {
eprintln('skipping test, since expect is missing')
exit(0)
})
Expand Down
3 changes: 2 additions & 1 deletion vlib/v/fmt/fmt.v
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,8 @@ fn expr_is_single_line(expr ast.Expr) bool {
}
}
ast.CallExpr {
if expr.or_block.stmts.len > 1 {
if expr.or_block.stmts.len > 1 || expr.args.any(it.expr is ast.CallExpr
&& it.expr.or_block.stmts.len > 1) {
return false
}
}
Expand Down
13 changes: 13 additions & 0 deletions vlib/v/fmt/tests/consts_with_or_block_keep.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os

const (
exe = os.find_abs_path_of_executable('my_exe') or {
eprintln('skipping test, since `my_exe` is missing')
exit(0)
}
exe_quoted = os.quoted_path(os.find_abs_path_of_executable('my_exe') or {
eprintln('skipping test, since `my_exe` is missing')
exit(0)
})
single_line_test_path = os.join_path(os.vtmp_dir(), 'my_test_path')
)

0 comments on commit 5c2eafc

Please sign in to comment.