Adze.Move (Adze v0.1.0)

Copy Markdown View Source

mv — reorder a logical definition within a single file.

Moves a def (with its attached @spec/@doc/leading comments and every clause — i.e. the whole Adze.Definition group) to just before another def in the same module.

Scope:

  • Single file, single module. Both --definition and --before must resolve to defs in the same defmodule. Cross-module moves are explicitly out of scope — that's extract's job.
  • --before is the only supported anchor (no --after).
  • mv/2 is pure (returns the diff + new source). mv!/2 writes the file.

Usage

iex> Adze.Move.mv(source, definition: "bar/2", before: "baz/1")
{:ok, %{diff: "...", new_source: "..."}}

Adze.Move.mv!("lib/foo.ex", definition: "bar/2", before: "baz/1")
# → {:ok, %{diff: ..., new_source: ...}}  +  rewrites lib/foo.ex

Summary

Types

opts()

@type opts() :: [
  definition: Adze.Definition.definition_spec(),
  before: Adze.Definition.definition_spec(),
  include_attrs: [atom()]
]

result()

@type result() :: %{diff: String.t(), new_source: String.t()}

Functions

mv(source, opts)

@spec mv(String.t(), opts()) :: {:ok, result()} | {:error, term()}

mv!(path, opts)

@spec mv!(Path.t(), opts()) :: {:ok, result()} | {:error, term()}

mv_file(path, opts)

@spec mv_file(Path.t(), opts()) :: {:ok, result()} | {:error, term()}