@@ -615,9 +615,14 @@ format_nodes_loop([], _PrintWidth) ->
615615 [].
616616
617617maybe_empty_line (Node , Next ) ->
618- case has_empty_line_between (Node , Next ) of
619- true -> " \n " ;
620- false -> " "
618+ case should_add_extra_newlines (Node , Next ) of
619+ two -> " \n\n " ; % Always add two newlines
620+ one -> " \n " ; % Always add one newline
621+ zero ->
622+ case has_empty_line_between (Node , Next ) of
623+ true -> " \n " ;
624+ false -> " "
625+ end
621626 end .
622627
623628-spec format_node (erlfmt_parse :abstract_node (), pos_integer ()) -> unicode :chardata ().
@@ -630,6 +635,21 @@ format_node(Node, PrintWidth) ->
630635has_empty_line_between (Left , Right ) ->
631636 erlfmt_scan :get_end_line (Left ) + 1 < erlfmt_scan :get_line (Right ).
632637
638+ % % Determine if we should add extra newlines between nodes based on their types
639+ should_add_extra_newlines (Node , Next ) ->
640+ case {node_type (Node ), node_type (Next )} of
641+ {spec , function } -> one ; % Add one newline between spec and function
642+ {function , spec } -> two ; % Add two newlines between function and next spec
643+ _ -> zero
644+ end .
645+
646+ % % Get the type of a node for spacing decisions
647+ node_type ({attribute , _ , spec , _ }) -> spec ;
648+ node_type ({attribute , _ , callback , _ }) -> spec ; % Treat callback same as spec
649+ node_type ({function , _ , _ }) -> function ;
650+ node_type ({raw_string , _ , _ }) -> raw_string ;
651+ node_type (_ ) -> other .
652+
633653verify_nodes (FileName , Nodes , Formatted ) ->
634654 Flattened = unicode :characters_to_list (Formatted ),
635655 case read_nodes_string (FileName , Flattened ) of
0 commit comments