Got annoyed and decided to pursue. I really want parentheses in my ecto
and ecto_sql
code.
TL;DR: I had this file in my project: priv/repo/migrations/.formatter.exs
. I also have the .formatter.exs
in the root of the project. I removed the first file and removed :ecto
and :ecto_sql
from import_deps
in my root .formatter.exs
file, then did rm -rf _build && mix do deps.get, compile
and et voila, both mix format
and ElixirLS started adding parentheses in my migrations code.
Long version:
priv/repo/migrations/.formatter.exs
had these contents:
[
import_deps: [:ecto_sql],
inputs: ["*.exs"]
]
.formatter.exs
(at the root of the project) had these contents:
[
import_deps: [:ecto, :ecto_sql, :phoenix],
subdirectories: ["priv/*/migrations"],
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/**/*.exs"]
]
When I tried desperately to manually mix format
my migrations to put parentheses in (I dislike the space syntax and prefer the parentheses
), I got this error (I have replaced the absolute path on my storage with $STORAGE_PATH):
Both .formatter.exs and $PROJECT_PATH/priv/repo/migrations/.formatter.exs specify the file $PROJECT/priv/repo/migrations/20240229041210_add_oban_jobs_table.exs in their :inputs option. To resolve the conflict, the configuration in .formatter.exs will be ignored. Please change the list of :inputs in one of the formatter files so only one of them matches $PROJECT_PATH/priv/repo/migrations/20240229041210_add_oban_jobs_table.exs
So I:
- Removed
priv/repo/migrations/.formatter.exs
;
- Edited the root
.formatter.exs
file like so (removed ecto
and ecto_sql
from import_deps
):
[
- import_deps: [:ecto, :ecto_sql, :phoenix],
+ import_deps: [:phoenix],
subdirectories: ["priv/*/migrations"],
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/**/*.exs"]
]
- Removed the
_build
directory (rm -rf _build
) and then ran mix do deps.get, compile
. Note that without this step formatting still didn’t work like I wanted it to.
mix format
worked immediately after – as in, it added parentheses where there were none.
ElixirLS worked immediately after as well.
Mystery solved. No idea what possessed me to make this secondary .formatter.exs
file inside the priv/repo/migrations/
directory.