@@ -191,6 +191,7 @@ defmodule Code.Formatter do
191191 sigils = Keyword . get ( opts , :sigils , [ ] )
192192 migrate = Keyword . get ( opts , :migrate , false )
193193 migrate_bitstring_modifiers = Keyword . get ( opts , :migrate_bitstring_modifiers , migrate )
194+ migrate_call_parens_on_pipe = Keyword . get ( opts , :migrate_call_parens_on_pipe , migrate )
194195 migrate_charlists_as_sigils = Keyword . get ( opts , :migrate_charlists_as_sigils , migrate )
195196 migrate_unless = Keyword . get ( opts , :migrate_unless , migrate )
196197 syntax_colors = Keyword . get ( opts , :syntax_colors , [ ] )
@@ -218,6 +219,7 @@ defmodule Code.Formatter do
218219 sigils: sigils ,
219220 file: file ,
220221 migrate_bitstring_modifiers: migrate_bitstring_modifiers ,
222+ migrate_call_parens_on_pipe: migrate_call_parens_on_pipe ,
221223 migrate_charlists_as_sigils: migrate_charlists_as_sigils ,
222224 migrate_unless: migrate_unless ,
223225 inspect_opts: % Inspect.Opts { syntax_colors: syntax_colors }
@@ -487,7 +489,16 @@ defmodule Code.Formatter do
487489 binary_op_to_algebra ( :in , "not in" , meta , left , right , context , state )
488490 end
489491
490- # disable migrate_unless within defmacro
492+ # disable migrate_call_parens_on_pipe within defmacro
493+ defp quoted_to_algebra (
494+ { atom , _ , [ { :|> , _ , _ } , _ ] } = ast ,
495+ context ,
496+ % { migrate_call_parens_on_pipe: true } = state
497+ )
498+ when atom in [ :defmacro , :defmacrop ] do
499+ quoted_to_algebra ( ast , context , % { state | migrate_call_parens_on_pipe: false } )
500+ end
501+
491502 defp quoted_to_algebra (
492503 { atom , _ , [ { :unless , _ , _ } , _ ] } = ast ,
493504 context ,
@@ -832,6 +843,20 @@ defmodule Code.Formatter do
832843 { wrap_in_parens ( doc ) , state }
833844 end
834845
846+ defp binary_operand_to_algebra (
847+ { var , meta , atom } ,
848+ context ,
849+ % { migrate_call_parens_on_pipe: true } = state ,
850+ :|> ,
851+ _parent_info ,
852+ :right ,
853+ _nesting
854+ )
855+ when is_atom ( var ) and is_atom ( atom ) do
856+ operand = { var , meta , [ ] }
857+ quoted_to_algebra ( operand , context , state )
858+ end
859+
835860 defp binary_operand_to_algebra ( operand , context , state , parent_op , parent_info , side , nesting ) do
836861 { parent_assoc , parent_prec } = parent_info
837862
0 commit comments