From 7a22d94a3ad9f91d81f4912d4b8816b3b3d61cee Mon Sep 17 00:00:00 2001 From: TSUYUSATO Kitsune Date: Mon, 20 Aug 2018 03:31:17 +0900 Subject: [PATCH 1/2] Fix formatting empty heredoc Fixed #6564 --- spec/compiler/formatter/formatter_spec.cr | 2 ++ src/compiler/crystal/tools/formatter.cr | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/compiler/formatter/formatter_spec.cr b/spec/compiler/formatter/formatter_spec.cr index 0714db2e63db..73c5d639d3d6 100644 --- a/spec/compiler/formatter/formatter_spec.cr +++ b/spec/compiler/formatter/formatter_spec.cr @@ -922,6 +922,8 @@ describe Crystal::Formatter do assert_format "x, y = <<-FOO, <<-BAR\n hello\n FOO\n world\n BAR" assert_format "x, y, z = <<-FOO, <<-BAR, <<-BAZ\n hello\n FOO\n world\n BAR\n qux\nBAZ" + assert_format "<<-FOO\nFOO" + assert_format "#!shebang\n1 + 2" assert_format " {{\n1 + 2 }}", "{{\n 1 + 2\n}}" diff --git a/src/compiler/crystal/tools/formatter.cr b/src/compiler/crystal/tools/formatter.cr index 251c5acd1478..8bb54ff0cdcd 100644 --- a/src/compiler/crystal/tools/formatter.cr +++ b/src/compiler/crystal/tools/formatter.cr @@ -542,9 +542,9 @@ module Crystal node.expressions.each do |exp| if @token.type == :DELIMITER_END - # If the delimiter ends with '\n' it's something like "\n HEREDOC", - # so we are done - break if @token.raw.starts_with?('\n') + # Heredoc cannot contain string continutation, + # so we are done. + break if is_heredoc # This is for " ... " \ # " ... " From 944b430a202fbb1bd995d476adc7a4a1f857406b Mon Sep 17 00:00:00 2001 From: TSUYUSATO Kitsune Date: Mon, 20 Aug 2018 05:36:59 +0900 Subject: [PATCH 2/2] Fix a typo Thank you @j8r! --- src/compiler/crystal/tools/formatter.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/crystal/tools/formatter.cr b/src/compiler/crystal/tools/formatter.cr index 8bb54ff0cdcd..b270d7db875e 100644 --- a/src/compiler/crystal/tools/formatter.cr +++ b/src/compiler/crystal/tools/formatter.cr @@ -542,7 +542,7 @@ module Crystal node.expressions.each do |exp| if @token.type == :DELIMITER_END - # Heredoc cannot contain string continutation, + # Heredoc cannot contain string continuation, # so we are done. break if is_heredoc