Elixir: Do not enforce parentheses in `Code.format_string!/2` on single-line `defmodule/2` calls

Created on 1 May 2019  路  2Comments  路  Source: elixir-lang/elixir

Environment

Erlang/OTP 21 [erts-10.0.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]
Elixir 1.8.1 (compiled with Erlang/OTP 20)

macOS Mojave 10.14.1

Current behavior

With the default setup, the code formatter will enforce parentheses on single-line module definitions with the defmodule/2 macro.

Say you have a module that simply calls use on another module to inject some code:

defmodule MyModule, do: use MyOtherModule

The formatter will replace the spaces with parentheses:

defmodule(MyModule, do: use(MyOtherModule))

Expected behavior

While I understand there may be reasoning for this design, it initially strikes me as a bit unexpected鈥攎ainly because the formatter doesn't enforce parentheses use for single-line calls to other Kernel marcos. For example, the very common single-line function definition:

def my_function(), do: :ok 

Can the default behavior of Code.format_string!/2 be changed to allow single-line defmodule/2 calls that omit parentheses?

I think this may be as simple as adding defmodule: 2 to the locals_without_parens list in Code.Formatter, but I may be wrong.

Most helpful comment

@josevalim great, will do!

All 2 comments

Yes, it is as simple as adding defmodule/2! Please send a PR!

Jos茅 Valim
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D

@josevalim great, will do!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Paddy3118 picture Paddy3118  路  3Comments

josevalim picture josevalim  路  3Comments

GianFF picture GianFF  路  3Comments

coryodaniel picture coryodaniel  路  3Comments

ckampfe picture ckampfe  路  3Comments