popo63301

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

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

popo63301

I have to precise. It’s annoying for 2 particular situations:

Macros like add and field (in Ecto Migrations and Schemas)

cmo

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

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

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.

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

We're in Beta

About us Mission Statement