API Reference presubmit v#0.2.2

Copy Markdown View Source

Modules

Assertions over the shape and contents of git commits, run as a linter.

Behaviour for library-aware adapters that turn a module's facts into a domain model: an Ecto schema's fields, a Phoenix router's routes, a supervisor's children.

Models use Ecto.Migration modules as a list of schema operations.

Models use Ecto.Schema modules.

One field, association, or embed declaration.

Models test modules: use ExUnit.Case, or use of any module whose name ends in Case (MyApp.DataCase, MyAppWeb.ConnCase).

Models OTP behaviours and the children they start.

Models the modules a Phoenix router can route to: controllers, LiveViews, and LiveComponents, plus channels.

Models Phoenix routers (use Phoenix.Router, or use MyAppWeb, :router) as a flat list of routes with plug modules fully resolved.

One route: verb, full path, resolved plug module, and action.

ExUnit assertion verbs over a Presubmit.Commit.

Assertions over CHANGELOG.md, built on Presubmit.Changelog.

Assertions over Ecto schemas and migrations, built on Presubmit.Adapters.EctoSchema and Presubmit.Adapters.EctoMigration.

Assertions over test coverage of a change, built on Presubmit.Adapters.ExUnitCase.

Assertions over mix.exs and mix.lock, built on Presubmit.MixFile.

Assertions over OTP processes and supervision trees, built on Presubmit.Adapters.OtpProcess.

Assertions over Phoenix routers, controllers, and LiveViews, built on Presubmit.Adapters.PhoenixRouter and Presubmit.Adapters.PhoenixHandler.

The logic behind mix presubmit, separated from Mix so it can be driven from tests: parse arguments, load configuration and change sets, run, render, and return an exit status.

Reads a Markdown changelog as a list of sections keyed by heading.

A change set: the trees before and after, the per-file changes between them, and (for real commits) the metadata and message.

Loads the rule configuration from .presubmit.exs, or builds a default one from what the examined tree and the VM contain.

Raised when the configuration file is missing, invalid, or names unknown rules.

One file's change between the before and after trees.

Renders runner reports as text or JSON.

Thin adapter over the git plumbing commands presubmit relies on.

Raised when a git command fails or its output cannot be interpreted.

Installs and removes the git hooks that run mix presubmit.

A contiguous run of changed lines within one file, with zero context.

Raised when the revision under test is a merge commit.

A parsed commit message: subject, body, and trailers.

Reads dependency and version declarations from mix.exs and mix.lock without evaluating them.

Raised when a message assertion runs against a change set that has no commit message, such as the staged index.

Path patterns for the conventional directories, anchored so they work at the repository root and inside umbrella apps or subdirectory projects (apps/foo/lib/, services/bar/test/).

Path patterns accepted by every query and assertion.

Functions that read facts out of a Presubmit.Commit for use in assertions or directly in tests.

One named check over a change set.

A module that groups related rules, so a configuration can enable a whole area of policy with one entry.

Reported (never raised) when a rule does not finish within the runner's timeout; the rule is killed and the run continues.

Changelog: API changes and releases are recorded. Option path: (default CHANGELOG.md).

Ecto: migrations are ordered, immutable, safe, reversible, and back every schema change.

Elixir source hygiene: specs, docs, deprecation before removal, pure moves.

ExUnit: new modules and behaviour changes come with tests.

Things that should never be committed. Options

Commit message conventions. All of these skip for change sets without a message.

Mix: mix.lock moves with mix.exs.

OTP: every added process is started by a supervisor.

Phoenix: every added controller and LiveView is routed.

Commit size. Options max_files: (default 50) and max_additions: (default 1000).

Runs rules against change sets and collects the outcomes.

Every rule's outcome for one change set.

The outcome of one rule against one change set.

Raised when the parent of the revision under test is not present locally.

Entry points for the Elixir-aware layers: the structural diff of a commit and the adapter models derived from it.

The shared cache of extracted facts: a public ETS table keyed by {blob_oid, path}, so a range of commits parses each distinct file version once.

The structural difference between the Elixir source before and after a change set: modules and functions added, removed, renamed, or changed.

Structural facts about one Elixir source file, extracted from its AST.

One function or macro, folded across its clauses.

One defmodule, including nested ones (named Outer.Inner).

Tree-wide discovery of modules, for invariants that need to look beyond the files a commit changed: "some router routes this controller", "some supervisor starts this server", "a test module exists for this module".

A snapshot of every file in the repository at one point in history.

Raised by an assertion verb when a change set does not satisfy it.

Mix Tasks

Runs the rules in .presubmit.exs (or the built-in defaults) against a change set and reports each rule as passed, failed, or skipped.

Installs a commit-msg hook that runs mix presubmit --staged --message-file "$1", so the staged changes and the message are checked together before the commit is created, and a prepare-commit-msg hook that tells it when the commit amends HEAD, so the amended commit (HEAD^ to the index) is what gets checked rather than the delta since HEAD.