Skip to content

Commit bd63670

Browse files
committed
Do not cache inputs from .formatter.exs
1 parent b78b480 commit bd63670

File tree

2 files changed

+61
-27
lines changed

2 files changed

+61
-27
lines changed

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

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ defmodule Mix.Tasks.Format do
176176
]
177177

178178
@manifest "cached_dot_formatter"
179-
@manifest_vsn 1
179+
@manifest_vsn 2
180180

181181
@doc """
182182
Returns which features this plugin should plug into.
@@ -304,10 +304,21 @@ defmodule Mix.Tasks.Format do
304304
else
305305
manifest = Path.join(Mix.Project.manifest_path(), @manifest)
306306

307-
maybe_cache_in_manifest(dot_formatter, manifest, fn ->
308-
{subdirectories, sources} = eval_subs_opts(subs, prefix, sources)
309-
{{eval_deps_opts(formatter_opts, deps), subdirectories}, sources}
310-
end)
307+
{{locals_without_parens, subdirectories}, sources} =
308+
maybe_cache_in_manifest(dot_formatter, manifest, fn ->
309+
{subdirectories, sources} = eval_subs_opts(subs, prefix, sources)
310+
{{eval_deps_opts(deps), subdirectories}, sources}
311+
end)
312+
313+
formatter_opts =
314+
Keyword.update(
315+
formatter_opts,
316+
:locals_without_parens,
317+
locals_without_parens,
318+
&(locals_without_parens ++ &1)
319+
)
320+
321+
{{formatter_opts, subdirectories}, sources}
311322
end
312323
end
313324

@@ -342,29 +353,21 @@ defmodule Mix.Tasks.Format do
342353
{entry, sources}
343354
end
344355

345-
defp eval_deps_opts(formatter_opts, []) do
346-
formatter_opts
356+
defp eval_deps_opts([]) do
357+
[]
347358
end
348359

349-
defp eval_deps_opts(formatter_opts, deps) do
360+
defp eval_deps_opts(deps) do
350361
deps_paths = Mix.Project.deps_paths()
351362

352-
parenless_calls =
353-
for dep <- deps,
354-
dep_path = assert_valid_dep_and_fetch_path(dep, deps_paths),
355-
dep_dot_formatter = Path.join(dep_path, ".formatter.exs"),
356-
File.regular?(dep_dot_formatter),
357-
dep_opts = eval_file_with_keyword_list(dep_dot_formatter),
358-
parenless_call <- dep_opts[:export][:locals_without_parens] || [],
359-
uniq: true,
360-
do: parenless_call
361-
362-
Keyword.update(
363-
formatter_opts,
364-
:locals_without_parens,
365-
parenless_calls,
366-
&(&1 ++ parenless_calls)
367-
)
363+
for dep <- deps,
364+
dep_path = assert_valid_dep_and_fetch_path(dep, deps_paths),
365+
dep_dot_formatter = Path.join(dep_path, ".formatter.exs"),
366+
File.regular?(dep_dot_formatter),
367+
dep_opts = eval_file_with_keyword_list(dep_dot_formatter),
368+
parenless_call <- dep_opts[:export][:locals_without_parens] || [],
369+
uniq: true,
370+
do: parenless_call
368371
end
369372

370373
defp eval_subs_opts(subs, prefix, sources) do

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,37 @@ defmodule Mix.Tasks.FormatTest do
178178
end)
179179
end
180180

181+
test "does not cache inputs from .formatter.exs", context do
182+
in_tmp(context.test, fn ->
183+
File.write!(".formatter.exs", """
184+
[
185+
inputs: Path.wildcard("{a,b}.ex"),
186+
locals_without_parens: [foo: 1]
187+
]
188+
""")
189+
190+
File.write!("a.ex", """
191+
foo bar baz
192+
""")
193+
194+
Mix.Tasks.Format.run([])
195+
196+
assert File.read!("a.ex") == """
197+
foo bar(baz)
198+
"""
199+
200+
File.write!("b.ex", """
201+
bar baz bat
202+
""")
203+
204+
Mix.Tasks.Format.run([])
205+
206+
assert File.read!("b.ex") == """
207+
bar(baz(bat))
208+
"""
209+
end)
210+
end
211+
181212
test "expands patterns in inputs from .formatter.exs", context do
182213
in_tmp(context.test, fn ->
183214
File.write!(".formatter.exs", """
@@ -343,7 +374,7 @@ defmodule Mix.Tasks.FormatTest do
343374
end)
344375
end
345376

346-
test "can read exported configuration from subdirectories", context do
377+
test "reads exported configuration from subdirectories", context do
347378
in_tmp(context.test, fn ->
348379
File.write!(".formatter.exs", """
349380
[subdirectories: ["lib"]]
@@ -396,7 +427,7 @@ defmodule Mix.Tasks.FormatTest do
396427
end)
397428
end
398429

399-
test "can read exported configuration from dependencies", context do
430+
test "reads exported configuration from dependencies", context do
400431
in_tmp(context.test, fn ->
401432
Mix.Project.push(__MODULE__.FormatWithDepsApp)
402433

@@ -434,7 +465,7 @@ defmodule Mix.Tasks.FormatTest do
434465
end)
435466
end
436467

437-
test "can read exported configuration from dependencies and subdirectories", context do
468+
test "reads exported configuration from dependencies and subdirectories", context do
438469
in_tmp(context.test, fn ->
439470
Mix.Project.push(__MODULE__.FormatWithDepsApp)
440471

0 commit comments

Comments
 (0)