Skip to content

Commit

Permalink
Fix dialyzer on OTP 26
Browse files Browse the repository at this point in the history
  • Loading branch information
michalmuskala committed Nov 8, 2023
1 parent 822fe72 commit 6672a5e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
13 changes: 8 additions & 5 deletions src/erlfmt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
-type config_option() :: {pragma, pragma()} | {print_width, pos_integer()} | verbose.
-type config() :: [config_option()].

%% needed because of getopt being weird
-dialyzer({nowarn_function, [init/1, main/1]}).

-define(DEFAULT_WIDTH, 100).

%% escript entry point
Expand All @@ -60,7 +63,7 @@ main(Argv) ->
end.

%% rebar3 plugin entry point
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
-spec init(term()) -> {ok, term()}.
init(State) ->
rebar3_fmt_prv:init(State).

Expand Down Expand Up @@ -382,7 +385,7 @@ format_range(FileName, StartLocation, EndLocation, Options, Nodes, Warnings) ->

%% API entry point
-spec read_nodes(file:name_all()) ->
{ok, [erlfmt_parse:abstract_form()], [error_info()]} | {error, error_info()}.
{ok, [erlfmt_parse:abstract_node()], [error_info()]} | {error, error_info()}.
read_nodes(FileName) ->
try
file_read_nodes(FileName, ignore)
Expand Down Expand Up @@ -427,7 +430,7 @@ read_stdin(Acc) ->

%% API entry point
-spec read_nodes_string(file:name_all(), string()) ->
{ok, [erlfmt_parse:abstract_form()], [error_info()]} | {error, error_info()}.
{ok, [erlfmt_parse:abstract_node()], [error_info()]} | {error, error_info()}.
read_nodes_string(FileName, String) ->
try
read_nodes_string(FileName, String, ignore)
Expand Down Expand Up @@ -575,7 +578,7 @@ node_string(Cont) ->
{String, Anno} = erlfmt_scan:last_node_string_trimmed(Cont),
{raw_string, Anno, String}.

-spec format_nodes([erlfmt_parse:abstract_form()], pos_integer()) -> [unicode:chardata()].
-spec format_nodes([erlfmt_parse:abstract_node()], pos_integer()) -> [unicode:chardata()].
format_nodes([], _PrintWidth) ->
[];
format_nodes(Nodes, PrintWidth) ->
Expand All @@ -600,7 +603,7 @@ maybe_empty_line(Node, Next) ->
false -> ""
end.

-spec format_node(erlfmt_parse:abstract_form(), pos_integer()) -> unicode:chardata().
-spec format_node(erlfmt_parse:abstract_node(), pos_integer()) -> unicode:chardata().
format_node({raw_string, _Anno, String}, _PrintWidth) ->
String;
format_node(Node, PrintWidth) ->
Expand Down
4 changes: 3 additions & 1 deletion src/erlfmt_cli.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

-type parsed() :: {format, list(), list(), #config{}} | help | version | {error, string()}.

-spec opts() -> [getopt:option_spec()].
opts() ->
[
{help, $h, "help", undefined, "print this message"},
Expand Down Expand Up @@ -111,6 +110,9 @@ with_parsed(Name, Config) ->
set_difference(Files, Excludes) ->
sets:to_list(sets:subtract(sets:from_list(Files), sets:from_list(Excludes))).

%% needed because of getopt
-dialyzer({nowarn_function, [unprotected_with_config/2]}).

-spec unprotected_with_config(string(), parsed()) -> ok.
unprotected_with_config(Name, ParsedConfig) ->
case ParsedConfig of
Expand Down
8 changes: 4 additions & 4 deletions src/erlfmt_format.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

-define(INDENT, 4).

-spec to_algebra(erlfmt_parse:abstract_form()) -> erlfmt_algebra:doc().
-spec to_algebra(erlfmt_parse:any_node()) -> erlfmt_algebra:doc().
to_algebra({shebang, Meta, String}) ->
Doc = string(String),
combine_comments(Meta, Doc);
Expand Down Expand Up @@ -524,7 +524,7 @@ surround_container(#break{inner = ForceInner, outer = ForceOuter}, Left, Doc, Ri

%% last_fits_fun returns a fun similar to next_break_fits/2
%% that takes into account the desired fits behaviour.
-spec last_fits_fun(last_normal | last_fits, [erlfmt_parse:abstract_form()]) ->
-spec last_fits_fun(last_normal | last_fits, [erlfmt_parse:any_node()]) ->
fun((erlfmt_algebra:doc(), disabled | enabled) -> erlfmt_algebra:doc()).
last_fits_fun(last_fits, Values) when Values =/= [] ->
case is_next_break_fits(lists:last(Values)) of
Expand All @@ -545,7 +545,7 @@ has_trailing_comments(Values) ->
PostComments =/= []
end.

-spec has_opening_line_break(erlfmt_scan:anno(), [erlfmt_parse:abstract_form()]) -> boolean().
-spec has_opening_line_break(erlfmt_scan:anno(), [erlfmt_parse:any_node()]) -> boolean().
has_opening_line_break(_Meta, []) ->
false;
has_opening_line_break(Meta, [HeadValue | _]) ->
Expand All @@ -562,7 +562,7 @@ has_any_break_between(_) ->
break_fun(flex_break) -> fun erlfmt_algebra:flex_break/2;
break_fun(_) -> fun erlfmt_algebra:break/2.

-type value_doc_pair() :: {erlfmt_parse:abstract_form(), erlfmt_algebra:doc()}.
-type value_doc_pair() :: {erlfmt_parse:any_node(), erlfmt_algebra:doc()}.

map_inner_values(_LastFitsFun, []) ->
[];
Expand Down
4 changes: 4 additions & 0 deletions src/erlfmt_parse.yrl
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ Erlang code.
abstract_expr/0,
abstract_node/0,
abstract_type/0,
any_node/0,
form_info/0,
error_info/0
]).
Expand All @@ -691,6 +692,9 @@ Erlang code.
-type abstract_node() ::
af_function_decl() | af_attribute() | abstract_expr().

-type any_node() ::
abstract_node() | af_guard_test() | af_pattern() | af_field() | af_generator() | af_binelement(abstract_expr()).

-type af_attribute() :: {attribute, anno(), af_atom(), [abstract_expr()]}.

-type af_function_decl() :: {function, anno(), af_clause_seq()}.
Expand Down
2 changes: 1 addition & 1 deletion src/erlfmt_scan.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
read_rest/1
]).

-export_type([state/0, anno/0, token/0, comment/0]).
-export_type([state/0, anno/0, token/0, comment/0, location/0]).

-define(ERL_SCAN_OPTS, [
text, return_white_spaces, return_comments, {reserved_word_fun, fun reserved_word/1}
Expand Down

0 comments on commit 6672a5e

Please sign in to comment.