ArchTest.Rule (ArchTest v0.3.0)

Copy Markdown View Source

Represents an architecture rule — a description and a check function that evaluates against the dependency graph and returns a list of violations.

Summary

Functions

Evaluates a reusable rule and raises an ExUnit assertion on violations.

Evaluates a rule against the given dependency graph.

Attaches a freeze baseline id to the rule.

Adds ignore filters to a reusable rule.

Creates a reusable architecture rule from a graph check function.

Types

graph()

@type graph() :: %{required(module()) => [module()]}

t()

@type t() :: %ArchTest.Rule{
  check_fn: (graph() -> [ArchTest.Violation.t()]),
  description: String.t(),
  freeze_id: String.t() | nil,
  ignore: keyword()
}

Functions

assert(rule, opts \\ [])

@spec assert(
  t(),
  keyword()
) :: :ok

Evaluates a reusable rule and raises an ExUnit assertion on violations.

Options:

  • :graph — pre-built graph
  • :app — app to inspect when :graph is not present

evaluate(rule, graph)

@spec evaluate(t(), graph()) :: {:ok, []} | {:violations, [ArchTest.Violation.t()]}

Evaluates a rule against the given dependency graph.

Returns {:ok, []} when no violations are found, or {:violations, [Violation.t()]} otherwise.

freeze(rule, freeze_id)

@spec freeze(t(), String.t()) :: t()

Attaches a freeze baseline id to the rule.

ignore(rule, filters)

@spec ignore(
  t(),
  keyword()
) :: t()

Adds ignore filters to a reusable rule.

Supported keys: :caller, :callee, and :module, each with a module glob pattern or list of patterns.

new(description, check_fn)

@spec new(String.t(), (graph() -> [ArchTest.Violation.t()])) :: t()

Creates a reusable architecture rule from a graph check function.