Skip to content

Commit

Permalink
Formatter: Fix assign followed by comment (#12319)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored and beta-ziliani committed Sep 6, 2022
1 parent bf94a83 commit 14f7750
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ describe Crystal::Formatter do
assert_format "a = \nif 1\n2\nend", "a =\n if 1\n 2\n end"
assert_format "a, b = \nif 1\n2\nend", "a, b =\n if 1\n 2\n end"
assert_format "a = b = 1\na, b =\n b, a"
assert_format "a = # foo\n bar(1)"
assert_format "a = \\\n # foo\n bar(1)"
assert_format "a = \\\n # foo\n nil"

assert_format %(require "foo"), %(require "foo")

Expand Down
6 changes: 3 additions & 3 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3294,7 +3294,7 @@ module Crystal
check_align = check_assign_length node.target
slash_is_regex!
write_token " ", :OP_EQ
skip_space
skip_space(consume_newline: false)
accept_assign_value_after_equals node.value, check_align: check_align

false
Expand Down Expand Up @@ -4491,7 +4491,7 @@ module Crystal
write_indent
next_token
@passed_backslash_newline = true
if @token.type.space?
if @token.type.space? || @token.type.comment?
return skip_space(write_comma, consume_newline)
else
return false
Expand Down Expand Up @@ -4620,7 +4620,7 @@ module Crystal

def write_comment(needs_indent = true, consume_newline = true, next_comes_end = false)
while @token.type.comment?
empty_line = @line_output.to_s.strip.empty?
empty_line = @line_output.empty?
if empty_line
write_indent if needs_indent
end
Expand Down

0 comments on commit 14f7750

Please sign in to comment.