Elixir formatter & macros - every time I create a macro I need to add it to the local_without_parens list

I’ve noticed something in my own code, that every time I create a macro, I need to add it to the local_without_parens list in .formatter.exs.

I’m not alone in this, Phoenix, Ecto, Ash, and probably many others, have this long lists of all the macros they’ve defined.

Wouldn’t it make sense to make this either the default behaviour, or at least have a flag like, macros_parens: false? Is there a technical limitation for doing this?

The formatter does not know if something is a macro or not. To know that, it would need to expand and execute macros, which would make formatting slower.


I’d also argue that setting all macros as without parens would be a bad default. Yes many of them look a lot better without parens, but not all macros are used in different ways to functions. E.g. the macros in explorer are macros because they need to be, but they’re generally not used differently than their function counterparts.


Thanks for the responses! I get it now

1 Like

Worth nothing that because our macros are all statically defined (i.e we don’t actually write the macros, we make structs and something else writes the macros), we actually generate the .formatter.exs with a mix task.

Same for anyone using Spark to build their DSL.

EDIT: we don’t generate it, but we modify it to include the locals_without_parens for any given DSL.

1 Like