Skip to content

Commit dce4562

Browse files
Sascha Wolfalexocode
authored andcommitted
Mix - Format: Evaluate the formatter options in the config files directory
This change fetches the folder from the provided dot_formatter config file, or it returns nil. Furthermore it adds a `fetch_deps_opts(formatter_opts, in_directory: formatter_dir)` function. This function then uses a non nil `formatter_dir` to wrap the actual `fetch_deps_opts/1` call in a `File.cd!` call for the provided `formatter_dir`. Fixes #7327
1 parent e43d35e commit dce4562

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ defmodule Mix.Tasks.Format do
126126

127127
def run(args) do
128128
{opts, args} = OptionParser.parse!(args, strict: @switches)
129-
formatter_opts = eval_dot_formatter(opts)
130-
formatter_opts = fetch_deps_opts(formatter_opts)
129+
{formatter_dir, formatter_opts} = eval_dot_formatter(opts)
130+
formatter_opts = fetch_deps_opts(formatter_opts, in_directory: formatter_dir)
131131

132132
args
133133
|> expand_args(formatter_opts)
@@ -138,8 +138,8 @@ defmodule Mix.Tasks.Format do
138138

139139
defp eval_dot_formatter(opts) do
140140
case dot_formatter(opts) do
141-
{:ok, dot_formatter} -> eval_file_with_keyword_list(dot_formatter)
142-
:error -> []
141+
{:ok, dot_formatter} -> {Path.dirname(dot_formatter), eval_file_with_keyword_list(dot_formatter)}
142+
:error -> {nil, []}
143143
end
144144
end
145145

@@ -153,6 +153,16 @@ defmodule Mix.Tasks.Format do
153153

154154
# This function reads exported configuration from the imported dependencies and deals with
155155
# caching the result of reading such configuration in a manifest file.
156+
defp fetch_deps_opts(formatter_opts, in_directory: nil) do
157+
fetch_deps_opts(formatter_opts)
158+
end
159+
160+
defp fetch_deps_opts(formatter_opts, in_directory: formatter_dir) do
161+
File.cd!(formatter_dir, fn ->
162+
fetch_deps_opts(formatter_opts)
163+
end)
164+
end
165+
156166
defp fetch_deps_opts(formatter_opts) do
157167
deps = Keyword.get(formatter_opts, :import_deps, [])
158168

0 commit comments

Comments
 (0)