Skip to content

Commit 3d0273a

Browse files
edennisjosevalim
authored andcommitted
Don't call formatter on directories (#12488)
1 parent 2b9d8b7 commit 3d0273a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,9 @@ defmodule Mix.Tasks.Format do
551551
end
552552

553553
defp stdin_or_wildcard("-"), do: [:stdin]
554-
defp stdin_or_wildcard(path), do: path |> Path.expand() |> Path.wildcard(match_dot: true)
554+
555+
defp stdin_or_wildcard(path),
556+
do: path |> Path.expand() |> Path.wildcard(match_dot: true) |> Enum.filter(&File.regular?/1)
555557

556558
defp elixir_format(content, formatter_opts) do
557559
case Code.format_string!(content, formatter_opts) do

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ defmodule Mix.Tasks.FormatTest do
8181
end)
8282
end
8383

84+
test "does not try to format a directory that matches a given pattern", context do
85+
in_tmp(context.test, fn ->
86+
File.mkdir_p!("a.ex")
87+
88+
assert_raise Mix.Error, ~r"Could not find a file to format", fn ->
89+
Mix.Tasks.Format.run(["*.ex"])
90+
end
91+
end)
92+
end
93+
8494
test "reads file from stdin and prints to stdout", context do
8595
in_tmp(context.test, fn ->
8696
File.write!("a.ex", """

0 commit comments

Comments
 (0)