Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Commit ebe6210

Browse files
Update formatters with changes from OTP 26 (#364)
1 parent 32fa348 commit ebe6210

32 files changed

+194
-76
lines changed

.github/workflows/erlang.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
otp: ['24.3', '25.2.1']
17-
rebar: ['3.20.0']
16+
otp: ['25', '26']
17+
rebar: ['3.24']
1818

1919
steps:
20-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v4
2121
- uses: erlef/setup-beam@v1
2222
id: setup-beam
2323
with:
2424
otp-version: ${{matrix.otp}}
2525
rebar3-version: ${{matrix.rebar}}
2626
- name: Restore _build
27-
uses: actions/cache@v2
27+
uses: actions/cache@v4
2828
with:
2929
path: _build
3030
key: _build-cache-for-os-${{runner.os}}-otp-${{steps.setup-beam.outputs.otp-version}}-rebar3-${{steps.setup-beam.outputs.rebar3-version}}-hash-${{hashFiles('rebar.lock')}}
3131
- name: Restore rebar3's cache
32-
uses: actions/cache@v2
32+
uses: actions/cache@v4
3333
with:
3434
path: ~/.cache/rebar3
3535
key: rebar3-cache-for-os-${{runner.os}}-otp-${{steps.setup-beam.outputs.otp-version}}-rebar3-${{steps.setup-beam.outputs.rebar3-version}}-hash-${{hashFiles('rebar.lock')}}

nextroll.dict

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ lay_clauses
3535
lay_items
3636
old-reliable
3737
otp25
38+
otp26
39+
otp27
3840
paragraph-format
3941
per-file
4042
plugin

rebar.config

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{erl_opts, [warn_unused_import, warn_export_vars, verbose, report, debug_info]}.
22

3-
{minimum_otp_vsn, "24"}.
3+
{minimum_otp_vsn, "25"}.
44

5-
{deps, [{katana_code, "~> 2.1.0"}]}.
5+
{deps, [{katana_code, "~> 2.2.0"}]}.
66

77
{ex_doc,
88
[{source_url, <<"https://github.com/AdRoll/rebar3_format">>},
@@ -13,12 +13,13 @@
1313

1414
{project_plugins,
1515
[{rebar3_hex, "~> 7.0.8"},
16-
{rebar3_hank, "~> 1.4.0"},
17-
{rebar3_lint, "~> 3.2.5"},
16+
{rebar3_hank, "~> 1.4.1"},
17+
{rebar3_lint, "~> 3.2.6"},
1818
{rebar3_sheldon, "~> 0.4.3"},
19-
{rebar3_ex_doc, "~> 0.2.23"}]}.
19+
{rebar3_ex_doc, "~> 0.2.24"}]}.
2020

21-
{dialyzer, [{warnings, [no_return, unmatched_returns, error_handling, underspecs]}]}.
21+
{dialyzer,
22+
[{warnings, [no_unknown, no_return, unmatched_returns, error_handling, underspecs]}]}.
2223

2324
{edoc_opts, [{todo, true}, {overview, "priv/overview.edoc"}]}.
2425

rebar.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{"1.2.0",
2-
[{<<"katana_code">>,{pkg,<<"katana_code">>,<<"2.1.0">>},0}]}.
2+
[{<<"katana_code">>,{pkg,<<"katana_code">>,<<"2.2.0">>},0}]}.
33
[
44
{pkg_hash,[
5-
{<<"katana_code">>, <<"0C42BDCD7E59995876AED9F678CF62E3D12EF42E0FBB2190556E64BFEBDD15C6">>}]},
5+
{<<"katana_code">>, <<"B67EAA70022702AFEC2803E33C89ABE3D817197E7A16246614FED42E03AA8753">>}]},
66
{pkg_hash_ext,[
7-
{<<"katana_code">>, <<"AE3BBACA187511588F69695A9FF22251CB2CC672FDCCC180289779BDD25175EF">>}]}
7+
{<<"katana_code">>, <<"A01F9FDBA838478FDFDE183A324FA12ECE9BA127935065395D01427FC5110CBB">>}]}
88
].

src/formatters/default_formatter.erl

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -594,18 +594,17 @@ lay_no_comments(Node, Ctxt) ->
594594
Ctxt1 = reset_prec(Ctxt),
595595
D1 = lay(erl_syntax:generator_pattern(Node), Ctxt1),
596596
D2 = lay(erl_syntax:generator_body(Node), Ctxt1),
597-
prettypr:par([D1,
598-
prettypr:beside(
599-
prettypr:text("<- "), D2)],
600-
Ctxt1#ctxt.break_indent);
597+
lay_generator(D1, D2, "<- ", Ctxt1);
601598
binary_generator ->
602599
Ctxt1 = reset_prec(Ctxt),
603600
D1 = lay(erl_syntax:binary_generator_pattern(Node), Ctxt1),
604601
D2 = lay(erl_syntax:binary_generator_body(Node), Ctxt1),
605-
prettypr:par([D1,
606-
prettypr:beside(
607-
prettypr:text("<= "), D2)],
608-
Ctxt1#ctxt.break_indent);
602+
lay_generator(D1, D2, "<= ", Ctxt1);
603+
map_generator ->
604+
Ctxt1 = reset_prec(Ctxt),
605+
D1 = lay(erl_syntax:map_generator_pattern(Node), Ctxt1),
606+
D2 = lay(erl_syntax:map_generator_body(Node), Ctxt1),
607+
lay_generator(D1, D2, "<- ", Ctxt1);
609608
implicit_fun ->
610609
D = lay(erl_syntax:implicit_fun_name(Node), reset_prec(Ctxt)),
611610
prettypr:beside(lay_text_float("fun "), D);
@@ -621,6 +620,12 @@ lay_no_comments(Node, Ctxt) ->
621620
D2 = lay_items(erl_syntax:binary_comp_body(Node), Ctxt1, fun lay/2),
622621
D3 = prettypr:beside(lay_text_float("|| "), prettypr:beside(D2, lay_text_float(" >>"))),
623622
prettypr:beside(lay_text_float("<< "), prettypr:par([D1, D3]));
623+
map_comp ->
624+
Ctxt1 = reset_prec(Ctxt),
625+
D1 = lay(erl_syntax:map_comp_template(Node), Ctxt1),
626+
D2 = lay_items(erl_syntax:map_comp_body(Node), Ctxt1, fun lay/2),
627+
D3 = prettypr:beside(lay_text_float("|| "), prettypr:beside(D2, lay_text_float("}"))),
628+
prettypr:beside(lay_text_float("#{"), prettypr:par([D1, D3]));
624629
macro ->
625630
%% This is formatted similar to a normal function call or a variable
626631
N = macro_name(Node, variable),
@@ -1084,6 +1089,12 @@ maybe_convert_to_qualifier(Node, #ctxt{force_arity_qualifiers = true}) ->
10841089
Node
10851090
end.
10861091

1092+
lay_generator(D1, D2, Connector, Ctxt) ->
1093+
prettypr:par([D1,
1094+
prettypr:beside(
1095+
prettypr:text(Connector), D2)],
1096+
Ctxt#ctxt.break_indent).
1097+
10871098
lay_nested_infix_expr(Node, #ctxt{parenthesize_infix_operations = false} = Ctxt) ->
10881099
lay(Node, Ctxt);
10891100
lay_nested_infix_expr(Node, #ctxt{parenthesize_infix_operations = true} = Ctxt) ->

src/formatters/otp_formatter.erl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,11 @@ lay_no_comments(Node, Ctxt) ->
664664
D1 = lay(erl_syntax:binary_generator_pattern(Node), Ctxt1),
665665
D2 = lay(erl_syntax:binary_generator_body(Node), Ctxt1),
666666
par([D1, beside(text("<= "), D2)], Ctxt1#ctxt.break_indent);
667+
map_generator ->
668+
Ctxt1 = reset_prec(Ctxt),
669+
D1 = lay(erl_syntax:map_generator_pattern(Node), Ctxt1),
670+
D2 = lay(erl_syntax:map_generator_body(Node), Ctxt1),
671+
par([D1, beside(text("<- "), D2)], Ctxt1#ctxt.break_indent);
667672
implicit_fun ->
668673
D = lay(erl_syntax:implicit_fun_name(Node), reset_prec(Ctxt)),
669674
beside(lay_text_float("fun "), D);
@@ -679,6 +684,12 @@ lay_no_comments(Node, Ctxt) ->
679684
D2 = par(seq(erl_syntax:binary_comp_body(Node), lay_text_float(","), Ctxt1, fun lay/2)),
680685
beside(lay_text_float("<< "),
681686
par([D1, beside(lay_text_float(" || "), beside(D2, lay_text_float(" >>")))]));
687+
map_comp ->
688+
Ctxt1 = set_prec(Ctxt, max_prec()),
689+
D1 = lay(erl_syntax:map_comp_template(Node), Ctxt1),
690+
D2 = par(seq(erl_syntax:map_comp_body(Node), lay_text_float(","), Ctxt1, fun lay/2)),
691+
beside(lay_text_float("#{"),
692+
par([D1, beside(lay_text_float("|| "), beside(D2, lay_text_float("}")))]));
682693
macro ->
683694
%% This is formatted similar to a normal function call, but
684695
%% prefixed with a "?".

test/otp_formatter_SUITE.erl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,24 @@ test_app(_Config) ->
1717
case string:to_integer(
1818
erlang:system_info(otp_release))
1919
of
20-
{N, _} when N >= 25 ->
20+
{N, _} when N >= 26 ->
2121
{ignore,
22-
["src/*_ignore.erl",
22+
["src/strings/non_heredoc.erl", %% newlines in strings are treated differently since OTP26
23+
"src/*_ignore.erl",
2324
"src/comments.erl",
2425
"src/ignored_file_config.erl",
2526
"src/dodge_macros.erl",
2627
"src/macros_in_specs.erl",
2728
"src/receive_after.erl"]};
29+
{25, _} ->
30+
{ignore,
31+
["src/*_ignore.erl",
32+
"src/comments.erl",
33+
"src/ignored_file_config.erl",
34+
"src/dodge_macros.erl",
35+
"src/macros_in_specs.erl",
36+
"src/receive_after.erl",
37+
"src/otp26.erl"]};
2838
_ ->
2939
{ignore,
3040
["src/*_ignore.erl",
@@ -33,6 +43,7 @@ test_app(_Config) ->
3343
"src/dodge_macros.erl",
3444
"src/macros_in_specs.erl",
3545
"src/receive_after.erl",
46+
"src/otp26.erl",
3647
"src/otp25.erl"]}
3748
end,
3849
State2 = rebar_state:set(State1, format, [Files, Formatter, IgnoredFiles]),

test/test_app_SUITE.erl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,20 @@ init_test_app() ->
5050
case string:to_integer(
5151
erlang:system_info(otp_release))
5252
of
53-
{N, []} when N >= 25 ->
54-
{ignore, ["src/*_ignore.erl", "src/ignored_file_config.erl"]};
53+
{N, _} when N >= 26 ->
54+
%% newlines in strings are treated differently since OTP26
55+
{ignore,
56+
["src/strings/non_heredoc.erl",
57+
"src/*_ignore.erl",
58+
"src/ignored_file_config.erl"]};
59+
{25, _} ->
60+
{ignore, ["src/*_ignore.erl", "src/ignored_file_config.erl", "src/otp26.erl"]};
5561
_ ->
56-
{ignore, ["src/*_ignore.erl", "src/ignored_file_config.erl", "src/otp25.erl"]}
62+
{ignore,
63+
["src/*_ignore.erl",
64+
"src/ignored_file_config.erl",
65+
"src/otp26.erl",
66+
"src/otp25.erl"]}
5767
end,
5868
rebar_state:set(State1, format, [Files, IgnoredFiles]).
5969

test_app/after/src/brackets.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-module(brackets).
22

3-
-format #{inline_items => all, paper => 50}.
3+
-format #{inline_items => all}.
4+
-format #{paper => 50}.
45

56
-compile(export_all).
67

test_app/after/src/brackets_ignore.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
%% This module should not be formatted since it's in the list of ignored modules
22
-module(brackets_ignore).
33

4-
-format(#{paper => 50, inline_items => all}).
4+
-format(#{paper => 50}).
5+
-format(#{inline_items => all}).
56

67
-compile(export_all).
78

0 commit comments

Comments
 (0)