Skip to content

Commit

Permalink
Showing 2 changed files with 4 additions and 9 deletions.
1 change: 1 addition & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
@@ -1038,6 +1038,7 @@ describe Crystal::Formatter do
assert_format "{ {% for x in 1..2 %}3{% end %}, nil }"
assert_format "{ %() }"
assert_format "{ %w() }"
assert_format "{ {1}.foo, 2 }"

assert_format "String?"
assert_format "String???"
12 changes: 3 additions & 9 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
@@ -809,15 +809,9 @@ module Crystal
end

# This is to prevent writing `{{` and `{%`
if prefix == :"{" && i == 0 && !wrote_newline && (
current_element.is_a?(TupleLiteral) ||
current_element.is_a?(NamedTupleLiteral) ||
current_element.is_a?(HashLiteral) ||
current_element.is_a?(MacroExpression) ||
current_element.is_a?(MacroIf) ||
current_element.is_a?(MacroFor) ||
@token.raw.starts_with?('%')
)
if prefix == :"{" && i == 0 && !wrote_newline &&
(@token.type == :"{" || @token.type == :"{{" || @token.type == :"{%" ||
@token.type == :"%" || @token.raw.starts_with?("%"))
write " "
write_space_at_end = true
end

0 comments on commit ad56b14

Please sign in to comment.