1111% % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212% % See the License for the specific language governing permissions and
1313% % limitations under the License.
14+
1415-module (erlfmt_format ).
1516
1617-include (" erlfmt_scan.hrl" ).
4748
4849-define (INDENT , 4 ).
4950
50-
51-
52-
53- % % =============================================================================
54- % % this
55- % % =============================================================================
56-
57-
58-
5951-spec to_algebra (erlfmt_parse :any_node ()) -> erlfmt_algebra :doc ().
6052
6153to_algebra ({shebang , Meta , String }) ->
@@ -145,6 +137,29 @@ to_algebra({attribute, Meta, Name, Values}) ->
145137 ),
146138 combine_comments_with_dot (Meta , Doc );
147139
140+ to_algebra ({comment , Meta , _Lines } = Comment ) ->
141+ % % Handle standalone comments with banner detection
142+ case is_comment_banner (Comment ) of
143+ true ->
144+ % % Banner comments get extra spacing
145+ IsFirstInFile = erlfmt_scan :get_line (Meta ) =:= 1 ,
146+ if
147+ IsFirstInFile ->
148+ % % No leading lines for banner at start of file
149+ concat (comment_to_algebra (Comment ), line (4 ));
150+
151+ true ->
152+ % % Normal banner spacing
153+ concat (
154+ concat (line (4 ), comment_to_algebra (Comment )), line (4 )
155+ )
156+ end ;
157+
158+ false ->
159+ % % Regular comments
160+ comment_to_algebra (Comment )
161+ end ;
162+
148163to_algebra (Expr ) ->
149164 Meta = element (2 , Expr ),
150165 Doc = do_expr_to_algebra (Expr ),
@@ -1418,15 +1433,15 @@ combine_pre_comments(Comments, Meta, Doc) ->
14181433 HasBanner = lists :any (fun is_comment_banner /1 , Comments ),
14191434 [FirstComment | _ ] = Comments ,
14201435 IsFirstInFile = erlfmt_scan :get_line (FirstComment ) =:= 1 ,
1421-
1436+
14221437 case
14231438 erlfmt_scan :get_end_line (lists :last (Comments )) + 1 <
14241439 erlfmt_scan :get_inner_line (Meta )
14251440 of
14261441 true when HasBanner andalso IsFirstInFile ->
14271442 % % Banner is first in file with existing break - no leading lines
14281443 concat (concat (comments_to_algebra (Comments ), line (4 )), Doc );
1429-
1444+
14301445 true when HasBanner ->
14311446 % % There's already a break, so add 3 more lines to get 4 total
14321447 concat (
@@ -1440,7 +1455,7 @@ combine_pre_comments(Comments, Meta, Doc) ->
14401455 false when HasBanner andalso IsFirstInFile ->
14411456 % % Banner is first in file with no break - no leading lines
14421457 concat (concat (comments_to_algebra (Comments ), line (4 )), Doc );
1443-
1458+
14441459 false when HasBanner ->
14451460 % % No existing break, so add all 4 lines
14461461 concat (
@@ -1490,7 +1505,6 @@ comment_to_algebra({comment, _Meta, Lines}) ->
14901505
14911506
14921507
1493-
14941508% % Detect comment banners (section dividers with === patterns)
14951509
14961510
0 commit comments