Skip to content

Commit 7cdf9e3

Browse files
makenowjustRX14
authored andcommittedJan 4, 2018
Fix formatting multi assignment with newline after equal (#5452)
Fixed #5451
1 parent 09f9650 commit 7cdf9e3

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed
 

Diff for: ‎spec/compiler/formatter/formatter_spec.cr

+1
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ describe Crystal::Formatter do
344344
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"
345345
assert_format "a = \nif 1\n2\nend", "a =\n if 1\n 2\n end"
346346
assert_format "a, b = \nif 1\n2\nend", "a, b =\n if 1\n 2\n end"
347+
assert_format "a = b = 1\na, b =\n b, a"
347348

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

Diff for: ‎src/compiler/crystal/tools/formatter.cr

+8-3
Original file line numberDiff line numberDiff line change
@@ -3510,14 +3510,19 @@ module Crystal
35103510

35113511
write_token " ", :"="
35123512
skip_space
3513-
if @token.type == :NEWLINE && node.values.size == 1
3513+
if @token.type == :NEWLINE
35143514
next_token_skip_space_or_newline
35153515
write_line
3516-
write_indent(@indent + 2, node.values.first)
3516+
if node.values.size == 1
3517+
write_indent(@indent + 2, node.values.first)
3518+
return false
3519+
else
3520+
write_indent(@indent + 2)
3521+
end
35173522
else
35183523
write " "
3519-
format_mutli_assign_values node.values
35203524
end
3525+
format_mutli_assign_values node.values
35213526

35223527
false
35233528
end

0 commit comments

Comments
 (0)