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 #342 #343

Merged
merged 4 commits into from
Feb 8, 2025
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
26 changes: 13 additions & 13 deletions lib/rufo/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,22 +252,22 @@ def visit(node)
next_token
else
# For heredocs with tilde we sometimes need to align the contents
if heredoc && tilde && @last_was_newline
unless (current_token_value == "\n" ||
current_token_kind == :on_heredoc_end)
write_indent(next_indent)
end
skip_ignored_space
if current_token_kind == :on_tstring_content
check :on_tstring_content
consume_token_value(current_token_value)
next_token
if heredoc && tilde
while (current_token_kind == :on_ignored_sp) ||
(current_token_kind == :on_tstring_content)
if @last_was_newline && current_token_value != "\n"
write_indent(next_indent)
@last_was_newline = false
end
if current_token_kind == :on_ignored_sp
skip_ignored_space
else
consume_token current_token_kind
end
end
else
while (current_token_kind == :on_ignored_sp) ||
(current_token_kind == :on_tstring_content) ||
(current_token_kind == :on_embexpr_beg)
check current_token_kind
(current_token_kind == :on_tstring_content)
break if current_token_kind == :on_embexpr_beg
consume_token current_token_kind
end
Expand Down
13 changes: 13 additions & 0 deletions spec/lib/rufo/formatter_source_specs/squiggly_heredoc.rb.spec
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,16 @@ EOF
heredoc
EOF
}

#~# ORIGINAL issue_342

foox <<~TEXT
#{x}x
a
TEXT

#~# EXPECTED
foox <<~TEXT
#{x}x
a
TEXT