File tree Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -262,6 +262,10 @@ defmodule CodeTest do
262
262
end
263
263
end
264
264
265
+ test "format_string/2 returns empty iodata for empty string" do
266
+ assert Code . format_string! ( "" ) == [ ]
267
+ end
268
+
265
269
test "ensure_loaded?/1" do
266
270
assert Code . ensure_loaded? ( __MODULE__ )
267
271
refute Code . ensure_loaded? ( Code.NoFile )
Original file line number Diff line number Diff line change @@ -544,6 +544,8 @@ defmodule Mix.Tasks.Format do
544
544
defp stdin_or_wildcard ( "-" ) , do: [ :stdin ]
545
545
defp stdin_or_wildcard ( path ) , do: path |> Path . expand ( ) |> Path . wildcard ( match_dot: true )
546
546
547
+ defp elixir_format ( "" , _formatter_opts ) , do: ""
548
+
547
549
defp elixir_format ( content , formatter_opts ) do
548
550
IO . iodata_to_binary ( [ Code . format_string! ( content , formatter_opts ) , ?\n ] )
549
551
end
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 format 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