Skip to content

Commit

Permalink
Fix formatting of { {1}.foo, ...} (#6300)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored and Serdar Dogruyol committed Jul 1, 2018
1 parent 75ba915 commit ad56b14
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
1 change: 1 addition & 0 deletions spec/compiler/formatter/formatter_spec.cr
Expand Up @@ -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???"
Expand Down
12 changes: 3 additions & 9 deletions src/compiler/crystal/tools/formatter.cr
Expand Up @@ -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
Expand Down

0 comments on commit ad56b14

Please sign in to comment.