From 466e0a2201c2e5b225cf4452993a95353c2b63d7 Mon Sep 17 00:00:00 2001 From: TSUYUSATO Kitsune Date: Mon, 16 Jul 2018 19:04:57 +0900 Subject: [PATCH] Format: fix comment indentation in case's else (#6393) Fix #6391 --- spec/compiler/formatter/formatter_spec.cr | 1 + src/compiler/crystal/tools/formatter.cr | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/compiler/formatter/formatter_spec.cr b/spec/compiler/formatter/formatter_spec.cr index 4fc11d1daa73..26c8f989151b 100644 --- a/spec/compiler/formatter/formatter_spec.cr +++ b/spec/compiler/formatter/formatter_spec.cr @@ -899,6 +899,7 @@ describe Crystal::Formatter do assert_format "return 1\n# end" assert_format "case\n# hello\nwhen 1\n 2\nend" assert_format "case 1\nwhen 2 # a\n # b\nend" + assert_format "case 1\nelse # foo\n # bar\nend" assert_format "{} of A => B\n{} of Foo => Bar" diff --git a/src/compiler/crystal/tools/formatter.cr b/src/compiler/crystal/tools/formatter.cr index 89cde7ab68ac..24509abf418a 100644 --- a/src/compiler/crystal/tools/formatter.cr +++ b/src/compiler/crystal/tools/formatter.cr @@ -3367,7 +3367,7 @@ module Crystal if a_else = node.else write_indent write_keyword :else - found_comment = skip_space + found_comment = skip_space(@indent + 2) if @token.type == :NEWLINE || found_comment write_line unless found_comment format_nested(a_else)