diff --git a/spec/compiler/formatter/formatter_spec.cr b/spec/compiler/formatter/formatter_spec.cr index 75f49c7a678a..628d3d2c8781 100644 --- a/spec/compiler/formatter/formatter_spec.cr +++ b/spec/compiler/formatter/formatter_spec.cr @@ -930,6 +930,7 @@ describe Crystal::Formatter do assert_format "# Hello\n#\n# ```\n# puts 1+2 # bye\n# 1+2 # hello\n#\n# 1+2\n# ```\n\n# ```\n# puts 1+2\n\n# ```\n# puts 1+2\n\n# Hola\n#\n# 1+2\n# foo do\n# 3+4\n# end\n\n# Hey\n#\n# 1+2\n# foo do\n# 3+4\n# end\n#\n# ```\n# 1+2\n# ```\n#\n# 1+2\n#\n# Bye\n", "# Hello\n#\n# ```\n# puts 1 + 2 # bye\n# 1 + 2 # hello\n#\n# 1 + 2\n# ```\n\n# ```\n# puts 1+2\n\n# ```\n# puts 1+2\n\n# Hola\n#\n# 1+2\n# foo do\n# 3+4\n# end\n\n# Hey\n#\n# 1+2\n# foo do\n# 3+4\n# end\n#\n# ```\n# 1 + 2\n# ```\n#\n# 1+2\n#\n# Bye" assert_format "macro foo\n {% for value, i in values %}\\\n {% if true %}\\\n {% end %}\\\n {{ 1 }}/\n {% end %}\\\nend\n\n{\n 1 => 2,\n 1234 => 5,\n}\n", "macro foo\n {% for value, i in values %}\\\n {% if true %}\\\n {% end %}\\\n {{ 1 }}/\n {% end %}\\\nend\n\n{\n 1 => 2,\n 1234 => 5,\n}" assert_format "a = \"\n\"\n1 # 1\n12 # 2\n", "a = \"\n\"\n1 # 1\n12 # 2" + assert_format "enum Foo\n A, B, C\nend\n", "enum Foo\n A; B; C\nend" assert_format "enum Foo\n A; B; C\nend\n", "enum Foo\n A; B; C\nend" assert_format "# ```\n# macro foo\n# 1\n# end\n# ```\n", "# ```\n# macro foo\n# 1\n# end\n# ```" assert_format "class Foo\n # ```\n # 1\n # ```\nend\n", "class Foo\n # ```\n # 1\n # ```\nend" diff --git a/src/compiler/crystal/syntax/parser.cr b/src/compiler/crystal/syntax/parser.cr index c4215b9074fe..e987246a42ef 100644 --- a/src/compiler/crystal/syntax/parser.cr +++ b/src/compiler/crystal/syntax/parser.cr @@ -5560,7 +5560,8 @@ module Crystal skip_space case @token.type - when :";", :NEWLINE, :EOF + # TODO: remove comma support after 0.28.0 + when :",", :";", :NEWLINE, :EOF next_token_skip_statement_end else unless @token.keyword?(:end) diff --git a/src/compiler/crystal/tools/formatter.cr b/src/compiler/crystal/tools/formatter.cr index 95144044c5b6..f876a29ead74 100644 --- a/src/compiler/crystal/tools/formatter.cr +++ b/src/compiler/crystal/tools/formatter.cr @@ -2060,7 +2060,8 @@ module Crystal end # This is the case of an enum member - if @token.type == :";" + # TODO: remove comma support after 0.28.0 + if @token.type == :";" || (node.name[0].ascii_uppercase? && @token.type == :",") next_token @lexer.skip_space if @token.type == :COMMENT