devops.cpp.checks
C++ checks module.
Functions
|
Run C++ checks based on the provided rules. |
|
Hard pre-check: scan every header in the project for cpp-only violations. |
|
Run file-based C++ checks on a given file. |
|
Run line-based C++ checks on a given file. |
Exceptions
Custom exception for C++ check errors. |
- exception devops.cpp.checks.CppCheckError[source]
Bases:
ExceptionCustom exception for C++ check errors.
- devops.cpp.checks.run_line_checks(rules, file, content=None)[source]
Run line-based C++ checks on a given file.
- Parameters:
- Returns:
list[ResultType] – The list of results from the checks.
- Raises:
CppCheckError – If a non-line rule is provided.
- Return type:
- devops.cpp.checks.run_file_rules(rules, file, content=None)[source]
Run file-based C++ checks on a given file.
- Parameters:
- Returns:
list[ResultType] – The list of results from the checks.
- Raises:
CppCheckError – If a non-file rule is provided.
- Return type:
- devops.cpp.checks.run_cpp_only_include_precheck(config)[source]
Hard pre-check: scan every header in the project for cpp-only violations.
This is a text/regex scan (see devops.cpp.cpp_only_include_scan), not the libclang-based enforceCppOnlyInclude AST check, and it always covers the entire repository (_collect_all_header_files) rather than whatever subset of files a given invocation happens to be scoped to. That makes it independent of incremental caching, any git-diff-based file selection (
--base-ref,check_only_staged_files), and evenconfig.check_dirsitself: a violation sitting in a header that wasn’t touched in the current diff, was already marked “passed” by the incremental state file, or simply lives outside the configuredcheck_dirs, is still caught every single run.Honors
config.fail_fastthe same way the rest of the pipeline does: when set (the default), scanning stops at the first file with a violation instead of walking every remaining header.
- devops.cpp.checks.run_cpp_checks(rules, config=CppConfig(style_checks=True, license_header_check=True, license_header=None, check_only_staged_files=False, check_dirs=[], exclude_dirs=[], header_guards_according_to_filepath=False, header_guard_pattern=None, ast_checks=True, ast_check_compile_args=['-std=c++23'], ast_check_compile_commands_db=None, ast_check_enabled_ids=[], ast_check_disabled_ids=[], ast_check_config={}, forbidden_spellings={}, incremental_state_file=None, fail_fast=True, parallel_jobs=1), dirs=None, state_file=None, base_ref=None, config_file=None)[source]
Run C++ checks based on the provided rules.
By default the function returns immediately after encountering the first file with errors (fail-fast). Set
config.fail_fast = False(or pass--no-fail-faston the CLI) to check all files regardless.When
state_fileis given the run is incremental: results are persisted tostate_fileafter every checked file, and only files that are new, previously failed, or modified since the last run are re-checked. The return value isFalsewhenever any entry in the accumulated state is failed. The state is discarded wheneverconfig_filechanged since it was written.When
config.parallel_jobs != 1and an AST-checks rule is present, the libclang parse (the one CPU-bound, per-file cost) is dispatched across a process pool instead of running serially; every other rule (line/file/style rules) still runs once per file in the main process, since that work is cheap. Withparallel_jobs > 1andfail_fastenabled, the run stops scheduling further files soon after a failure is seen, rather than at the exact first failing file in listing order.- Parameters:
config (CppConfig) – The global C++ configuration.
dirs (list[Path] | None) – If given, only files under these directories are checked.
state_file (Path | None) – Path to the JSON state file used for incremental runs. When
None(the default) no state is read or written and the classic fail-fast behavior is used.base_ref (str | None) – A git commit hash or branch name. When given, only files changed relative to it (see
get_changed_files) are checked, overridingcheck_only_staged_files. The changed files are still further restricted toconfig.check_dirs(if set) and, when given, todirs, which takes precedence overconfig.check_dirs.config_file (Path | None) – The TOML config file in use. Its content hash is stored in the state file; when it differs on the next run, all incremental state is invalidated and every file is re-checked.
- Raises:
CppCheckError – If invalid (non-file or non-line) rules are provided.
GitRefError – If
base_refcannot be resolved.
- Returns:
bool – True if all checks pass, False if any check fails.
- Return type: