Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/mix/lib/mix/tasks/format.ex
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,9 @@ defmodule Mix.Tasks.Format do
end

defp stdin_or_wildcard("-"), do: [:stdin]
defp stdin_or_wildcard(path), do: path |> Path.expand() |> Path.wildcard(match_dot: true)

defp stdin_or_wildcard(path),
do: path |> Path.expand() |> Path.wildcard(match_dot: true) |> Enum.filter(&File.regular?/1)

defp elixir_format(content, formatter_opts) do
case Code.format_string!(content, formatter_opts) do
Expand Down
10 changes: 10 additions & 0 deletions lib/mix/test/mix/tasks/format_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ defmodule Mix.Tasks.FormatTest do
end)
end

test "does not try to format a directory that matches a given pattern", context do
in_tmp(context.test, fn ->
File.mkdir_p!("a.ex")

assert_raise Mix.Error, ~r"Could not find a file to format", fn ->
Mix.Tasks.Format.run(["*.ex"])
end
end)
end

test "reads file from stdin and prints to stdout", context do
in_tmp(context.test, fn ->
File.write!("a.ex", """
Expand Down