From 26127bc51a56fe999f491699a0206a6f6bc2f93b Mon Sep 17 00:00:00 2001 From: Matt Enlow Date: Thu, 22 Jun 2023 15:19:32 -0600 Subject: [PATCH] add a test --- lib/style/module_directives.ex | 1 + test/style/module_directives_test.exs | 32 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/style/module_directives.ex b/lib/style/module_directives.ex index c6fd911c..c1132705 100644 --- a/lib/style/module_directives.ex +++ b/lib/style/module_directives.ex @@ -228,6 +228,7 @@ defmodule Styler.Style.ModuleDirectives do end defp fix_line_numbers([last], acc), do: Enum.reverse([last | acc]) + defp fix_line_numbers([], []), do: [] defp expand_and_sort(directives) do diff --git a/test/style/module_directives_test.exs b/test/style/module_directives_test.exs index b2188e88..7abc206e 100644 --- a/test/style/module_directives_test.exs +++ b/test/style/module_directives_test.exs @@ -349,4 +349,36 @@ defmodule Styler.Style.ModuleDirectivesTest do """) end end + + describe "with comments..." do + test "moving aliases up through non-directives doesn't move comments up" do + assert_style( + """ + defmodule Foo do + alias B + # hi + # this is foo + def foo do + # i promise it's ok! + :ok + end + alias A + end + """, + """ + defmodule Foo do + @moduledoc false + alias A + alias B + # hi + # this is foo + def foo do + # i promise it's ok! + :ok + end + end + """ + ) + end + end end