Skip to content

Commit ae817a7

Browse files
authored
Merge pull request #343 from ruby-formatter/fix-342
Fix #342
2 parents cb5525c + 90471aa commit ae817a7

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

lib/rufo/formatter.rb

+13-13
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,22 @@ def visit(node)
252252
next_token
253253
else
254254
# For heredocs with tilde we sometimes need to align the contents
255-
if heredoc && tilde && @last_was_newline
256-
unless (current_token_value == "\n" ||
257-
current_token_kind == :on_heredoc_end)
258-
write_indent(next_indent)
259-
end
260-
skip_ignored_space
261-
if current_token_kind == :on_tstring_content
262-
check :on_tstring_content
263-
consume_token_value(current_token_value)
264-
next_token
255+
if heredoc && tilde
256+
while (current_token_kind == :on_ignored_sp) ||
257+
(current_token_kind == :on_tstring_content)
258+
if @last_was_newline && current_token_value != "\n"
259+
write_indent(next_indent)
260+
@last_was_newline = false
261+
end
262+
if current_token_kind == :on_ignored_sp
263+
skip_ignored_space
264+
else
265+
consume_token current_token_kind
266+
end
265267
end
266268
else
267269
while (current_token_kind == :on_ignored_sp) ||
268-
(current_token_kind == :on_tstring_content) ||
269-
(current_token_kind == :on_embexpr_beg)
270-
check current_token_kind
270+
(current_token_kind == :on_tstring_content)
271271
break if current_token_kind == :on_embexpr_beg
272272
consume_token current_token_kind
273273
end

spec/lib/rufo/formatter_source_specs/squiggly_heredoc.rb.spec

+13
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,16 @@ EOF
273273
heredoc
274274
EOF
275275
}
276+
277+
#~# ORIGINAL issue_342
278+
279+
foox <<~TEXT
280+
#{x}x
281+
a
282+
TEXT
283+
284+
#~# EXPECTED
285+
foox <<~TEXT
286+
#{x}x
287+
a
288+
TEXT

0 commit comments

Comments
 (0)