Skip to content

Commit

Permalink
Fix formatting multi assignment with newline after equal (#5452)
Browse files Browse the repository at this point in the history
Fixed #5451
  • Loading branch information
makenowjust authored and RX14 committed Jan 4, 2018
1 parent 09f9650 commit 7cdf9e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions spec/compiler/formatter/formatter_spec.cr
Expand Up @@ -344,6 +344,7 @@ describe Crystal::Formatter do
assert_format "a = case 1\nwhen 2\n3\nelse\n4\nend", "a = case 1\n when 2\n 3\n else\n 4\n end"
assert_format "a = \nif 1\n2\nend", "a =\n if 1\n 2\n end"
assert_format "a, b = \nif 1\n2\nend", "a, b =\n if 1\n 2\n end"
assert_format "a = b = 1\na, b =\n b, a"

assert_format %(require "foo"), %(require "foo")

Expand Down
11 changes: 8 additions & 3 deletions src/compiler/crystal/tools/formatter.cr
Expand Up @@ -3510,14 +3510,19 @@ module Crystal

write_token " ", :"="
skip_space
if @token.type == :NEWLINE && node.values.size == 1
if @token.type == :NEWLINE
next_token_skip_space_or_newline
write_line
write_indent(@indent + 2, node.values.first)
if node.values.size == 1
write_indent(@indent + 2, node.values.first)
return false
else
write_indent(@indent + 2)
end
else
write " "
format_mutli_assign_values node.values
end
format_mutli_assign_values node.values

false
end
Expand Down

0 comments on commit 7cdf9e3

Please sign in to comment.