Skip to content

Commit bb1f1af

Browse files
committed
Trim trailing whitespace on heredocs with \r\n
1 parent a32ce8b commit bb1f1af

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Diff for: lib/elixir/lib/code/formatter.ex

+1
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,7 @@ defmodule Code.Formatter do
16831683
end
16841684

16851685
defp heredoc_line(["", _ | _]), do: nest(line(), :reset)
1686+
defp heredoc_line(["\r", _ | _]), do: nest(line(), :reset)
16861687
defp heredoc_line(_), do: line()
16871688

16881689
defp args_to_algebra_with_comments(args, meta, skip_parens?, last_arg_mode, join, state, fun) do

Diff for: lib/elixir/test/elixir/code_formatter/literals_test.exs

+8
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,14 @@ defmodule Code.Formatter.LiteralsTest do
384384
"""
385385
'''
386386
end
387+
388+
test "with new lines" do
389+
assert_format ~s|foo do\n """\n foo\n \n bar\n """\nend|,
390+
~s|foo do\n """\n foo\n\n bar\n """\nend|
391+
392+
assert_format ~s|foo do\r\n """\r\n foo\r\n \r\n bar\r\n """\r\nend|,
393+
~s|foo do\n """\n foo\r\n\r\n bar\r\n """\nend|
394+
end
387395
end
388396

389397
describe "charlist heredocs" do

0 commit comments

Comments
 (0)