Skip to content

Commit 4b480cb

Browse files
committed
Allow iodata in sigil formatting functions
1 parent f809d03 commit 4b480cb

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/elixir/lib/code/formatter.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,12 +1330,12 @@ defmodule Code.Formatter do
13301330
]
13311331

13321332
case callback.(hd(entries), metadata) do
1333-
binary when is_binary(binary) ->
1334-
[binary]
1333+
iodata when is_binary(iodata) or is_list(iodata) ->
1334+
[IO.iodata_to_binary(iodata)]
13351335

13361336
other ->
13371337
raise ArgumentError,
1338-
"expected sigil callback to return a binary, got: #{inspect(other)}"
1338+
"expected sigil callback to return iodata, got: #{inspect(other)}"
13391339
end
13401340

13411341
%{} ->

lib/elixir/test/elixir/code_formatter/general_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ defmodule Code.Formatter.GeneralTest do
142142

143143
formatter = fn content, opts ->
144144
assert opts == [file: nil, line: 1, sigil: :W, modifiers: 'abc']
145-
content |> String.split(~r/ +/) |> Enum.join(" ")
145+
content |> String.split(~r/ +/) |> Enum.intersperse(" ")
146146
end
147147

148148
assert_format bad, good, sigils: [W: formatter]

0 commit comments

Comments
 (0)