Ensure -> does not pass line lengths, closes #7279
This commit is contained in:
@@ -1599,10 +1599,16 @@ defmodule Code.Formatter do
|
||||
{args_doc, state} = clause_args_to_algebra(args, min_line, state)
|
||||
{body_doc, state} = block_to_algebra(body, min_line, max_line, state)
|
||||
|
||||
head =
|
||||
args_doc
|
||||
|> ungroup_if_group()
|
||||
|> concat(" ->")
|
||||
|> nest(:cursor)
|
||||
|> group()
|
||||
|
||||
doc =
|
||||
"fn "
|
||||
|> concat(group(nest(args_doc, :cursor)))
|
||||
|> concat(" ->")
|
||||
|> concat(head)
|
||||
|> glue(body_doc)
|
||||
|> nest(2)
|
||||
|> glue("end")
|
||||
@@ -1648,15 +1654,12 @@ defmodule Code.Formatter do
|
||||
{args_doc, state} = clause_args_to_algebra(args, min_line, state)
|
||||
{body_doc, state} = block_to_algebra(body, min_line, max_line, state)
|
||||
|
||||
clause_doc =
|
||||
" ->"
|
||||
|> glue(body_doc)
|
||||
|> nest(2)
|
||||
|
||||
doc =
|
||||
args_doc
|
||||
|> ungroup_if_group()
|
||||
|> concat(" ->")
|
||||
|> group()
|
||||
|> concat(clause_doc)
|
||||
|> concat(break() |> concat(body_doc) |> nest(2))
|
||||
|> wrap_in_parens()
|
||||
|> maybe_force_clauses(clauses)
|
||||
|> group()
|
||||
@@ -1724,7 +1727,15 @@ defmodule Code.Formatter do
|
||||
|
||||
state = %{state | operand_nesting: nesting}
|
||||
{body_doc, state} = block_to_algebra(body, min_line, end_line(meta), state)
|
||||
{concat(args_doc, " ->" |> glue(body_doc) |> nest(2)), state}
|
||||
|
||||
doc =
|
||||
args_doc
|
||||
|> ungroup_if_group()
|
||||
|> concat(" ->")
|
||||
|> group()
|
||||
|> concat(break() |> concat(body_doc) |> nest(2))
|
||||
|
||||
{doc, state}
|
||||
end
|
||||
|
||||
defp add_max_line_to_last_clause([{op, meta, args}], max_line) do
|
||||
|
||||
@@ -161,7 +161,8 @@ defimpl Enumerable, for: GenEvent.Stream do
|
||||
|
||||
defp flush_events(ref) do
|
||||
receive do
|
||||
{_from, {_pid, ^ref}, {notify, _event}} when notify in [:notify, :ack_notify, :sync_notify] ->
|
||||
{_from, {_pid, ^ref}, {notify, _event}}
|
||||
when notify in [:notify, :ack_notify, :sync_notify] ->
|
||||
flush_events(ref)
|
||||
after
|
||||
0 -> :ok
|
||||
|
||||
@@ -329,6 +329,46 @@ defmodule Code.Formatter.GeneralTest do
|
||||
end
|
||||
"""
|
||||
end
|
||||
|
||||
test "with -> on line limit" do
|
||||
bad = """
|
||||
fn ab, cd ->
|
||||
ab + cd
|
||||
end
|
||||
"""
|
||||
|
||||
good = """
|
||||
fn ab,
|
||||
cd ->
|
||||
ab + cd
|
||||
end
|
||||
"""
|
||||
|
||||
assert_format bad, good, @short_length
|
||||
|
||||
bad = """
|
||||
fn
|
||||
ab, cd ->
|
||||
1
|
||||
xy, zw ->
|
||||
2
|
||||
end
|
||||
"""
|
||||
|
||||
good = """
|
||||
fn
|
||||
ab,
|
||||
cd ->
|
||||
1
|
||||
|
||||
xy,
|
||||
zw ->
|
||||
2
|
||||
end
|
||||
"""
|
||||
|
||||
assert_format bad, good, @short_length
|
||||
end
|
||||
end
|
||||
|
||||
describe "anonymous functions types" do
|
||||
|
||||
Reference in New Issue
Block a user