Skip to content

Commit

Permalink
Formatter: keep newline for multi-lines call with a block (#5062)
Browse files Browse the repository at this point in the history
Fixes #5060
  • Loading branch information
makenowjust authored and RX14 committed Sep 30, 2017
1 parent 7e3b642 commit 37d4448
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/compiler/formatter/formatter_spec.cr
Expand Up @@ -243,6 +243,7 @@ describe Crystal::Formatter do
assert_format "foo 1,\na: 1,\nb: 2,\nc: 3", "foo 1,\n a: 1,\n b: 2,\n c: 3"
assert_format "foo(\n 1, 2, &block)", "foo(\n 1, 2, &block)"
assert_format "foo(\n 1, 2,\n&block)", "foo(\n 1, 2,\n &block)"
assert_format "foo(\n 1,\n 2\n) do\n 1\nend"
assert_format "foo 1, a: 1,\nb: 2,\nc: 3,\n&block", "foo 1, a: 1,\n b: 2,\n c: 3,\n &block"
assert_format "foo 1, do\n2\nend", "foo 1 do\n 2\nend"
assert_format "a.b &.[c]?\n1"
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/crystal/tools/formatter.cr
Expand Up @@ -2287,6 +2287,10 @@ module Crystal
needs_space = !has_parentheses || has_args
skip_space
if has_parentheses && @token.type == :")"
if ends_with_newline
write_line unless found_comment
write_indent
end
write ")"
next_token_skip_space_or_newline
format_block block, needs_space
Expand Down

0 comments on commit 37d4448

Please sign in to comment.