popo63301
VSCode Elixir Format - Prevent auto parentheses
Hello !
I would like to prevent automatic parentheses while coding in Elixir in VSCode.
I can’t see where to configure that.
Any suggestions ?
Most Liked
cmo
The elixir formatter doesn’t have much in the way of options. The idea is that you accept how it is and move on with your life, free from worrying about formatting.
There are libraries, ecto, phoenix etc, that tell it not to add them to some macros, which you need to add to formatter.exs.
If you’re just talking about it creating the second bracket, look in the VS Code settings.
popo63301
I have to precise. It’s annoying for 2 particular situations:
Macros like add and field (in Ecto Migrations and Schemas)
cmo
Have you got the inpit_deps set in .formatter.exs? The ecto setting should stop that. However, as someone pointed out, it will randomly screw it up every now and then. You have git to save you in those instances.
[
import_deps: [:ecto, :phoenix, :surface, :nimble_parsec],
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs,sface}"],
subdirectories: ["priv/*/migrations"],
...
greven
This is a bug with ElixirLS and it’s a trick one, it has to do with race conditions.
It’s being tracked here: Formatter doesn't respect formatter.exs while your code is still compiling · Issue #526 · elixir-lsp/elixir-ls · GitHub
adamu
The good news is, that’s one of the few customisable options.
The bad news is, you have to specify every function name and arity where you don’t want it to automatically add the parenthesis.
Check out the mix format and Code.format_format_string/2 docs. You’re looking for :locals_without_parens.
See Plug for an example.







