File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -561,7 +561,7 @@ defmodule Mix.Tasks.Format do
561
561
562
562
defp format_file ( { file , formatter } , task_opts ) do
563
563
input = read_file ( file )
564
- output = formatter . ( input )
564
+ output = bit_size ( input ) > 0 && formatter . ( input ) || << >>
565
565
check_formatted? = Keyword . get ( task_opts , :check_formatted , false )
566
566
dry_run? = Keyword . get ( task_opts , :dry_run , false )
567
567
Original file line number Diff line number Diff line change @@ -15,6 +15,16 @@ defmodule Mix.Tasks.FormatTest do
15
15
end
16
16
end
17
17
18
+ test "doesn't convert empty lines into line breaks" , context do
19
+ in_tmp ( context . test , fn ->
20
+ File . write! ( "a.exs" , "" )
21
+
22
+ Mix.Tasks.Format . run ( [ "a.exs" ] )
23
+
24
+ assert File . read! ( "a.exs" ) == ""
25
+ end )
26
+ end
27
+
18
28
test "formats the given files" , context do
19
29
in_tmp ( context . test , fn ->
20
30
File . write! ( "a.ex" , """
You can’t perform that action at this time.
0 commit comments