Skip to content

Commit 203ab9f

Browse files
makenowjustRX14
authored andcommittedSep 10, 2017
Format: fix #4620, to format /= after else in case (#4627)
`skip_space_or_newline` is not needed because it is called inside `format_nested`.
1 parent 46197bd commit 203ab9f

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed
 

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

+1
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ describe Crystal::Formatter do
460460
assert_format "case 1 \n when .foo? \n 3 \n end", "case 1\nwhen .foo?\n 3\nend"
461461
assert_format "case 1\nwhen 1 then\n2\nwhen 3\n4\nend", "case 1\nwhen 1\n 2\nwhen 3\n 4\nend"
462462
assert_format "case 1 \n when 2 \n 3 \n else 4 \n end", "case 1\nwhen 2\n 3\nelse 4\nend"
463+
assert_format "a = 1\ncase\nwhen 2\nelse\n a /= 3\nend"
463464

464465
assert_format "select \n when foo \n 2 \n end", "select\nwhen foo\n 2\nend"
465466
assert_format "select \n when foo \n 2 \n when bar \n 3 \n end", "select\nwhen foo\n 2\nwhen bar\n 3\nend"

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -3277,12 +3277,8 @@ module Crystal
32773277
write_keyword :else
32783278
found_comment = skip_space
32793279
if @token.type == :NEWLINE || found_comment
3280-
unless found_comment
3281-
write_line
3282-
next_token
3283-
end
3284-
skip_space_or_newline(@indent + 2)
3285-
format_nested(a_else, @indent)
3280+
write_line unless found_comment
3281+
format_nested(a_else)
32863282
skip_space_or_newline(@indent + 2)
32873283
else
32883284
while @token.type == :";"

0 commit comments

Comments
 (0)