Skip to content

Commit 5d0519c

Browse files
committed
Change mix format to skip empty '.ex' and '.exs' files
1 parent 549a867 commit 5d0519c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/mix/lib/mix/tasks/format.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ defmodule Mix.Tasks.Format do
561561

562562
defp format_file({file, formatter}, task_opts) do
563563
input = read_file(file)
564-
output = formatter.(input)
564+
output = bit_size(input) > 0 && formatter.(input) || <<>>
565565
check_formatted? = Keyword.get(task_opts, :check_formatted, false)
566566
dry_run? = Keyword.get(task_opts, :dry_run, false)
567567

lib/mix/test/mix/tasks/format_test.exs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ defmodule Mix.Tasks.FormatTest do
1515
end
1616
end
1717

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+
1828
test "formats the given files", context do
1929
in_tmp(context.test, fn ->
2030
File.write!("a.ex", """

0 commit comments

Comments
 (0)