Skip to content

Commit 72bb758

Browse files
authored
Only remove -spec/-type from first line (#1894)
Before this change a spec looking like this: ``` -spec foo(integer()) -> ok; (atom()) -> ok. ``` would be transformed to: ``` -spec foo(integer()) -> ok; (atom()) -> ok. ``` that is the second clause would be indented incorrectly.
1 parent 7f8e971 commit 72bb758

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

lib/ex_doc/language/erlang.ex

+5-12
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,11 @@ defmodule ExDoc.Language.Erlang do
709709
offset = byte_size(Atom.to_string(type)) + 2
710710

711711
options = [linewidth: 98 + offset]
712-
:erl_pp.attribute(ast, options) |> IO.iodata_to_binary() |> trim_offset(offset)
712+
713+
:erl_pp.attribute(ast, options)
714+
|> IO.chardata_to_string()
715+
|> String.trim()
716+
|> String.trim_leading("-#{Atom.to_string(type)} ")
713717
end
714718

715719
## Helpers
@@ -723,15 +727,4 @@ defmodule ExDoc.Language.Erlang do
723727
:module
724728
end
725729
end
726-
727-
# `-type t() :: atom()` becomes `t() :: atom().`
728-
defp trim_offset(binary, offset) do
729-
binary
730-
|> String.trim()
731-
|> String.split("\n")
732-
|> Enum.map(fn line ->
733-
binary_part(line, offset, byte_size(line) - offset)
734-
end)
735-
|> Enum.join("\n")
736-
end
737730
end

0 commit comments

Comments
 (0)