Skip to content

Commit 37d4448

Browse files
makenowjustRX14
authored andcommittedSep 30, 2017
Formatter: keep newline for multi-lines call with a block (#5062)
Fixes #5060
1 parent 7e3b642 commit 37d4448

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed
 

‎spec/compiler/formatter/formatter_spec.cr

+1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ describe Crystal::Formatter do
243243
assert_format "foo 1,\na: 1,\nb: 2,\nc: 3", "foo 1,\n a: 1,\n b: 2,\n c: 3"
244244
assert_format "foo(\n 1, 2, &block)", "foo(\n 1, 2, &block)"
245245
assert_format "foo(\n 1, 2,\n&block)", "foo(\n 1, 2,\n &block)"
246+
assert_format "foo(\n 1,\n 2\n) do\n 1\nend"
246247
assert_format "foo 1, a: 1,\nb: 2,\nc: 3,\n&block", "foo 1, a: 1,\n b: 2,\n c: 3,\n &block"
247248
assert_format "foo 1, do\n2\nend", "foo 1 do\n 2\nend"
248249
assert_format "a.b &.[c]?\n1"

‎src/compiler/crystal/tools/formatter.cr

+4
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,10 @@ module Crystal
22872287
needs_space = !has_parentheses || has_args
22882288
skip_space
22892289
if has_parentheses && @token.type == :")"
2290+
if ends_with_newline
2291+
write_line unless found_comment
2292+
write_indent
2293+
end
22902294
write ")"
22912295
next_token_skip_space_or_newline
22922296
format_block block, needs_space

0 commit comments

Comments
 (0)
Please sign in to comment.