Skip to content

Commit

Permalink
Delete root level alias
Browse files Browse the repository at this point in the history
  • Loading branch information
mgieger committed Dec 1, 2023
1 parent 38695b4 commit 40fc991
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/style/single_node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ defmodule Styler.Style.SingleNode do
alias Styler.Style
alias Styler.Zipper

# Delete root level alias
# `alias Foo` -> ``
def run({{:alias, _, [{:__aliases__, _, [_]}]}, _} = zipper, ctx), do: {:cont, Zipper.remove(zipper), ctx}

def run({node, meta}, ctx), do: {:cont, {style(node), meta}, ctx}

# Our use of the `literal_encoder` option of `Code.string_to_quoted_with_comments!/2` creates
Expand Down
16 changes: 16 additions & 0 deletions test/style/single_node_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,20 @@ defmodule Styler.Style.SingleNodeTest do
assert_style("Enum.reverse(foo, bar) ++ bar")
end
end

test "Delete root level alias" do
assert_style(
"""
alias unquote(Foo)
alias Foo
alias Bar, as: Bop
alias __MODULE__
""",
"""
alias __MODULE__
alias Bar, as: Bop
alias unquote(Foo)
"""
)
end
end

0 comments on commit 40fc991

Please sign in to comment.