Module

linting.runner

The lint() entrypoint and the Linter class.

lint() is the headline function (symmetric with parse/render). It accepts astr(parsed internally, capturing the source for line rules) OR a pre-parsedDocument(with the raw source supplied via the keyword-onlytext parameter). One LintContext is built and fed to each rule'scheckonce; the runner STAMPS each diagnostic'srule_id and severityfrom the emitting rule, then returns a deterministically sorted list.

Thread Safety:

No module-level mutable state. The only mutable state is the per-call
accumulator list and the per-construction ``_NodeCollector`` inside the
context — both created fresh per call. A single `Linter` (immutable
registry on ``__slots__``) is safe to share across threads.

Classes

Linter 2
Reusable linter bound to an immutable rule registry. Use this to lint many documents with a fixed …

Reusable linter bound to an immutable rule registry.

Use this to lint many documents with a fixed rule set. The registry is held immutably on__slots__; each lint() call builds its own context and accumulator, so one Linter is safe to share across threads.

Methods

lint 3 list[Diagnostic]
Lint Markdown using this linter's registry. Same polymorphic signature as the …
def lint(self, source: str | Document, *, text: str = '', source_file: str | None = None) -> list[Diagnostic]

Lint Markdown using this linter's registry.

Same polymorphic signature as the top-levellint(), minus the rulesargument (the registry is fixed at construction).

Parameters
Name Type Description
source

Markdown source string, or a pre-parsedDocument.

text

Raw source for a pre-parsedDocument (see :func:lint).

Default:''
source_file

Optional source file path.

Default:None
Returns
list[Diagnostic] A sorted list of :class:`Diagnostic`.
Internal Methods 1
__init__ 1
Initialize with a registry (the default starter rules if None).
def __init__(self, registry: LintRuleRegistry | None = None) -> None
Parameters
Name Type Description
registry

An immutable :class:LintRuleRegistry. Defaults to :func:create_default_lint_registry.

Default:None

Functions

_resolve_rules 1 tuple[LintRule, ...]
Normalize the ``rules`` argument to a tuple of rules in order.
def _resolve_rules(rules: Sequence[LintRule] | LintRuleRegistry | None) -> tuple[LintRule, ...]
Parameters
Name Type Description
rules Sequence[LintRule] | LintRuleRegistry | None
Returns
tuple[LintRule, ...]
_run 2 list[Diagnostic]
Run rules over a context, stamping id/severity, sorted for determinism.
def _run(ctx: LintContext, rules: tuple[LintRule, ...]) -> list[Diagnostic]
Parameters
Name Type Description
ctx LintContext
rules tuple[LintRule, ...]
Returns
list[Diagnostic]
lint 4 list[Diagnostic]
Lint Markdown and return a list of diagnostics. Pass a ``str`` for the trivial…
def lint(source: str | Document, *, text: str = '', source_file: str | None = None, rules: Sequence[LintRule] | LintRuleRegistry | None = None) -> list[Diagnostic]

Lint Markdown and return a list of diagnostics.

Pass astrfor the trivial path: it is parsed internally and the same string is used as the raw source for line-oriented rules, so all rules run with zero ceremony. Pass a pre-parsed Document for the power path, supplying the raw source viatext=so source-driven rules (e.g. trailing-whitespace) are not silently skipped.

Parameters
Name Type Description
source str | Document

Markdown source string, or a pre-parsedDocument.

text str

Raw source for a pre-parsedDocument. Ignored when source is a str. If omitted for a Document, source-driven rules have no input and emit nothing (AST rules still run).

Default:''
source_file str | None

Optional source file path; flows into the parse and into synthesized diagnostic locations.

Default:None
rules Sequence[LintRule] | LintRuleRegistry | None

An explicitSequence[LintRule] (used in order), a :class:LintRuleRegistry (uses registry.rules), or None (the three built-in starter rules).

Default:None
Returns
list[Diagnostic]