diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2017-10-10 14:11:42 +0200 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2017-10-10 14:19:42 +0200 |
commit | 7dff1b24722d59b977a6edb6b05ce64829235f0d (patch) | |
tree | 65244009a1cc8bd338f26ab8f23a71f61ef85415 /lib | |
parent | 547d042398d1e7191df9f1004c84f880019ea375 (diff) | |
download | elixir-7dff1b24722d59b977a6edb6b05ce64829235f0d.tar.gz |
Consistently format operators in capture
Diffstat (limited to 'lib')
-rw-r--r-- | lib/elixir/lib/code/formatter.ex | 12 | ||||
-rw-r--r-- | lib/elixir/test/elixir/code_formatter/operators_test.exs | 5 |
2 files changed, 6 insertions, 11 deletions
diff --git a/lib/elixir/lib/code/formatter.ex b/lib/elixir/lib/code/formatter.ex index 39bc37a4e..7516cad80 100644 --- a/lib/elixir/lib/code/formatter.ex +++ b/lib/elixir/lib/code/formatter.ex @@ -830,17 +830,9 @@ defmodule Code.Formatter do {string("#{name}/#{arity}"), state} end - defp capture_target_to_algebra({op, _, [_, _]} = arg, context, state) when is_atom(op) do - {doc, state} = quoted_to_algebra(arg, context, state) - - case Code.Identifier.binary_op(op) do - {_, _} -> {wrap_in_parens(doc), state} - _ -> {doc, state} - end - end - defp capture_target_to_algebra(arg, context, state) do - quoted_to_algebra(arg, context, state) + {doc, state} = quoted_to_algebra(arg, context, state) + {wrap_in_parens_if_necessary(arg, doc), state} end ## Calls (local, remote and anonymous) diff --git a/lib/elixir/test/elixir/code_formatter/operators_test.exs b/lib/elixir/test/elixir/code_formatter/operators_test.exs index 3b8733e53..f0d940d7f 100644 --- a/lib/elixir/test/elixir/code_formatter/operators_test.exs +++ b/lib/elixir/test/elixir/code_formatter/operators_test.exs @@ -673,7 +673,8 @@ defmodule Code.Formatter.OperatorsTest do end test "with operators inside" do - assert_format "&(+1)", "&+1" + assert_format "& +1", "&(+1)" + assert_format "& not &1", "&(not &1)" assert_format "& a ++ b", "&(a ++ b)" assert_format "& &1 && &2", "&(&1 && &2)" assert_same "&(&1 | &2)" @@ -686,6 +687,7 @@ defmodule Code.Formatter.OperatorsTest do test "with call expressions" do assert_format "& local(&1, &2)", "&local(&1, &2)" + assert_format "&-local(&1, &2)", "&(-local(&1, &2))" end test "with blocks" do @@ -721,6 +723,7 @@ defmodule Code.Formatter.OperatorsTest do assert_same "&+/2" assert_same "&and/2" assert_same "& &&/2" + assert_same "& &/1" end test "Module.remote/arity" do |