The formatter cannot change the AST, as that changes the semantics of the
code. Doing this change would change the AST and consequently the code
semantics.

Imagine someones does this:

use SomethingThatReplacesKernelDefbyMyOwnDef


def foo, ...


Can we say that for this new "def", we can add parens to "foo()"? We
cannot. Since the formatter doesn't execute code, it is not even sure to
whom the "def" definition belongs.



*José Valimwww.plataformatec.com.br
<http://www.plataformatec.com.br/>Founder and Director of R&D*

2018-01-23 14:10 GMT+01:00 Fernando Tapia Rico <fertap...@gmail.com>:

> Hi,
>
> The formatter currently accepts definitions of functions with no arguments
> (arity 0) with or without parens. This means that these two expressions are
> valid (format-wise) within the same codebase:
>
> def main do
> end
>
> def main() do
> end
>
>
> To show real-life examples, I made a list of some functions in the Elixir
> codebase defined with or without parens:
>
>
> *Without parens:*
>
>
>    - Kernel.node/0 - https://github.com/elixir-
>    lang/elixir/blob/master/lib/elixir/lib/kernel.ex#L711
>    
> <https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/kernel.ex#L711>
>    - Regex.version/0 - https://github.com/elixir-
>    lang/elixir/blob/master/lib/elixir/lib/regex.ex#L215
>    
> <https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/regex.ex#L215>
>    - Keyword.new/0 - https://github.com/elixir-
>    lang/elixir/blob/master/lib/elixir/lib/keyword.ex#L111
>    
> <https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/keyword.ex#L111>
>    - Map.new/0 - https://github.com/elixir-lang/elixir/blob/master/lib/
>    elixir/lib/map.ex#L150
>    - IO.ANSI.enabled?/0 - https://github.com/elixir-
>    lang/elixir/blob/master/lib/elixir/lib/io/ansi.ex#L42
>    
> <https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/io/ansi.ex#L42>
>    - Port.list/0 - https://github.com/elixir-lang/elixir/blob/master/lib/
>    elixir/lib/port.ex#L294
>    - System.argv/0 - https://github.com/elixir-
>    lang/elixir/blob/master/lib/elixir/lib/system.ex#L200
>    
> <https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/system.ex#L200>
>    - System.cwd/0 - https://github.com/elixir-lang/elixir/blob/master/lib/
>    elixir/lib/system.ex#L221
>    - System.cwd!/0 - https://github.com/elixir-
>    lang/elixir/blob/master/lib/elixir/lib/system.ex#L242
>    
> <https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/system.ex#L242>
>    - All the /0 of System
>
>
> *With parens:*
>
>
>    - Kernel.make_ref/0 - https://github.com/elixir-
>    lang/elixir/blob/master/lib/elixir/lib/kernel.ex#L618
>    
> <https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/kernel.ex#L618>
>    - Kernel.self/0 - https://github.com/elixir-
>    lang/elixir/blob/master/lib/elixir/lib/kernel.ex#L803
>    
> <https://github.com/elixir-lang/elixir/blob/master/lib/elixir/lib/kernel.ex#L803>
>    - Access.all/0 - https://github.com/elixir-lang/elixir/blob/master/lib/
>    elixir/lib/access.ex#L613
>    - MapSet.new/0 - https://github.com/elixir-lang/elixir/blob/master/lib/
>    elixir/lib/map_set.ex#L57
>    - File.cwd/0 - https://github.com/elixir-lang/elixir/blob/master/lib/
>    elixir/lib/file.ex#L1353
>    - File.cwd!/0 - https://github.com/elixir-lang/elixir/blob/master/lib/
>    elixir/lib/file.ex#L1373
>
>
> Is this flexibility in the style intended? I'm probably nitpicking, but it
> would be nice if one style is enforced. The same applies for function
> specifications.
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elixir-lang-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/elixir-lang-core/665af8fd-45b0-411b-acb4-
> 4ea03732f4f4%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/665af8fd-45b0-411b-acb4-4ea03732f4f4%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4J-ThFKaaWfy2PN1KjyjkjydDbNqy0ER%2BXeFFMTx3DNjw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to