Skip to content

Commit

Permalink
erlfmt_format: dont group pipes, so they all break together
Browse files Browse the repository at this point in the history
  • Loading branch information
awalterschulze committed Aug 4, 2020
1 parent 1f6d78d commit 7baebc6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/erlfmt_format.erl
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,18 @@ binary_op_to_algebra(Op, Meta, Left, Right, Indent) ->
IsNextBreakFits = is_next_break_fits_op(Op, Right) andalso not HasBreak,

Doc =
with_next_break_fits(IsNextBreakFits, RightD, fun (R) ->
RightOpD = nest(break(concat(<<" ">>, OpD), group(R)), Indent, break),
concat(group(LeftD), group(concat(maybe_force_breaks(HasBreak), RightOpD)))
end),
case Op of
'|' ->
with_next_break_fits(IsNextBreakFits, RightD, fun (R) ->
RightOpD = nest(break(concat(<<" ">>, OpD), R), Indent, break),
concat(LeftD, concat(maybe_force_breaks(HasBreak), RightOpD))
end);
_ ->
with_next_break_fits(IsNextBreakFits, RightD, fun (R) ->
RightOpD = nest(break(concat(<<" ">>, OpD), group(R)), Indent, break),
concat(group(LeftD), group(concat(maybe_force_breaks(HasBreak), RightOpD)))
end)
end,

combine_comments(Meta, maybe_wrap_in_parens(Meta, Doc)).

Expand Down
10 changes: 10 additions & 0 deletions test/erlfmt_format_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,16 @@ spec(Config) when is_list(Config) ->
" another_long_type()\n"
") -> some_very:very(long, type).\n",
50
),
?assertFormat(
"-spec encode(#a{} | #blonglonglong{} | #c{} | #d{}) -> binary().",
"-spec encode(\n"
" #a{} |\n"
" #blonglonglong{} |\n"
" #c{} |\n"
" #d{}\n"
") -> binary().\n",
30
).

define(Config) when is_list(Config) ->
Expand Down

0 comments on commit 7baebc6

Please sign in to comment.