The doxygen gate (clew guard)¶
clew guard is the pre-commit gate formerly published as
doxygen-guard, absorbed into clew at
doxygen-guard’s own 1.4.2 release. It enforces doxygen documentation and reports the change impact of a commit.
It is optional: nothing in the index pipeline runs it, and a repo that does not declare the
hook is unaffected.
What did not change: the config schema, the tag vocabulary, and every subcommand. What changed:
the command is clew guard (console script clew-guard), the package is clew.guard, the
pre-commit hook id is now clew-guard rather than doxygen-guard, Rust is supported on request — see
Rust — and the config is the guard: section of the repo’s .clew.yaml, the
same file that carries clew’s index declarations. .doxygen-guard.yaml is no longer read;
see Migrating from doxygen-guard.
flowchart LR
commit[git commit] --> hook[clew-guard hook<br/>staged files]
hook --> presence[every function documented<br/>@brief · @param · @return]
hook --> version[a changed body bumps<br/>its @version]
hook --> req["every @req names a requirement<br/>in the catalog"]
presence & version & req --> verdict{all pass?}
verdict -- yes --> ok[commit proceeds]
verdict -- no --> refuse[refused, each violation named]
hook -. clew guard impact .-> impact[impact.json<br/>requirements whose code changed]
impact -.-> wiki[the wiki's Change impact page]
Why it lives here¶
clew already read every target’s guard config — for the @req id pattern and the
requirements catalog — and it imported doxygen-guard to do it. The target’s gate and clew’s
index were therefore parsing one file with two independently pinned releases, and clew
carried a version-skew salvage layer to survive the disagreements. With the gate inside clew
and its config inside .clew.yaml, the gate and the index read one section with one schema,
from one release. They read it at different severities: the gate refuses an invalid guard:
section, while the index warns and runs on its defaults rather than failing a build.
Quick start¶
1. Add the hook¶
# .pre-commit-config.yaml
repos:
- repo: https://github.com/tvanfossen/clew
rev: <clew release tag>
hooks:
- id: clew-guard
types_or: [c, c++, python] # add rust / javascript / ts once declared — see below
Installing the hook installs clew; there is no lighter gate-only distribution.
2. Add a guard: section to .clew.yaml¶
# .clew.yaml
requirements: # the catalog — one section the gate, the index and the wiki read
file: docs/requirements.yaml
format: yaml
guard:
validate:
exclude:
- "tests/**"
- ".venv/**"
tags:
req:
pattern: "^REQ-[A-Z]+-[0-9]{3}$"
impact:
report_dir: docs/generated/impact/ # the default
The gate reads .clew.yaml from the directory it runs in (the repo root, under pre-commit);
args: [--config, path/to/file.yaml] points it at another file of the same shape. A file with
no guard: section, or no file at all, runs the gate on its built-in defaults. Everything
outside guard: is clew’s index declaration (index_scope:, locks:, …), which the gate
never reads.
3. Document your functions¶
/**
* @brief Read temperature from sensor hardware.
* @version 1.0
* @req REQ-SENSE-001
* @return Raw ADC value
*/
int Sensor_ReadTemperature(void) {
return hw_read_adc(TEMP_CHANNEL);
}
pre-commit run --all-files prints violations to stderr and writes the impact report
(impact.md, impact.json) to guard.impact.report_dir. It is the same report
clew guard impact prints: each requirement’s covering tests, via for an untagged change
reached through its callers (read from the repository’s existing index; a declaration whose
definition carries @req, or the reverse, is linked by those requirements directly, as coverage
counts the two as one function), and unmapped /
unmapped_files for changes that reach no requirement. A deleted path and a submodule bump are
listed under unmapped_files; neither is opened.
Migrating from doxygen-guard¶
Change the hook’s
repo:andrev:lines to point here, and the id fromdoxygen-guardtoclew-guard. This IS a breaking change and it is deliberate: the old id was being held in place by a code comment naming a file that no longer exists, and nothing resolves the string programmatically. One tool, one name.Move the contents of
.doxygen-guard.yamlunder aguard:key in.clew.yaml, indented one level, and delete.doxygen-guard.yaml. clew does not read it. Three keys then move, and each is refused, naming where it went, until it does:output_dir(andimpact.output) →guard.impact.report_dir;impact.requirements→ the top-levelrequirements:section, besideguard:;a
validate.excluderegex such as^gen/→ a glob (gen/**), or there:prefix (re:^gen/) to keep it a regex.clew guard validatelists every refusal in one run, so one pass fixes them all.
If the old file carried an
x-clew:section, move its sections to the top level of.clew.yaml(besideguard:, not inside it). Thex-passthrough is gone.If the hook passed
--config conf/doxygen-guard.yaml, drop the argument (the gate reads.clew.yamlat the root) or point it at the moved file.The gate refuses to run while
.doxygen-guard.yamlexists, or while.pre-commit-config.yamlstill names thedoxygen-guardhook id, naming each leftover. 2.0.0 is the hard cut: nothing doxygen-guard wrote is read. (clew indexonly warns, since it indexes repositories it must not change.)Replace every
@dg_internalwith@utility(a plain text replace; the gate refuses the old tag, naming the new one). Where a member’s doc block sits inside a class body, the class may then ask for its own@versionbump, because its body text changed.
What it checks¶
Every function in a staged file is checked for:
Presence:
@brief, the revision tag (@version), and@returnon non-void functions.Version staleness: when the function body changed against git
HEAD, the revision tag must have been incremented.Tag syntax: tag values match the configured patterns. Every doxygen built-in command (
@p,@c,@code,@sa,@retval…) is a known tag; an unknown one is a typo or a project tag, whichvalidate.extra_tagsdeclares (andclew guard doxyfilealiases).Requirement coverage:
@req, or an exemption tag.
A C/C++ declaration and its definition are one function. A prototype that carries its own
doc block, in a header or in a class body, has that block checked like a definition’s:
@brief, @version, @return, every @req resolving to the catalog, unknown and removed tags,
and @version staleness of its own text. A prototype with no doc block is skipped, because its
definition carries the documentation. The “@req or an exemption” rule stays with the
definition, so a header never needs its @req written twice. clew guard coverage matches the
two sides by Class::name(params), so a requirement tagged on either side counts once.
Exemption tag |
Effect |
|---|---|
|
Exempt from |
|
Exempt from |
@dg_internal, doxygen-guard’s tag, was removed in 2.0.0 and is refused with a pointer to
@utility. It is not @internal on purpose: doxygen’s \internal hides every tag after it in
the block when INTERNAL_DOCS is off, which is doxygen’s default.
These are tool vocabulary, not doxygen commands; clew guard doxyfile emits the ALIASES
that keep doxygen quiet about them. @internal is recognised but grants no exemption (it
hides the rest of the block from doxygen when INTERNAL_DOCS is off).
Change impact. The impact subcommand, and the pre-commit run when a catalog is declared,
cross-reference the diff with parsed functions and report which requirements the change
touches, as markdown and JSON under guard.impact.report_dir. clew guard impact prints the
report (--format markdown|json|text); --write writes both files there instead.
Requirement coverage. clew guard coverage reports covered, uncovered and orphan
requirements, plus documented functions carrying no @req. Exit code 1 when gaps exist.
Languages¶
Language |
Extensions |
Block |
Gated |
|---|---|---|---|
C |
|
|
by default |
C++ |
|
|
by default |
Python |
|
the docstring (PEP 257), or a |
by default |
Rust |
|
|
when declared |
JavaScript |
|
JSDoc |
when declared |
TypeScript |
|
JSDoc |
when declared |
Which extension is which language comes from
lang-parsing-substrate’s
registry, shared with knots, moldy and aurora-lint. A .h that contains C++ constructs is
parsed as C++. A language’s extensions: list in the config decides which files are checked.
Python¶
PEP 257 leads. A function’s docstring is its documentation, with or without tags. Its
summary line (the first line, up to a blank line) stands in for @brief, and the tags the
gate needs go inside it:
def apply_patch(repo_path: str, patch: str) -> int:
"""Apply a unified-diff patch to a project directory.
@version 1
@req REQ-PATCH-001
@return 0 on success, non-zero on failure.
"""
A doxygen ## block above the def is accepted too, and takes precedence when both exist,
so a codebase already documented for doxygen keeps working unchanged. An empty docstring is
not a block.
Changed from doxygen-guard: a docstring with no
@brief/@versionused to be ignored, so an idiomatic docstring reported “no doxygen comment”. It now counts as the block, and only the missing tag (usually@version) is reported.
doxygen itself renders a docstring as preformatted text. clew’s index reads the summary line
and @version out of it where doxygen left the function undocumented (see
Python integration). If you also generate docs with
doxygen, prefer the ## form or open the docstring with """!.
JavaScript and TypeScript¶
JSDoc, opt-in like Rust (validate.languages.javascript: {} / typescript: {}):
/**
* Trim and normalise a label.
* @version 2
* @req REQ-UI-004
*/
export const cleanLabel = (s: string): string => s.trim();
A function is a function declaration, a method, or a name bound to an arrow function or function expression (
const f = () => ..., a class fieldf = () => ...). Anonymous callbacks are not gated; neither are bodiless TypeScript signatures.The JSDoc block sits above the function, or above the
export/constaround it.Its summary stands in for
@brief, as for Rust.@return(or@returns) is not required unless the language entry setsrequire_return: true, and then only where a TypeScript return annotation says the function returns a value: notvoid,never,undefinedorPromiseof those. Plain JavaScript has no annotation, so it never requires one..tsxis parsed with the JSX-aware grammar and governed by thetypescriptentry.
Rust¶
doxygen has no Rust parser, so this is the gate applying its policy to rustdoc comments.
rustdoc has no tag vocabulary of its own: a doc comment is markdown, and only its first
paragraph has a defined meaning (the summary). The convention is therefore the same tags, in
/// lines, with three adjustments for how rustdoc is written:
/// Read the raw temperature.
///
/// Longer markdown prose, examples, `# Panics` sections — none of it is parsed.
///
/// @version 2
/// @req REQ-SENSE-001
#[inline]
pub fn read_temperature(channel: u8) -> u16 {
u16::from(channel) * 2
}
The summary paragraph is the brief. Without an explicit
@brief, the first paragraph counts as the brief. This is rustdoc’s rule, and doxygen’sJAVADOC_AUTOBRIEF. An explicit@briefwins.@returnis not required. rustdoc has no return tag and documents the result in prose. Setrequire_return: trueon therustentry to require it anyway. A function with no->or-> ()counts as void either way.Test code is not gated. Functions marked
#[test],#[tokio::test],#[rstest]or#[bench], and the#[cfg(test)]module, are skipped. Inline unit tests are idiomatic, so a path exclude cannot separate them from the code they test.
The block is the outer doc comment: /// lines (not ////, which rustdoc treats as a
plain comment) or one /** */ block. It is found across any #[...] attributes between it
and the fn, and a blank line inside a run of /// lines ends the block. Inner doc comments
(//!, /*!) document the module. They never document a function, and they are what
require_file_doxygen looks for in a .rs file, where @file is not required. A trait
method with no body is a declaration and is skipped, as a C prototype is. Methods are
identified by their impl type (impl<T> Trait for Foo<T> → Foo), so two news in two
impls do not share a revision history.
Rust is opt-in:
guard:
validate:
languages:
rust: {} # completed from the built-in defaults
and add rust to the hook’s types_or. Undeclared, .rs files are skipped. That way a repo
that adopted the gate for its C does not start failing on its Rust the first time it bumps
rev:. The defaults a declaration is completed from are published by
clew guard config --schema under opt_in_language_defaults.
What this does not do: check that the tags are meaningful to rustdoc (to rustdoc, @version 2
is literal text), parse markdown sections such as # Errors, check macro_rules! macros or
closures, or require docs on structs, enums and traits (the gate checks functions in every
language).
Files the gate skips¶
Binary files, whatever their extension: a zip or object file named
.cis never parsed. Detection is lang-parsing-substrate’sclassify_file(magic numbers and byte statistics from the first 8 KiB).The repository’s shared toolchain config, the files knots, moldy and aurora-lint also read (lang-parsing-substrate’s
docs/unified-config-spec.md), at the repo root:# toolchain.toml [ignore] paths = ["vendor/**", "third_party/**"] # every tool, including clew's index [clew.ignore] paths = ["legacy/**"] # clew's gate only # suppress.toml [[suppress]] name = "generated" tool = "*" # every tool ("clew" = the gate only) file_glob = "gen/**"
An entry that names a
rulesuppresses that rule only and excludes no file. These apply aftervalidate.exclude, andclew guard filesreports them (toolchain_config,toolchain_ignores).
Configuration reference¶
Every key below lives under the guard: section of .clew.yaml.
validate¶
Key |
Type |
Default |
Description |
|---|---|---|---|
|
dict |
C, C++, Python |
Per-language extensions, comment styles and excludes; |
|
bool |
— |
Overrides |
|
bool |
|
Require a block on every function |
|
bool |
|
Require |
|
bool |
|
Require a file-level block |
|
string |
|
Tag used as the per-function revision counter |
|
bool |
|
Require the revision tag |
|
bool |
|
Require a bump when the body changes |
|
list |
|
Globs for files to skip ( |
|
bool |
|
Flag a repeated |
|
list |
|
Further tag names to accept as known |
|
bool |
|
Report a tag no rule knows ( |
|
|
|
|
|
list |
— |
Name globs of functions that cross a bus, which must carry a bus tag |
|
list |
— |
Calls that choose a topic; a function calling one must carry a bus tag |
|
list |
— |
Allowed first words of a bus tag |
The bus tags are the event vocabulary — the top-level event_tags: the index reads, or the
index’s built-in one when none is declared (2.0.0; validate.bus.tags is refused with that
pointer). Those words are also known tags everywhere, and @node is known when wiki.sources is
declared, so a convention one part of clew asks for is never an unknown tag to another.
tags.<tag> — per-tag rules, for req or any tag you name (each key is checked):
Key |
Type |
Description |
|---|---|---|
|
string |
Regex the tag’s value must match |
|
list |
The value must start with one of these |
|
string |
The value must contain this |
|
bool |
|
languages.<lang> — per-language parsing (each key is checked):
Key |
Type |
Description |
|---|---|---|
|
list |
File extensions of the language |
|
string |
Regex locating a function definition |
|
list |
Function names never required to carry a block |
|
mapping |
|
|
bool |
Overrides |
|
bool |
|
|
string |
— |
version.tag exists because the gate treats the tag as a revision counter, where doxygen
documents \version as prose. A project using \version idiomatically can point the gate at
another tag and alias it: version: {tag: "@revision"} plus extra_tags: ["revision"].
impact¶
Key |
Type |
Default |
Description |
|---|---|---|---|
|
string |
|
Where the pre-commit run and |
|
string |
|
The branch the pre-commit impact report diffs against (merge-base to HEAD); a repository on |
coverage¶
Key |
Type |
Default |
Description |
|---|---|---|---|
|
number in (0, 1] |
none (no floor) |
Fail when the share of non-test functions carrying |
The ratio counts one function per identity (Class::name(params)), so a declaration and its
definition count once. Test code is the declared tests.paths, else the index’s built-in test
paths. There is no built-in floor: no standard sets one (DO-178C, ISO 26262 and IEC 62304
require every function to trace to a requirement or be justified), and the right number is the
repository’s. Every run prints the counts, pass or fail. clew’s own, measured with
clew guard coverage . at the repository root on 2026-11-19 (feat/1.3.1, after the @utility
fold):
Traceability: 1016 with @req, 1629 exempt (@utility 1629) — ratio 0.3841 (no floor declared)
Coverage runs in the hook. When a catalog or a floor is declared, clew guard <files> (the
pre-commit entry) also runs the coverage gate over the repository. Uncovered catalog entries,
@req naming no entry, and a ratio below the floor fail the commit. clew guard coverage
reports the same, with the full lists.
The top-level requirements: section¶
The catalog is the repository’s, not the gate’s: one top-level section that the gate, the index
and the wiki all read (2.0.0 — it was guard.impact.requirements, and the old location is
refused with a pointer here). One path is the short form of {file: <path>}.
Key |
Type |
Default |
Description |
|---|---|---|---|
|
string |
— |
Path to the requirements catalog |
|
string |
|
|
|
string |
|
Id column ( |
|
string |
|
Name column or field |
|
list |
— |
Catalogues this repository does not own: a path, or |
|
string |
|
The catalogue field that holds a requirement’s status |
|
list |
— |
Statuses that exempt an untagged requirement from |
|
map of field → list |
— |
Exempt by any catalogue field (2.1): |
|
string |
— |
Catalog field naming the release a requirement becomes active in (with |
|
string |
— |
A Sphinx-needs |
Moved in 2.0.0, each refused with where it went: guard.impact.requirements → requirements:,
guard.output_dir and guard.impact.output → guard.impact.report_dir,
guard.validate.version_gate.current_version → guard.validate.current_version,
guard.validate.version_gate.version_field → requirements.version_field, wiki.catalogs →
requirements.external, wiki.needs → requirements.needs, wiki.impact → the gate’s
report_dir.
The preferred catalog is a mapping keyed by id:
requirements:
REQ-VAL-001:
name: Doxygen presence check # required
subsystem: Validate # optional
min_version: v0.1.0 # optional
description: >- # optional
Every function must have a doxygen comment
acceptance_criteria: >- # optional
Undocumented functions produce presence violations
satisfies: [REQ-PRD-004] # optional: requirements this one serves
failure_modes: # optional (2.2): the ways it can fail
FM-VAL-001-1: an undocumented function passes
failure_modes maps each id to a one-line meaning. The ids are declared here once. A test names
the ones it guards with @fails_when FM-VAL-001-1 in its doc comment (for a Catch2 case, in the
comment block directly above it). The gate refuses an id no requirement declares, as it refuses
an unknown @req, and the requirement’s dossier lists each mode with the tests that name it.
A CSV catalogue cannot nest the mapping, so it declares none.
satisfies names requirements in this catalogue, in an external one, or as <catalog>:<id>;
a link no catalogue holds is a violation. The index records each link, and a requirement’s
dossier carries both directions, satisfies and satisfied_by. serves is read as the same link (2.1), so a
catalogue already written with serves: needs no rename; an entry may use either key, or both.
A module’s catalogue usually links up to a product’s, and the product’s clone is not on every
machine the module’s gate runs on. Mark that entry parent: true (2.1):
requirements:
external:
- {name: product, repo: ../product, rev: <sha>, path: requirements.yaml, parent: true}
Where the clone is present, links into it are checked like any other. Where it is not, the gate
does not fail: each link it cannot resolve is a warning, “unchecked — parent catalogue(s) product
not present here”. The product’s own gate, where the clone is, still checks them. An entry not
marked parent still refuses when it cannot be read.
A product requirement that no product code implements, but a module’s requirement satisfies, reads UNCOVERED. To count those, opt in (2.1):
guard:
coverage:
through_dependencies: true
clew guard coverage then counts such a requirement as covered through the dependency when that
dependency’s satisfying requirement is either:
implemented — its code carries the requirement tag at the pinned revision. This is checked with
git grepin the local clone at that revision, never taken from the dependency’s own status field; orexempt — exempt under this repository’s
exempt_status/exempt_when.
It is reported in its own list, “REQ-PRD-001 via lib:REQ-LIB-001 (implemented)”, never merged into
covered. The option is off by default; without it, nothing changes and covered_via is absent.
A missing file, an unknown format, a wrong shape, a missing name, or an id failing
validate.tags.req.pattern raises RequirementsError. The run fails rather than continuing
with an empty catalog.
A library whose requirements are owned by the product that consumes it names the product’s
catalogue under external and needs no file of its own:
requirements:
external:
- product/requirements.yaml # a path in this checkout
- {repo: ../product, rev: v3.2.0, path: requirements.yaml} # a local clone, at a pin
A pinned entry is read with git show rev:path, so it is the catalogue as of that revision, not
the clone’s working tree. The gate never fetches: a URL is refused by name.
No catalogue, a tag: a violation. With tags.req.cross_reference on and no catalogue
declared anywhere, every @req tag is reported as one that cannot be checked. (Before 2.0.0 it
passed unchecked.) Declare a catalogue, or set cross_reference: false.
Validation of the config itself¶
Unknown keys inside guard: are rejected, with a suggestion when one is close. There is no
x- passthrough: the rest of .clew.yaml is where anything that is not the gate’s belongs.
Escaping @¶
As in doxygen, @word is a command anywhere in a block, including mid-sentence. To mention a
tag in prose, write \@req or @@req.
Using doxygen alongside the gate¶
clew guard doxyfile > clew-guard.doxyfile # then: @INCLUDE = clew-guard.doxyfile
The fragment declares the gate’s tags as ALIASES (@req becomes a cross-referenced
“Requirement Index”) and enables WARN_IF_DOC_ERROR. Division of authority: doxygen
decides whether a comment is valid doxygen. The gate decides whether it satisfies your
policy: catalog membership, revision increments against git diff, per-file scoping.
Consumer contract¶
clew guard config --schema # schema, defaults, opt-in language defaults, contract_version
clew guard config --effective # the merged config in force and what it resolved to
clew guard files src/ # the exact post-exclude file set the gate walks
All three emit JSON carrying contract_version: 3 added opt_in_language_defaults, 4
added the toolchain fields to files, and 5 moved the config into .clew.yaml (config_file,
config_section) and dropped the x- passthrough fields. Typed errors are importable from clew.guard.errors:
GuardError, with ConfigError and RequirementsError.
CLI¶
clew guard [--config path] [files...] # pre-commit mode (what the hook runs)
clew guard validate --no-git src/*.c
clew guard validate --format sarif src/*.c > guard.sarif
clew guard impact --staged src/*.c
clew guard coverage src/
clew guard config --schema | --effective
clew guard files src/
clew guard doxyfile
clew guard -v coverage src/ # log which config sections were declared vs defaulted
clew-guard is the same entry point as a console script.
Machine-readable output¶
clew guard validate --format sarif|gitlab|github writes the violations to stdout for a
code host to annotate. The default, text, keeps the file:line: [check] message lines on
stderr. The exit code is the same in every format, and zero violations still produce a document
(an empty SARIF run, [], or no lines).
format |
consumer |
shape |
|---|---|---|
|
GitHub code scanning and other SARIF 2.1.0 readers |
one run, one rule per check class |
|
GitLab Code Quality (merge-request widget) |
JSON array of issues |
|
GitHub Actions annotations |
one |
The fingerprint ignores line numbers. SARIF partialFingerprints and the GitLab
fingerprint hash the check, the file, the function’s qualified identity (class, name,
parameters) and the message. Inserting lines above a function keeps its fingerprint the same,
and two overloads get different ones.
Complexity is not in these outputs. Cognitive complexity and return counts are checked by a
separate pre-commit hook, not by clew guard, so the SARIF, GitLab and GitHub documents never
carry them.
Adopting on an existing codebase¶
Start with presence and revision only. Add
@briefand@versionas you touch functions, and usevalidate.current_versionwithrequirements.version_fieldto require@reqonly on requirements from a given version on.Turn off
presence.require_returnduring migration if needed.Exclude what you are not ready to cover (
validate.exclude: ["vendor/**", "legacy/**"]).
Requirement ids in clew’s own catalog¶
The gate’s requirements are clew’s REQ-DDB-GUARD-001–025 in requirements.yaml. 001–023
are renumbered from doxygen-guard’s catalog, and each entry keeps its old id as
x-upstream-id. 024 is the Rust support and 025 JavaScript/TypeScript. The shared toolchain
config is REQ-DDB-CONFIG-009 and binary skipping REQ-DDB-PIPE-011, because the index
honours them too.