@@ -506,6 +506,22 @@ defmodule Code.Formatter do
506
506
quoted_to_algebra ( { :if , meta , [ negate_condition ( condition ) , block ] } , context , state )
507
507
end
508
508
509
+ # a |> b() |> unless(...) => a |> b() |> Kernel.!() |> unless(...)
510
+ defp quoted_to_algebra (
511
+ { :|> , meta1 , [ { :|> , _ , _ } = condition , { :unless , meta2 , [ block ] } ] } ,
512
+ context ,
513
+ % { migrate_unless: true } = state
514
+ ) do
515
+ negated_condition = { :|> , [ ] , [ condition , { { :. , [ ] , [ Kernel , :! ] } , [ closing: [ ] ] , [ ] } ] }
516
+
517
+ quoted_to_algebra (
518
+ { :|> , meta1 , [ negated_condition , { :if , meta2 , [ block ] } ] } ,
519
+ context ,
520
+ state
521
+ )
522
+ end
523
+
524
+ # condition |> unless(...) => negated(condition) |> unless(...)
509
525
defp quoted_to_algebra (
510
526
{ :|> , meta1 , [ condition , { :unless , meta2 , [ block ] } ] } ,
511
527
context ,
@@ -2516,7 +2532,6 @@ defmodule Code.Formatter do
2516
2532
defp negate_condition ( condition ) do
2517
2533
case condition do
2518
2534
{ neg , _ , [ condition ] } when neg in [ :! , :not ] -> condition
2519
- { :|> , _ , _ } -> { :|> , [ ] , [ condition , { { :. , [ ] , [ Kernel , :! ] } , [ closing: [ ] ] , [ ] } ] }
2520
2535
{ op , _ , [ _ , _ ] } when op in @ bool_operators -> { :not , [ ] , [ condition ] }
2521
2536
{ guard , _ , [ _ | _ ] } when guard in @ guards -> { :not , [ ] , [ condition ] }
2522
2537
{ :== , meta , [ left , right ] } -> { :!= , meta , [ left , right ] }
0 commit comments