Skip to content

Commit

Permalink
Format: fix #4620, to format /= after else in case (#4627)
Browse files Browse the repository at this point in the history
`skip_space_or_newline` is not needed because it is called inside
`format_nested`.
  • Loading branch information
makenowjust authored and RX14 committed Sep 10, 2017
1 parent 46197bd commit 203ab9f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
1 change: 1 addition & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ describe Crystal::Formatter do
assert_format "case 1 \n when .foo? \n 3 \n end", "case 1\nwhen .foo?\n 3\nend"
assert_format "case 1\nwhen 1 then\n2\nwhen 3\n4\nend", "case 1\nwhen 1\n 2\nwhen 3\n 4\nend"
assert_format "case 1 \n when 2 \n 3 \n else 4 \n end", "case 1\nwhen 2\n 3\nelse 4\nend"
assert_format "a = 1\ncase\nwhen 2\nelse\n a /= 3\nend"

assert_format "select \n when foo \n 2 \n end", "select\nwhen foo\n 2\nend"
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"
Expand Down
8 changes: 2 additions & 6 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3277,12 +3277,8 @@ module Crystal
write_keyword :else
found_comment = skip_space
if @token.type == :NEWLINE || found_comment
unless found_comment
write_line
next_token
end
skip_space_or_newline(@indent + 2)
format_nested(a_else, @indent)
write_line unless found_comment
format_nested(a_else)
skip_space_or_newline(@indent + 2)
else
while @token.type == :";"
Expand Down

0 comments on commit 203ab9f

Please sign in to comment.