Skip to content

Commit

Permalink
Format: fix formatting call having trailing comma with block (crystal…
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust authored and chris-huxtable committed Apr 6, 2018
1 parent f1d7f77 commit d2e4f75
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ describe Crystal::Formatter do
assert_format "foo(1,\n2,\n)", "foo(1,\n 2,\n)"
assert_format "foo(out x)", "foo(out x)"
assert_format "foo(\n 1,\n a: 1,\n b: 2,\n)"
assert_format "foo(1, ) { }", "foo(1) { }"
assert_format "foo(1, ) do\nend", "foo(1) do\nend"

assert_format "foo.bar\n.baz", "foo.bar\n .baz"
assert_format "foo.bar.baz\n.qux", "foo.bar.baz\n .qux"
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2366,6 +2366,10 @@ module Crystal
needs_space = !has_parentheses || has_args
block_indent = @multiline_call_indent || @indent
skip_space
if has_parentheses && @token.type == :","
next_token_skip_space
write "," if @token.type != :")" # foo(1, &.foo) case
end
if has_parentheses && @token.type == :")"
if ends_with_newline
write_line unless found_comment
Expand Down

0 comments on commit d2e4f75

Please sign in to comment.