Skip to content

Commit bd275ea

Browse files
author
José Valim
committed
Raise if imported dependencies have not been checked out on mix format
1 parent d027555 commit bd275ea

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,19 @@ defmodule Mix.Tasks.Format do
214214
defp assert_valid_dep_and_fetch_path(dep, deps_paths) when is_atom(dep) do
215215
case Map.fetch(deps_paths, dep) do
216216
{:ok, path} ->
217-
path
217+
if File.dir?(path) do
218+
path
219+
else
220+
Mix.raise(
221+
"Unavailable dependency #{inspect(dep)} given to :import_deps in the formatter configuration. " <>
222+
"The dependency cannot be found in the filesystem, please run mix deps.get and try again"
223+
)
224+
end
218225

219226
:error ->
220227
Mix.raise(
221-
"Found a dependency in :import_deps that the project doesn't depend on: #{inspect(dep)}"
228+
"Unknown dependency #{inspect(dep)} given to :import_deps in the formatter configuration. " <>
229+
"The dependency is not listed in your mix.exs file"
222230
)
223231
end
224232
end

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,12 @@ defmodule Mix.Tasks.FormatTest do
209209
"""
210210

211211
manifest_path = Path.join(Mix.Project.manifest_path(), "cached_formatter_deps")
212-
213212
assert File.regular?(manifest_path)
214213

215214
# Let's check that the manifest gets updated if it's stale.
216215
File.touch!(manifest_path, {{1970, 1, 1}, {0, 0, 0}})
217216

218217
Mix.Tasks.Format.run(["a.ex"])
219-
220218
assert File.stat!(manifest_path).mtime > {{1970, 1, 1}, {0, 0, 0}}
221219
end
222220
end
@@ -225,13 +223,23 @@ defmodule Mix.Tasks.FormatTest do
225223
Mix.Project.push(__MODULE__.FormatWithDepsApp)
226224

227225
in_tmp context.test, fn ->
226+
File.write!(".formatter.exs", """
227+
[import_deps: [:my_dep]]
228+
""")
229+
230+
message =
231+
"Unavailable dependency :my_dep given to :import_deps in the formatter configuration. " <>
232+
"The dependency cannot be found in the filesystem, please run mix deps.get and try again"
233+
234+
assert_raise Mix.Error, message, fn -> Mix.Tasks.Format.run([]) end
235+
228236
File.write!(".formatter.exs", """
229237
[import_deps: [:nonexistent_dep]]
230238
""")
231239

232240
message =
233-
"Found a dependency in :import_deps that the project doesn't " <>
234-
"depend on: :nonexistent_dep"
241+
"Unknown dependency :nonexistent_dep given to :import_deps in the formatter configuration. " <>
242+
"The dependency is not listed in your mix.exs file"
235243

236244
assert_raise Mix.Error, message, fn -> Mix.Tasks.Format.run([]) end
237245
end

0 commit comments

Comments
 (0)