Skip to content

Commit 6672a5e

Browse files
committed
Fix dialyzer on OTP 26
1 parent 822fe72 commit 6672a5e

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

‎src/erlfmt.erl‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
-type config_option() :: {pragma, pragma()} | {print_width, pos_integer()} | verbose.
4040
-type config() :: [config_option()].
4141

42+
%% needed because of getopt being weird
43+
-dialyzer({nowarn_function, [init/1, main/1]}).
44+
4245
-define(DEFAULT_WIDTH, 100).
4346

4447
%% escript entry point
@@ -60,7 +63,7 @@ main(Argv) ->
6063
end.
6164

6265
%% rebar3 plugin entry point
63-
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
66+
-spec init(term()) -> {ok, term()}.
6467
init(State) ->
6568
rebar3_fmt_prv:init(State).
6669

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

383386
%% API entry point
384387
-spec read_nodes(file:name_all()) ->
385-
{ok, [erlfmt_parse:abstract_form()], [error_info()]} | {error, error_info()}.
388+
{ok, [erlfmt_parse:abstract_node()], [error_info()]} | {error, error_info()}.
386389
read_nodes(FileName) ->
387390
try
388391
file_read_nodes(FileName, ignore)
@@ -427,7 +430,7 @@ read_stdin(Acc) ->
427430

428431
%% API entry point
429432
-spec read_nodes_string(file:name_all(), string()) ->
430-
{ok, [erlfmt_parse:abstract_form()], [error_info()]} | {error, error_info()}.
433+
{ok, [erlfmt_parse:abstract_node()], [error_info()]} | {error, error_info()}.
431434
read_nodes_string(FileName, String) ->
432435
try
433436
read_nodes_string(FileName, String, ignore)
@@ -575,7 +578,7 @@ node_string(Cont) ->
575578
{String, Anno} = erlfmt_scan:last_node_string_trimmed(Cont),
576579
{raw_string, Anno, String}.
577580

578-
-spec format_nodes([erlfmt_parse:abstract_form()], pos_integer()) -> [unicode:chardata()].
581+
-spec format_nodes([erlfmt_parse:abstract_node()], pos_integer()) -> [unicode:chardata()].
579582
format_nodes([], _PrintWidth) ->
580583
[];
581584
format_nodes(Nodes, PrintWidth) ->
@@ -600,7 +603,7 @@ maybe_empty_line(Node, Next) ->
600603
false -> ""
601604
end.
602605

603-
-spec format_node(erlfmt_parse:abstract_form(), pos_integer()) -> unicode:chardata().
606+
-spec format_node(erlfmt_parse:abstract_node(), pos_integer()) -> unicode:chardata().
604607
format_node({raw_string, _Anno, String}, _PrintWidth) ->
605608
String;
606609
format_node(Node, PrintWidth) ->

‎src/erlfmt_cli.erl‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

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

30-
-spec opts() -> [getopt:option_spec()].
3130
opts() ->
3231
[
3332
{help, $h, "help", undefined, "print this message"},
@@ -111,6 +110,9 @@ with_parsed(Name, Config) ->
111110
set_difference(Files, Excludes) ->
112111
sets:to_list(sets:subtract(sets:from_list(Files), sets:from_list(Excludes))).
113112

113+
%% needed because of getopt
114+
-dialyzer({nowarn_function, [unprotected_with_config/2]}).
115+
114116
-spec unprotected_with_config(string(), parsed()) -> ok.
115117
unprotected_with_config(Name, ParsedConfig) ->
116118
case ParsedConfig of

‎src/erlfmt_format.erl‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
-define(INDENT, 4).
4949

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

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

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

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

567567
map_inner_values(_LastFitsFun, []) ->
568568
[];

‎src/erlfmt_parse.yrl‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ Erlang code.
680680
abstract_expr/0,
681681
abstract_node/0,
682682
abstract_type/0,
683+
any_node/0,
683684
form_info/0,
684685
error_info/0
685686
]).
@@ -691,6 +692,9 @@ Erlang code.
691692
-type abstract_node() ::
692693
af_function_decl() | af_attribute() | abstract_expr().
693694

695+
-type any_node() ::
696+
abstract_node() | af_guard_test() | af_pattern() | af_field() | af_generator() | af_binelement(abstract_expr()).
697+
694698
-type af_attribute() :: {attribute, anno(), af_atom(), [abstract_expr()]}.
695699

696700
-type af_function_decl() :: {function, anno(), af_clause_seq()}.

‎src/erlfmt_scan.erl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
read_rest/1
4141
]).
4242

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

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

0 commit comments

Comments
 (0)