elixir-lang / elixir

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

Minor regression on code formatter adding new lines between @moduledoc and comments #9873

Closed fertapric closed 4 years ago

fertapric commented 4 years ago

Environment

Elixir 1.10.1 (compiled with Erlang/OTP 22)


* Operating system:  macOS 10.15.3

### Current behavior

Elixir v1.10 shipped with a minor regression in the code formatter. On Elixir v1.9 or earlier (tried with v1.9.4 and v1.8.2) this code would be left as is:

```elixir
defmodule Sample do
  @moduledoc false
  # Here goes the module doc for the private module Sample

  def sample, do: :sample
end

However, running mix format in Elixir v1.10 changes the code above to:

defmodule Sample do
  @moduledoc false

  # Here goes the module doc for the private module Sample

  def sample, do: :sample
end

In addition, this code is unchanged in all versions (including v1.10):

defmodule Sample do
  @moduledoc false
  # Here goes the module doc for the private module Sample
end

Expected behavior

I would expect mix format to not add a new line between @moduledoc false and the comment.

fertapric commented 4 years ago

To give more context, this remains unchanged in all versions (including v1.10):

defmodule Sample do
  @moduledoc false
  # Comment 1

  # Comment 2
  @attr1 1
  # Comment 3

  # Comment 4
  @doc "Doc"
  # Comment 5
  @attr2 2
  # Comment 6
  def sample, do: :sample
end

However, this code remains unchanged in prior version of v1.10:

defmodule Sample do
  @moduledoc false
  # Comment 1

  @attr1 1
  # Comment 3

  @doc "Doc"
  @attr2 2
  # Comment 6
  def sample, do: :sample
end

But in v1.10:

defmodule Sample do
  @moduledoc false

  # Comment 1

  @attr1 1

  # Comment 3

  @doc "Doc"
  @attr2 2
  # Comment 6
  def sample, do: :sample
end