Skip to content

Commit eb74331

Browse files
fahchenclaude
andcommitted
fix: use IO.iodata_to_binary before pattern-matching format output
The pattern-matching on `Code.format_string!/2` output directly works on Elixir 1.19 where dialyzer infers binary() | nonempty_improper_list(), but fails on Elixir 1.18 where the return type is [binary()] and the "" pattern cannot match. Normalize to binary first so the check is version-agnostic. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f2b1caf commit eb74331

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

lib/dprint_markdown_formatter.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,14 @@ defmodule DprintMarkdownFormatter do
255255
# Remove dprint options to pass only valid Elixir formatter options
256256
elixir_opts = Keyword.drop(opts, @dprint_opts)
257257

258-
case Code.format_string!(formatted_content, elixir_opts) do
258+
formatted =
259+
formatted_content
260+
|> Code.format_string!(elixir_opts)
261+
|> IO.iodata_to_binary()
262+
263+
case formatted do
259264
"" -> {:ok, ""}
260-
formatted -> {:ok, IO.iodata_to_binary([formatted, ?\n])}
265+
_ -> {:ok, formatted <> "\n"}
261266
end
262267
end
263268
end

0 commit comments

Comments
 (0)