devops.cpp
Package defining C++ check rules.
- devops.cpp.add_license_header(file, header_to_add, *, dry_run=False)[source]
Add the license header to the file content if it’s missing.
- Parameters:
- Returns:
bool – True if the license header was added, False if it was already present.
- Raises:
DevOpsFileNotFoundError – If the header file does not exist.
- Return type:
- devops.cpp.build_cpp_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))[source]
Build and return the list of C++ rules based on the global configuration.
- devops.cpp.filter_buggy_cpp(files)[source]
Filter out known buggy C++ header files from a list of files.
- devops.cpp.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:
Modules
AST-based (libclang) C++ checks for devops. |
|
Module for filtering known buggy C++ header files. |
|
Module to build C++ rules based on global configuration. |
|
C++ checks module. |
|
Plain-text scanning for cpp-only header violations. |
|
File-based rule flagging forbidden spellings, like a reverse dictionary. |
|
Module to check for license headers in C++ files. |
|
Shared file-path pattern matching for per-check path exceptions/exclusions. |
|
State persistence for incremental C++ checks. |
|
C++ rules for mstd devops. |