Skip to content

Commit

Permalink
Fixes AdRoll#249: Spacing for empty records (AdRoll#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkatsuba authored May 6, 2021
1 parent 9c46cdd commit 6c400e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/formatters/default_formatter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,8 @@ number_from_text(Text, Default) ->

lay_fields(Opening, Exprs, Ctxt = #ctxt{spaces_around_fields = false}, Fun) ->
beside(Opening, beside(lay_fields(Exprs, Ctxt, Fun), lay_text_float("}")));
lay_fields(Opening, [] = Exprs, Ctxt = #ctxt{spaces_around_fields = true}, Fun) ->
lay_fields(Opening, Exprs, Ctxt#ctxt{spaces_around_fields = false}, Fun);
lay_fields(Opening, Exprs, Ctxt = #ctxt{spaces_around_fields = true}, Fun) ->
par([par([Opening, lay_fields(Exprs, Ctxt, Fun)], Ctxt#ctxt.break_indent),
lay_text_float("}")]).
Expand Down
9 changes: 7 additions & 2 deletions test_app/after/src/records.erl
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
-module(records).

-format #{ spaces_around_fields => true }.

-record(record, {with_another :: #record{}, in_it}).
-record(rec, {}).

-type record() :: #record{in_it :: 1..3}.
-type record() :: #record{ in_it :: 1..3 }.
-type rec() :: #rec{}.

f(A) ->
_ = #rec{},
B = C = A#record.with_another#record.with_another#record.in_it,
D = A#record{with_another = #record{with_another = #record{in_it = B}, in_it = C}},
D = A#record{ with_another = #record{ with_another = #record{ in_it = B }, in_it = C } },
(normalize(D))#record.with_another#record.in_it.
5 changes: 5 additions & 0 deletions test_app/src/records.erl
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
-module(records).

-format #{spaces_around_fields => true}.

-record(record, {with_another :: #record{}, in_it}).
-record(rec, {}).
-type record() :: #record{in_it :: 1..3}.
-type rec() :: #rec{}.

f(A) ->
_ = #rec{},
B = C = A#record.with_another#record.with_another#record.in_it,
D = A#record{with_another = #record{with_another = #record{in_it = B}, in_it = C}},
(normalize(D))#record.with_another#record.in_it.

0 comments on commit 6c400e4

Please sign in to comment.