Skip to content

Commit f5e35da

Browse files
fertapricJosé Valim
authored andcommitted
Match files starting with dot in "mix format" (#7697)
Here is the example `.formatter.exs` file given in the documentation of `mix format`: [ inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] ] With the previous implementation, the `.formatter.exs` file would not be formatted because internally `Path.wildcard/2` was used without expanding files starting with dot ".": iex> Path.wildcard("{mix,.formatter}.exs") ["mix.exs"] iex> Path.wildcard("{mix,.formatter}.exs", match_dot: true) [".formatter.exs", "mix.exs"] Signed-off-by: José Valim <[email protected]>
1 parent 3d72978 commit f5e35da

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ defmodule Mix.Tasks.Format do
352352

353353
map =
354354
for input <- List.wrap(formatter_opts[:inputs]),
355-
file <- Path.wildcard(Path.join(prefix ++ [input])),
355+
file <- Path.wildcard(Path.join(prefix ++ [input]), match_dot: true),
356356
do: {file, formatter_opts},
357357
into: %{}
358358

@@ -375,7 +375,7 @@ defmodule Mix.Tasks.Format do
375375
end
376376

377377
defp stdin_or_wildcard("-"), do: [:stdin]
378-
defp stdin_or_wildcard(path), do: Path.wildcard(path)
378+
defp stdin_or_wildcard(path), do: Path.wildcard(path, match_dot: true)
379379

380380
defp read_file(:stdin) do
381381
{IO.stream(:stdio, :line) |> Enum.to_list() |> IO.iodata_to_binary(), file: "stdin"}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,34 @@ defmodule Mix.Tasks.FormatTest do
180180
end)
181181
end
182182

183+
test "expands patterns in inputs from .formatter.exs", context do
184+
in_tmp(context.test, fn ->
185+
File.write!(".formatter.exs", """
186+
[
187+
inputs: ["{a,.b}.ex"]
188+
]
189+
""")
190+
191+
File.write!("a.ex", """
192+
foo bar
193+
""")
194+
195+
File.write!(".b.ex", """
196+
foo bar
197+
""")
198+
199+
Mix.Tasks.Format.run([])
200+
201+
assert File.read!("a.ex") == """
202+
foo(bar)
203+
"""
204+
205+
assert File.read!(".b.ex") == """
206+
foo(bar)
207+
"""
208+
end)
209+
end
210+
183211
test "uses inputs and configuration from --dot-formatter", context do
184212
in_tmp(context.test, fn ->
185213
File.write!("custom_formatter.exs", """

0 commit comments

Comments
 (0)