diff options
author | Andrea Leopardi <an.leopardi@gmail.com> | 2017-12-13 13:04:25 +0100 |
---|---|---|
committer | Andrea Leopardi <an.leopardi@gmail.com> | 2017-12-13 13:06:08 +0100 |
commit | 619d58c272476df04ebdb82df98812bf36ab6864 (patch) | |
tree | 83eabe57b496dc807b7d328f617cd1f47c2d240c | |
parent | 982c2e082fe4bffc94a14258234e56ead7d8906f (diff) | |
download | elixir-619d58c272476df04ebdb82df98812bf36ab6864.tar.gz |
Implement José's feedback
-rw-r--r-- | lib/mix/lib/mix/tasks/format.ex | 21 | ||||
-rw-r--r-- | lib/mix/test/mix/tasks/format_test.exs | 8 |
2 files changed, 14 insertions, 15 deletions
diff --git a/lib/mix/lib/mix/tasks/format.ex b/lib/mix/lib/mix/tasks/format.ex index 64e918001..036f2bfb6 100644 --- a/lib/mix/lib/mix/tasks/format.ex +++ b/lib/mix/lib/mix/tasks/format.ex @@ -196,8 +196,8 @@ defmodule Mix.Tasks.Format do deps_paths = Mix.Project.deps_paths() for dep <- deps, - ensure_valid_dependency!(dep, deps_paths), - dep_dot_formatter = Path.join(Map.fetch!(deps_paths, dep), ".formatter.exs"), + dep_path = assert_valid_dep_and_fetch_path(dep, deps_paths), + dep_dot_formatter = Path.join(dep_path, ".formatter.exs"), File.regular?(dep_dot_formatter), dep_opts = eval_file_with_keyword_list(dep_dot_formatter), parenless_call <- dep_opts[:export][:locals_without_parens] || [], @@ -205,21 +205,22 @@ defmodule Mix.Tasks.Format do do: parenless_call end - defp ensure_valid_dependency!(dep, deps_paths) do - cond do - not is_atom(dep) -> - Mix.raise("Dependencies in :import_deps should be atoms, got: #{inspect(dep)}") + defp assert_valid_dep_and_fetch_path(dep, deps_paths) when is_atom(dep) do + case Map.fetch(deps_paths, dep) do + {:ok, path} -> + path - not Map.has_key?(deps_paths, dep) -> + :error -> Mix.raise( "Found a dependency in :import_deps that the project doesn't depend on: #{inspect(dep)}" ) - - true -> - :ok end end + defp assert_valid_dep_and_fetch_path(dep, _deps_paths) do + Mix.raise("Dependencies in :import_deps should be atoms, got: #{inspect(dep)}") + end + defp eval_file_with_keyword_list(path) do {opts, _} = Code.eval_file(path) diff --git a/lib/mix/test/mix/tasks/format_test.exs b/lib/mix/test/mix/tasks/format_test.exs index c4d91c80e..46aabcbfe 100644 --- a/lib/mix/test/mix/tasks/format_test.exs +++ b/lib/mix/test/mix/tasks/format_test.exs @@ -209,17 +209,15 @@ defmodule Mix.Tasks.FormatTest do """ manifest_path = Path.join(Mix.Project.manifest_path(), ".cached_deps_formatter") + assert File.regular?(manifest_path) - # Let's check that the manifest gets updated if .formatter.exs changes. + # Let's check that the manifest gets updated if it's stale. File.touch!(manifest_path, {{1970, 1, 1}, {0, 0, 0}}) - %File.Stat{mtime: mtime} = File.stat!(manifest_path) - File.touch!(".formatter.exs") Mix.Tasks.Format.run(["a.ex"]) - %File.Stat{mtime: new_mtime} = File.stat!(manifest_path) - assert new_mtime > mtime + assert File.stat!(manifest_path).mtime > {{1970, 1, 1}, {0, 0, 0}} end end |