Closed
Description
Precheck
- Do not use the issues tracker for help or support (try Elixir Forum, Stack Overflow, IRC, etc.) ✅
- For bugs, do a quick search and make sure the bug has not yet been reported ✅
- Finally, be nice and have fun! ✅
Environment
- Elixir 1.6.1
- Erlang OTP20
- macOS High Sierra (10.13.2)
Current behavior
Running mix format
using --dot-formatter
with a .formatter.exs
in a different folder - containing a import_deps
configuration - results in the following error:
** (File.Error) could not read file "<PATH_TO_CURRENT_FOLDER>/_build/dev/.mix/cached_formatter_deps": no such file or directory
(elixir) lib/file.ex:310: File.read!/1
(mix) lib/mix/tasks/format.ex:193: Mix.Tasks.Format.read_deps_manifest/1
(mix) lib/mix/tasks/format.ex:173: Mix.Tasks.Format.fetch_deps_opts/1
(mix) lib/mix/tasks/format.ex:129: Mix.Tasks.Format.run/1
(mix) lib/mix/task.ex:314: Mix.Task.run_task/3
(mix) lib/mix/cli.ex:80: Mix.CLI.run_task/2
Expected behavior
mix format
should format the file(s) using the configuration from .formatter.exs
and respect :import_deps
.
Research
I've tried to track the cause of the issue and it seems the root cause might be this line:
elixir/lib/mix/lib/mix/tasks/format.ex
Line 166 in ae8502d
It seems that Mix.Project.manifest_path/0
always takes the current folder to expand the path. This is fairly easy to reproduce in iex
.
# Let's assume we're in the root of an umbrella project
iex> Mix.Project.manifest_path
"<path-to-project>/_build/<env>"
iex> cd "apps"
iex> Mix.Project.manifest_path
"<path-to-project>/apps/_build/<env>"
This then results in mix format
trying to read <path-to-project>/apps/_build/<env>/cached_formatter_deps
which obviously can not be found and raises a File.Error
.