Skip to content

Commit

Permalink
Format comma to semicolon
Browse files Browse the repository at this point in the history
  • Loading branch information
j8r committed Apr 3, 2019
1 parent 8a41cfe commit 9f6fa91
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions spec/compiler/formatter/formatter_spec.cr
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/crystal/syntax/parser.cr
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/crystal/tools/formatter.cr
Expand Up @@ -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
Expand Down

0 comments on commit 9f6fa91

Please sign in to comment.