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—mainly 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.
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:The formatter will replace the spaces with parentheses:
Expected behavior
While I understand there may be reasoning for this design, it initially strikes me as a bit unexpected—mainly 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:
Can the default behavior of
Code.format_string!/2
be changed to allow single-linedefmodule/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.