Skip to content

Commit

Permalink
Handle trailing comma with multiple parameters on the same line
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacksmoke16 committed Oct 18, 2024
1 parent dacd97b commit 130efd8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,13 @@ describe Crystal::Formatter do
end
CRYSTAL

assert_format <<-CRYSTAL
def foo(
a, b,
)
end
CRYSTAL

assert_format <<-CRYSTAL
macro foo(
a,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ module Crystal
yield

# Write "," before skipping spaces to prevent inserting comment between argument and comma.
write "," if has_more || (wrote_newline && @token.type.op_comma?) || (write_trailing_comma && flag?("def_trailing_comma"))
write "," if has_more || (wrote_newline && @token.type.op_comma?) || (write_trailing_comma && flag?("def_trailing_comma")) || (write_trailing_comma && @token.type.op_comma?)

just_wrote_newline = skip_space
if @token.type.newline?
Expand Down

0 comments on commit 130efd8

Please sign in to comment.