Skip to content

Commit

Permalink
Fix indentation after comment inside 'when'
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust authored and asterite committed Jan 29, 2018
1 parent bfd7c99 commit 995d3f9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ 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 "case 1\nwhen 1, # 1\n 2, # 2\n 3 # 3\n 1\nend"
assert_format "a = case 1\n when 1, # 1\n 2, # 2\n 3 # 3\n 1\n end"
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"
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3346,9 +3346,9 @@ module Crystal
write ","
slash_is_regex!
next_token
skip_space
if @token.type == :NEWLINE
write_line
found_comment = skip_space
if found_comment || @token.type == :NEWLINE
write_line unless found_comment
skip_space_or_newline
next_needs_indent = true
else
Expand Down

0 comments on commit 995d3f9

Please sign in to comment.