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

Formatter: fix end indent after comment inside begin #12994

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
10 changes: 10 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2416,4 +2416,14 @@ describe Crystal::Formatter do
end
end
CRYSTAL

# #12964
assert_format <<-CRYSTAL
begin
begin
a
# b
end
end
CRYSTAL
end
6 changes: 6 additions & 0 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,14 @@ module Crystal
@indent = old_indent

if has_newline && !last_found_comment && (!@wrote_newline || empty_expressions)
# Right after the last expression but we didn't insert a newline yet
# so we are still missing a newline following by an indent and the "end" keyword
write_line
write_indent
elsif has_newline && last_found_comment && @wrote_newline
# Right after the last expression and we did insert a newline (because of a comment)
# so we are still missing an indent and the "end" keyword
write_indent
end

if has_paren
Expand Down