@@ -57,18 +57,25 @@ defmodule Styler.Style.Blocks do
5757
5858 zipper =
5959 case Zipper . up ( zipper ) do
60- { { := , am , [ parent_lhs , _single_clause_case ] } , _ } = zipper ->
61- # this was a `x = case head, do: (lhs -> rhs)`. make it `x = lhs = head; rhs`
60+ { { := , am , [ parent_lhs , _case_statement_rhs ] } , _ } = zipper ->
61+ # this was a `x = case head, do: (lhs -> rhs)`. make it `x = lhs = head; x = rhs`
6262 meta = [ line: am [ :line ] ]
63- Zipper . replace ( zipper , { := , meta , [ parent_lhs , { := , meta , [ lhs , head ] } ] } )
63+ # change the if there are multiple clauses in the case, have the final one be the new rhs of parent_lhs
64+ # the meta for the final equality has an incorrect line, but it shouldn't mess with comments so leaving it be
65+ siblings = List . update_at ( rhs , - 1 , & { := , meta , [ parent_lhs , & 1 ] } )
66+
67+ zipper
68+ |> Zipper . replace ( { := , meta , [ lhs , head ] } )
69+ |> Zipper . insert_siblings ( siblings )
6470
6571 _ ->
6672 zipper
6773 |> Style . find_nearest_block ( )
6874 |> Zipper . replace ( { := , [ line: m [ :line ] ] , [ lhs , head ] } )
75+ |> Zipper . insert_siblings ( rhs )
6976 end
7077
71- { :cont , Zipper . insert_siblings ( zipper , rhs ) , ctx }
78+ { :cont , zipper , ctx }
7279 end
7380
7481 def run ( { { :cond , _ , [ [ { do_ , clauses } ] ] } , _ } = zipper , ctx ) do
0 commit comments