Skip to content

Commit

Permalink
Formatter: fix removal of newline when it had spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Jun 3, 2017
1 parent ddc3cb3 commit 0c3c3d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1020,4 +1020,6 @@ describe Crystal::Formatter do
assert_format "def a\n b(\n 1, # x\n # y\n a: 1, # x\n # y\n b: 2 # z\n )\nend"

assert_format "def foo(a, **b : Int32)\nend"

assert_format "foo\n \nbar", "foo\n\nbar"
end
3 changes: 2 additions & 1 deletion src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4139,7 +4139,7 @@ module Crystal
def consume_newlines
if @token.type == :NEWLINE
write_line
next_token
next_token_skip_space

if @token.type == :NEWLINE
write_line
Expand Down Expand Up @@ -4210,6 +4210,7 @@ module Crystal
else
@column += string.size
end

@wrote_newline = false
@last_write = string
end
Expand Down

0 comments on commit 0c3c3d4

Please sign in to comment.