AdRoll / rebar3_format

Erlang Formatter for Rebar3
https://tech.nextroll.com/blog/dev/2020/02/25/erlang-rebar3-format.html
MIT License
108 stars 21 forks source link

Expand `sort_function_exports` option to format (sort) attributes with pure lists of arity qualifiers #327

Closed pablocostass closed 1 year ago

pablocostass commented 1 year ago

Currently, default_formatter formats this code, when sort_function_exports is set to true

%% assuming both the types and functions exist
-export_type([type_c/0, type_a/0, type_b/0, a_first_type/0]).
-export([b_fun/0, a_fun/0]).
-optional_callbacks([d_fun/0, c_fun/0]).

…like this…

%% only the export attribute is sorted
-export_type([type_c/0, type_a/0, type_b/0, a_first_type/0]).
-export([a_fun/0, b_fun/0]).
-optional_callbacks([d_fun/0, c_fun/0]).

I would like it to be formatted like this…

-export_type([a_first_type/0, type_a/0, type_b/0, type_c/0]).
-export([a_fun/0, b_fun/0]).
-optional_callbacks([c_fun/0, d_fun/0]).

It would be nice if the formatter were able to format (sort) other attributes than -export lists, as long as said attributes only contain arity qualifiers (e.g., -dialyzer([{nowarn_function, a_fun/0}, no_return]). should not be formatted (sorted)).