Skip to content

Commit

Permalink
Showing 2 changed files with 23 additions and 7 deletions.
5 changes: 5 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
@@ -976,4 +976,9 @@ describe Crystal::Formatter do
assert_format "def foo(a,\n **b)\nend"
assert_format "def foo(**b, # comment\n &block)\nend"
assert_format "def foo(a, **b, # comment\n &block)\nend"

assert_format "1 +\n # foo\n 2"
assert_format "1 +\n # foo\n 2"
assert_format "1 ||\n # foo\n 2"
assert_format "foo(1 ||\n # foo\n 2)"
end
25 changes: 18 additions & 7 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
@@ -2163,13 +2163,16 @@ module Crystal
next_token
found_comment = skip_space
if found_comment || @token.type == :NEWLINE
skip_space_write_line
skip_space_or_newline
if @inside_call_or_assign == 0
write_indent(@indent + 2, node.args.last)
next_indent = @indent + 2
else
write_indent(column == 0 ? 2 : column, node.args.last)
next_indent = column == 0 ? 2 : column
end
indent(next_indent) do
skip_space_write_line
skip_space_or_newline
end
write_indent(next_indent, node.args.last)
else
write " " if needs_space
inside_call_or_assign do
@@ -2794,6 +2797,8 @@ module Crystal
end

def format_binary(node, token, alternative)
column = @column

accept node.left
skip_space_or_newline

@@ -2817,9 +2822,15 @@ module Crystal
write_token " ", token
skip_space
if @token.type == :NEWLINE
next_token_skip_space_or_newline
write_line
next_indent = @inside_cond == 0 ? @indent + 2 : @indent
if @inside_call_or_assign == 0
next_indent = @inside_cond == 0 ? @indent + 2 : @indent
else
next_indent = column == 0 ? 2 : column
end
indent(next_indent) do
skip_space_write_line
skip_space_or_newline
end
write_indent(next_indent, node.right)
return false
end

0 comments on commit b351d65

Please sign in to comment.