Skip to content

Commit

Permalink
Remove docs from doc and moduledoc attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
michalmuskala committed Sep 3, 2024
1 parent 925e48a commit fcb71a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/erlfmt_format.erl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ to_algebra({attribute, Meta, {atom, _, record}, [Name, {tuple, TMeta, Values} =
Doc = surround(HeadD, <<"">>, expr_to_algebra(Tuple), <<"">>, <<")">>),
combine_comments_with_dot(Meta, Doc)
end;
to_algebra({attribute, Meta, {atom, _, RawName} = Name, [Value]}) when
RawName =:= doc; RawName =:= moduledoc
->
ValueD = expr_to_algebra(Value),
Doc = concat([<<"-">>, expr_to_algebra(Name), <<" ">>, ValueD]),
combine_comments_with_dot(Meta, Doc);
to_algebra({attribute, Meta, Name, Values}) ->
Doc = concat(<<"-">>, attribute_to_algebra(Name), call(Meta, Values, <<"(">>, <<")">>)),
combine_comments_with_dot(Meta, Doc);
Expand Down
8 changes: 4 additions & 4 deletions test/erlfmt_format_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4283,10 +4283,10 @@ comment(Config) when is_list(Config) ->
).

doc_attributes(Config) when is_list(Config) ->
?assertSame("-moduledoc(\"Test\").\n-moduledoc(#{since => <<\"1.0.0\">>}).\n"),
?assertSame("-moduledoc(\"\"\"\nTest\nMultiline\n\"\"\").\n"),
?assertSame("-doc(\"Test\").\n-doc(#{since => <<\"1.0.0\">>}).\ntest() -> ok.\n"),
?assertSame("-doc(\"Test\").\n-doc(#{since => <<\"1.0.0\">>}).\n-type t() :: ok.\n").
?assertSame("-moduledoc \"Test\".\n-moduledoc #{since => <<\"1.0.0\">>}.\n"),
?assertSame("-moduledoc \"\"\"\nTest\nMultiline\n\"\"\".\n"),
?assertSame("-doc \"Test\".\n-doc #{since => <<\"1.0.0\">>}.\ntest() -> ok.\n"),
?assertSame("-doc \"Test\".\n-doc #{since => <<\"1.0.0\">>}.\n-type t() :: ok.\n").

doc_macros(Config) when is_list(Config) ->
%% Doc Attributes as macros is a common pattern for OTP < 27 compatibility.
Expand Down

0 comments on commit fcb71a3

Please sign in to comment.