Repository: hrzndhrn/recode (elixir)
Issue: Failing on __MODULE__ aliases with `as`
Hi! Thank you for this tool. I am trying to test it but it fails for me for __MODULE__ aliases 

```elixir
alias __MODULE__, as: SummaryForm
```

It fails with: 

```
** (FunctionClauseError) no function clause matching in Recode.AST.alias_info/1    
    
    The following arguments were given to Recode.AST.alias_info/1:
    
        # 1
        {:alias, [trailing_comments: [], leading_comments: [], end_of_expression: [newlines: 1, line: 6, column: 36], line: 6, column: 3], [{:__MODULE__, [trailing_comments: [], leading_comments: [], line: 6, column: 9], nil}, [{{:__block__, [trailing_comments: [], leading_comments: [], format: :keyword, line: 6, column: 21], [:as]}, {:__aliases__, [trailing_comments: [], leading_comments: [], last: [line: 6, column: 25], line: 6, column: 25], [:SummaryForm]}}]]}
    
    Attempted function clauses (showing 8 out of 8):
    
        def alias_info({:alias, _meta1, [{:__aliases__, _meta2, aliases}]})
        def alias_info({:alias, _meta1, [{:__MODULE__, _meta2, nil}]})
        def alias_info({:alias, _meta1, [{{:., _meta2, [{:__MODULE__, _meta3, _args}, _opts]}, _meta4, multi}]})
        def alias_info({:alias, _meta1, [{{:., _meta2, [aliases, _opts]}, _meta3, multi}]})
        def alias_info({:alias, _meta1, [{:__aliases__, _meta2, aliases}, [{_block, as}]]})
        def alias_info({:alias, _meta1, [{:__block__, _meta2, aliases}, [{_block, as}]]})
        def alias_info({:alias, _meta1, [{:unquote, _meta2, _args}]})
        def alias_info({:alias, _meta1, [{:unquote, _meta2, _args}, [{_block, as}]]})
```
Pull request description: Fix alias info
closes #83 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c1154ba..b8f786d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,8 +1,8 @@
 # Changelog
 
-## 0.7.2 - dev
+## 0.7.2 - 2024/02/10
 
-+ Add `Recode.Task.Moduledoc`
++ Fix AST.alias_info fot `alias __MODULE__, as: MyModule`.
 
 ## 0.7.1 - 2024/01/09
 
diff --git a/lib/recode/ast.ex b/lib/recode/ast.ex
index 13e8ba2..3ea3b67 100644
--- a/lib/recode/ast.ex
+++ b/lib/recode/ast.ex
@@ -441,6 +441,18 @@ defmodule Recode.AST do
       ...> end
       iex> alias_info(ast)
       {Foo, [], Baz}
+
+      iex> ast = Sourceror.parse_string!("alias __MODULE__")
+      iex> alias_info(ast)
+      {:__MODULE__, [], nil}
+
+      iex> ast = Sourceror.parse_string!("alias __MODULE__.{Foo, Bar.Baz}")
+      iex> alias_info(ast)
+      {:__MODULE__, [Foo, Bar.Baz], nil}
+
+      iex> ast = Sourceror.parse_string!("alias __MODULE__, as: MyModule")
+      iex> alias_info(ast)
+      {:__MODULE__, [], MyModule}
   """
   @spec alias_info(Macro.t()) :: {module(), [module()], module() | nil}
   def alias_info({:alias, _meta1, [{:__aliases__, _meta2, aliases}]}) do
@@ -466,6 +478,11 @@ defmodule Recode.AST do
     {:__MODULE__, multi, nil}
   end
 
+  def alias_info({:alias, _meta1, [{:__MODULE__, _meta2, _args}, [{_block, as}]]}) do
+    as = aliases_concat(as)
+    {:__MODULE__, [], as}
+  end
+
   def alias_info({:alias, _meta1, [{{:., _meta2, [aliases, _opts]}, _meta3, multi}]}) do
     module = aliases_concat(aliases)
     multi = Enum.map(multi, &aliases_concat/1)


Test patch:
diff --git a/test/recode/task/alias_order_test.exs b/test/recode/task/alias_order_test.exs
index c34b142..55630fb 100644
--- a/test/recode/task/alias_order_test.exs
+++ b/test/recode/task/alias_order_test.exs
@@ -79,6 +79,28 @@ defmodule Recode.Task.AliasOrderTest do
     |> assert_code(expected)
   end
 
+  test "sorts modules with :as" do
+    code = """
+    defmodule MyModule do
+      alias Beta, as: Delta
+      alias __MODULE__, as: Charlie
+      alias Alpha, as: Gamma
+    end
+    """
+
+    expected = """
+    defmodule MyModule do
+      alias Alpha, as: Gamma
+      alias Beta, as: Delta
+      alias __MODULE__, as: Charlie
+    end
+    """
+
+    code
+    |> run_task(AliasOrder, autocorrect: true)
+    |> assert_code(expected)
+  end
+
   test "sorts erlang modules" do
     code = """
     defmodule MyModule do