devops.cpp.cpp_only_include_scan
Plain-text scanning for cpp-only header violations.
This mirrors the semantics of the enforceCppOnlyInclude AST check (devops.cpp.ast.checks.enforce_cpp_only_include) but works purely off of a file’s raw text via regex, with no libclang parse involved. Two consequences make that useful:
It has no dependency on the optional
astextra, so it runs even when libclang isn’t installed.It can be run as a standalone, whole-project pre-check (see devops.cpp.checks.run_cpp_only_include_precheck) over every header file, independent of whatever subset of files a given invocation is scoped to (a
--base-refdiff, staged files, or an incremental-state skip) — a violation sitting in an untouched header can’t silently pass just because that header wasn’t part of the current run’s selection.
Module Attributes
Shared with devops.cpp.ast.checks.enforce_cpp_only_include's check id, duplicated here (rather than imported) so this module never needs to import that check module and, transitively, libclang. |
Functions
|
Return every #include directive in content as (line number, path). |
|
Return whether filename is an including file this check applies to. |
|
Return whether include_path matches a configured cpp-only header pattern. |
|
Scan a header file's raw text for #includes of a configured cpp-only header. |
- devops.cpp.cpp_only_include_scan.CHECK_ID = 'enforceCppOnlyInclude'
Shared with devops.cpp.ast.checks.enforce_cpp_only_include’s check id, duplicated here (rather than imported) so this module never needs to import that check module and, transitively, libclang.
- devops.cpp.cpp_only_include_scan.find_includes(content)[source]
Return every #include directive in content as (line number, path).
- devops.cpp.cpp_only_include_scan.is_checked_file(filename, extensions=())[source]
Return whether filename is an including file this check applies to.
- Parameters:
- Returns:
bool – True if the check applies to filename.
- Return type:
- devops.cpp.cpp_only_include_scan.matches_cpp_only_header(include_path, headers)[source]
Return whether include_path matches a configured cpp-only header pattern.
Matching is against the
#includepath exactly as written in the source — never against just its basename. This matters whenever two different libraries happen to ship a same-named header: a pattern of"units.hpp"matches a bare#include "units.hpp", but not#include <mstd/units.hpp>— a distinct file from a different library that merely shares the name. To match a header regardless of which directory it’s included from, write an explicit glob (fnmatch’s*matches across/too), e.g."*/units.hpp"or"*_impl.hpp".
- devops.cpp.cpp_only_include_scan.scan_text_for_violations(filename, content, headers, exclude_paths=(), extensions=())[source]
Scan a header file’s raw text for #includes of a configured cpp-only header.
- Parameters:
filename (str) – Path of the header file being scanned (used for diagnostics, and matched against exclude_paths; the caller is responsible for only scanning actual header files).
content (str) – The file’s full text.
headers (Iterable[str]) – The configured cpp-only header patterns (see matches_cpp_only_header).
exclude_paths (Iterable[str]) – Path patterns (see devops.cpp.path_patterns.matches_path) identifying including files that are exempt from this check — e.g. the header that itself wraps/defines a cpp-only header and must therefore include it unconditionally. When filename matches any pattern here, nothing is flagged regardless of headers.
extensions (Iterable[str]) – If non-empty, only files with one of these extensions are checked (see is_checked_file); other files yield no diagnostics.
- Returns:
list[Diagnostic] – One diagnostic per
#includeline matching a configured cpp-only header pattern, unless filename is excluded.- Return type: