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)