Igniter.Refactors.Rename (igniter v0.8.0)

View Source

Refactors for renaming things in a project

Summary

Functions

rename_function(igniter, old, new, opts \\ [])

@spec rename_function(
  Igniter.t(),
  old :: {module(), atom()},
  new :: {module(), atom()},
  opts :: Keyword.t()
) :: Igniter.t()

Renames a function globally across a project.

Options

  • :arity - :any | integer | [integer]. The arity or arities of the function to rename. Defaults to :any.

  • :deprecate - :soft | :hard. Leave the original function in place, but with a deprecation. Soft deprecations appear in documentation but do not cause warnings. Hard deprecations warn when they are called.

rename_module(igniter, old_module, new_module, opts \\ [])

@spec rename_module(Igniter.t(), module(), module(), Keyword.t()) :: Igniter.t()

Renames a module globally across a project.

Renames the module everywhere it appears: defmodule, alias, use, import, require, and all call sites. Also handles submodules, the corresponding test module, string literals mentioning the module name, and moves the file(s) to match the new module's proper location.

Alias handling

  • alias Foo.Bar — the alias declaration and all Bar.* call sites are renamed.
  • alias Foo.{Bar, Other} — the declaration and call sites are renamed. Spitfire does not macro-expand the brace form, so resolution falls back to an explicit AST scan.
  • alias Foo.Bar, as: B — only the declaration is updated (alias Foo.Baz, as: B). B.* call sites are left untouched because the as: clause still resolves correctly.

Limitations

  • Dynamic references (e.g. apply/3, Module.concat/2 with variables) are not rewritten.
  • String-literal replacement is a plain substring replace over the raw file content, so it also rewrites occurrences in comments and unrelated strings. Grep after.

subsume_module_attrs(zipper, attrs \\ [], top? \\ true)