From 7dff1b24722d59b977a6edb6b05ce64829235f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 10 Oct 2017 14:11:42 +0200 Subject: Consistently format operators in capture --- lib/elixir/lib/code/formatter.ex | 12 ++---------- lib/elixir/test/elixir/code_formatter/operators_test.exs | 5 ++++- 2 files changed, 6 insertions(+), 11 deletions(-) (limited to 'lib') 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 -- cgit v1.2.1