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

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
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
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
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
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
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New

Other popular topics Top

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
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
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
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
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
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement