AST-Based C++ Checks
The text-based style checks (header guards, keyword order, license headers)
cannot express anything that depends on meaning — the type of a parameter,
whether a name resolves to std::, what a macro expands to. For that,
cpp_checks can optionally parse each file with libclang and run a set of
semantic checks over the resulting AST.
Requirements & enabling
AST checks need the optional ast extra (bundles libclang):
pip install devops[ast]
They are on by default once installed. Toggle and tune them from the
[cpp] section:
Key |
Purpose |
|---|---|
|
Master on/off switch (default |
|
Directory containing |
|
Fallback compiler flags (e.g. |
|
Allowlist / denylist of check ids, by the |
See Configuration File for the full key reference, defaults, and a worked TOML example.
How checks run
All enabled checks share a single preorder walk over each file’s AST (see
devops.cpp.ast.engine) — adding another check never costs another parse.
Each one implements devops.cpp.ast.base.Check and reports zero or more
Diagnostics, formatted like cppcheck output:
src/box.cpp:42:18: style: parameter of type 'molsys::SimulationBox' named 'box' should be named 'simulationBox' [paramNameForType]
The trailing [check-id] is what you put in ast_check_enabled_ids /
ast_check_disabled_ids to select or silence that check.
Available checks
Check id |
Flags |
Configuration |
|---|---|---|
A private or protected member variable not starting with |
None |
|
A private or protected member function not starting with |
None |
|
A public member variable/function starting with |
None |
|
A member variable/function declared before a section that must precede it (public/protected/private members, then public/protected/private member functions). |
Optional ( |
|
A parameter of a configured type not using its canonical name. |
Required ( |
|
Use of a banned macro that has a required replacement. |
Optional (ships with a default mapping) |
|
|
Optional (name filters) |
|
|
Optional (name filters) |
|
|
None |
|
|
None |
|
|
None |
|
|
None |
|
A named by-value parameter declared with top-level |
None |
|
|
None |
|
A template type parameter introduced with |
None |
|
A quoted |
Required ( |
|
A trailing comment on an |
Optional ( |
|
An |
Required ( |
|
A configured header |
Required ( |
|
A parameter of a configured type not passed by (const) reference or by value as required. |
Required ( |
|
A member function whose body is written inside the class definition. |
None |
|
An anonymous namespace defining a class/struct or holding more than
|
Optional ( |
|
A hand-written |
Optional ( |
|
|
None |
|
A |
None |