clmay

clmay

Function parentheses and `mix format`

Hi there,

I’m currently following an Elixir tutorial and I have the following lines of code in my project:

Path.join([path, file])
    |> File.read!
    |> split
    |> process(post)

When I run mix format, it gets turned into this:

Path.join([path, file])
    |> File.read!()
    |> split
    |> process(post)

I know this is a minor gripe, but I find it annoying/ugly that (optional) parentheses are added to File.read!/1 but not split/1

How can I configure mix format not to add (optional) parentheses to functions with no/implicit arguments?

I am aware of the .formatter.exs options import_deps: [...] and locals_without_parens: [...] but could not figure out how to add File.read! to these in a way that mix format would accept.

Any ideas?

Most Liked

NobbZ

NobbZ

You can not configure the treatment of File.read!/1, as it is not a “local”. :locals_without_parens will only ever work for unqualified calls, those you write without a module in fron tof them.

And parenthesis aren’t really optional, they are considered best practice by the community and most of us actually agree on the formatter in the regard of adding them unconditionally. I’d even consider it a bug, that none are added to split/1.

The main reason why parens have been made optional for the compiler, is probably to make things like def and defmodule writable without having to wrap parenthesis to their arguments.

marcandre

marcandre

For those interested, the latest formatter plugin freedom_formatter now has the option to add parenthesis for these calls.

foo |> bar |> baz
# becomes, if `local_pipe_with_parens` option set to `true`:
foo |> bar() |> baz()

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
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
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
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
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement