From 0c3c3d4694b6189dc708a425e753863cae1ccdd1 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Sat, 3 Jun 2017 19:40:18 -0300 Subject: [PATCH] Formatter: fix removal of newline when it had spaces --- spec/compiler/formatter/formatter_spec.cr | 2 ++ src/compiler/crystal/tools/formatter.cr | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/compiler/formatter/formatter_spec.cr b/spec/compiler/formatter/formatter_spec.cr index 34d36a173184..8ee648bc2fb9 100644 --- a/spec/compiler/formatter/formatter_spec.cr +++ b/spec/compiler/formatter/formatter_spec.cr @@ -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 diff --git a/src/compiler/crystal/tools/formatter.cr b/src/compiler/crystal/tools/formatter.cr index 76df631db2f6..1faa489b8169 100644 --- a/src/compiler/crystal/tools/formatter.cr +++ b/src/compiler/crystal/tools/formatter.cr @@ -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 @@ -4210,6 +4210,7 @@ module Crystal else @column += string.size end + @wrote_newline = false @last_write = string end