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])
    |> split
    |> process(post)

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

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

I know this is a minor gripe, but I find it annoying/ugly that (optional) parentheses are added to!/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! to these in a way that mix format would accept.

Any ideas?

1 Like

You can not configure the treatment of!/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.


This is fine – conversely then, how can I make mix format respect best practices and add parentheses to the call to split/1?