Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix formatter comment on extra line at end of method args #12908

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ describe Crystal::Formatter do
assert_format "foo.% bar"
assert_format "foo.bar(&.%(baz))"
assert_format "foo.bar(&.% baz)"
assert_format "if 1\n foo(\n bar\n # comment\n )\nend"
assert_format "if 1\n foo(\n bar,\n # comment\n )\nend"

assert_format "foo.bar\n.baz", "foo.bar\n .baz"
assert_format "foo.bar.baz\n.qux", "foo.bar.baz\n .qux"
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2766,7 +2766,7 @@ module Crystal
if @token.type.newline?
ends_with_newline = true
end
skip_space_or_newline
indent(base_indent + 2) { skip_space_or_newline(last: true, at_least_one: ends_with_newline) }
elsif has_args || node.block_arg
write " " unless passed_backslash_newline
skip_space
Expand Down Expand Up @@ -2958,8 +2958,9 @@ module Crystal
if @token.type.newline? && has_newlines
write ","
write_line
write_indent(column)
skip_space_or_newline(column + 2)
write_indent(column)
skip_space_or_newline(column)
else
found_comment |= skip_space_or_newline(column + 2)
if has_newlines
Expand Down