tadasajon
How can I force `mix format` to enforce the use of parentheses wherever they are possible?
My partner and I are working on a codebase together and we have something different in our setup that is causing his system to add parens while mine does not. We are both using the same .formatter.exs file, which looks like this:
[
import_deps: [:ecto, :phoenix],
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
subdirectories: ["priv/*/migrations"]
]
Our working theory is that we have something different configured in our VSCode plugins. In any case, I’d like us to get our systems on the exact same page in regard to formatting, so I’d just like to enforce the use of parentheses everywhere. How can I do this using mix format?
I’ve read the docs here – mix format: parens and no parens in function calls – but it is still not clear to me how I can force the use of parentheses everywhere possible.
Most Liked
hauleth
That would result in quite weird looking code:
defmodule(Foo) do
def(foo(arg)) do
case(arg) do
:ok -> {:ok, bar()}
_ -> :error
end
end
def(bar(), do: 10)
end
moogle19
I know that ecto and phoenix export their locals_without_parens and therefore no parens are added to function like from/2 or the ecto schema stuff (take a look at Ecto and Phoenix to see all functions / macros).
Not sure why your partners mix format adds them, if he uses the same config with [:ecto, :phoenix] as imports.
Edit: Which plugins do you use for formatting in VSCode? Just ElixirLS?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









