KogenCredo.CoreSupport.Aliases (KogenCredo v0.1.0)
View SourceFile-level alias resolution.
build/1 collects every alias in a file (including as: and multi-alias
forms), ignoring lexical scope: an alias declared in one function is treated as
visible in the whole file. Checks that need real scoping (an alias declared in one
function or module must not leak into another) use
KogenCredo.CoreSupport.Scope.walk/3, which hands each node the aliases map in
force there; resolve/2 works with either.
Summary
Functions
Collects alias declarations of a file as a map from short name to module name.
Locally defined function names with arities, used to avoid mistaking local functions for imports.
Resolves a module node using the file aliases.
Types
@type t() :: %{required(atom()) => KogenCredo.CoreSupport.Ast.module_name()}
Short alias name => module name; :__MODULE__ carries the enclosing module's name.
Functions
Collects alias declarations of a file as a map from short name to module name.
@spec local_functions(Macro.t()) :: MapSet.t({atom(), non_neg_integer()})
Locally defined function names with arities, used to avoid mistaking local functions for imports.
@spec resolve(Macro.t(), t()) :: KogenCredo.CoreSupport.Ast.module_name() | nil
Resolves a module node using the file aliases.
Returns the fully-qualified module name ("MyApp.Repo") for {:__aliases__, ...} nodes
(first segment expanded through aliases) and the colon form (":rand") for Erlang modules;
nil for anything dynamic. No atom is created, so modules that are not loaded (or do not
exist) resolve like any other. __MODULE__ resolves when the map carries the enclosing
module under the :__MODULE__ key (as Scope.walk/3 provides).