Skip to content

Commit

Permalink
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
@@ -599,6 +599,8 @@ describe Crystal::Formatter do
assert_format "1#foo", "1 # foo"
assert_format "1 # foo\n1234 # bar\n\n10 # bar", "1 # foo\n1234 # bar\n\n10 # bar"
assert_format "# foo\na = 1 # bar"
assert_format "#### ###"
assert_format "#######"

assert_format "A = 1\nFOO = 2\n\nEX = 3", "A = 1\nFOO = 2\n\nEX = 3"
assert_format "FOO = 2\nA = 1", "FOO = 2\nA = 1"
2 changes: 2 additions & 0 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
@@ -3836,6 +3836,8 @@ module Crystal
after_comment_value = raw_after_comment_value.strip
if after_comment_value.starts_with?("=>")
value = "\# => #{after_comment_value[2..-1].strip}"
elsif after_comment_value.each_char.all? { |c| c.whitespace? || c == '#' }
# Nothing, leave sequences of whitespaces and '#' as is
else
char_1 = value[1]?
if char_1 && !char_1.whitespace?

0 comments on commit 352eb73

Please sign in to comment.