Skip to content

Commit 755639f

Browse files
author
José Valim
committed
Consider .formatter.exs when formatting stdin
Closes #7411 Signed-off-by: José Valim <[email protected]>
1 parent 97e0b1e commit 755639f

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ defmodule Mix.Tasks.Format do
308308
|> Enum.uniq()
309309
end
310310

311-
defp expand_args(files_and_patterns, _dot_formatter, formatter_opts_and_subs) do
311+
defp expand_args(files_and_patterns, _dot_formatter, {formatter_opts, subs}) do
312312
files =
313313
for file_or_pattern <- files_and_patterns,
314314
file <- stdin_or_wildcard(file_or_pattern),
@@ -324,10 +324,10 @@ defmodule Mix.Tasks.Format do
324324

325325
for file <- files do
326326
if file == :stdin do
327-
{file, []}
327+
{file, formatter_opts}
328328
else
329329
split = file |> Path.relative_to_cwd() |> Path.split()
330-
{file, find_formatter_opts_for_file(split, formatter_opts_and_subs)}
330+
{file, find_formatter_opts_for_file(split, {formatter_opts, subs})}
331331
end
332332
end
333333
end

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ defmodule Mix.Tasks.FormatTest do
9090
end)
9191
end
9292

93+
test "reads file from stdin and prints to stdout with formatter", context do
94+
in_tmp(context.test, fn ->
95+
File.write!(".formatter.exs", """
96+
[locals_without_parens: [foo: 1]]
97+
""")
98+
99+
output =
100+
capture_io("foo :bar", fn ->
101+
Mix.Tasks.Format.run(["-"])
102+
end)
103+
104+
assert output == """
105+
foo :bar
106+
"""
107+
end)
108+
end
109+
93110
test "checks if file is formatted with --check-formatted", context do
94111
in_tmp(context.test, fn ->
95112
File.write!("a.ex", """

0 commit comments

Comments
 (0)