devops.cpp.ast.checks.no_forbidden_include
Flag #include directives of libraries that must never be included.
Some libraries (e.g. mp-units) must not be pulled into a code base at
all. This check flags every #include whose path matches one of the
configured patterns, whether written with quotes or angle brackets, in any
file.
Patterns are matched against the #include path exactly as written in the
source. A pattern matches if it equals the path (with fnmatch rules, where
* also matches /) or if it names a directory prefix, so a bare
library name excludes the library and all of its subfiles:
[cpp.ast_check_config.noForbiddenInclude]
libs = ["mp-units", "boost/hana.hpp", "*_deprecated.hpp"]
mp-units above matches <mp-units/systems/si.h> as well as
<mp-units/core.h>. Files that are allowed to include a forbidden library
anyway can be exempted via exclude_paths (a trailing / matches a
directory prefix; anything else is an fnmatch glob):
[cpp.ast_check_config.noForbiddenInclude]
libs = ["mp-units"]
exclude_paths = ["src/units/"]
An empty/unset libs list disables the check entirely.
Functions
|
Return whether include_path matches any forbidden-library pattern. |
Classes
Flag #includes of configured libraries that must never be included. |
- devops.cpp.ast.checks.no_forbidden_include.matches_forbidden_include(include_path, patterns)[source]
Return whether include_path matches any forbidden-library pattern.
- class devops.cpp.ast.checks.no_forbidden_include.NoForbiddenInclude[source]
Bases:
CheckFlag #includes of configured libraries that must never be included.
- configure(config)[source]
Load the forbidden library patterns.
- Parameters:
config (dict) – Expected shape:
{"libs": ["mp-units"], "exclude_paths": ["src/units/"]}. Whenlibsis absent or empty, this check never flags anything.- Raises:
ConfigError – If
libsorexclude_pathsis present but is not a list of strings, or if the table contains any other (e.g. misspelled) key.- Return type:
None
- visit(cursor, filename)[source]
Flag the cursor if it’s an #include of a forbidden library.
- Parameters:
cursor (clang.Cursor) – The AST node currently being visited.
filename (str) – Path of the file being checked.
- Returns:
list[Diagnostic] – A single diagnostic if cursor is an
#includedirective of a forbidden library, otherwise an empty list.- Return type: