elixir-lang / elixir

Elixir is a dynamic, functional language for building scalable and maintainable applications
https://elixir-lang.org/
Apache License 2.0
24.31k stars 3.35k forks source link

Formatter doesn't insert new line after constant definition #8960

Closed rhnonose closed 5 years ago

rhnonose commented 5 years ago

Environment

Current behavior

Formatting of a file doesn't include blank lines between a constant and a function definition. A reproducible snippet:

defmodule MyModule do
  @const [
    :test1,
    :test1
  ]
  def my_function do
    :do_nothing
  end
end

The formatter doesn't insert a blank line between ] and def my_function do. If there's a blank line, the formatter keeps it.

Expected behavior

The formatter should insert a blank line between ] and def my_function do.

josevalim commented 5 years ago

It is on purpose becomes sometimes you want the attribute stay close to the function, such as @spec, @doc, etc. We also don't want to hardcode special module attributes (as you can always define your own), so we have to respect the user choice. For example, this would be completely valid:

  @decorate [Foo, Bar]
  def foo(...)

And if we put them apart users would be angry at us. :)