diff --git a/src/erlfmt_format.erl b/src/erlfmt_format.erl index fd53479..2f7d3b5 100644 --- a/src/erlfmt_format.erl +++ b/src/erlfmt_format.erl @@ -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); diff --git a/test/erlfmt_format_SUITE.erl b/test/erlfmt_format_SUITE.erl index b33c917..7fa0b0f 100644 --- a/test/erlfmt_format_SUITE.erl +++ b/test/erlfmt_format_SUITE.erl @@ -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.