devops.cpp.style_rules

C++ rules for mstd devops.

Functions

check_header_guards(file_rule_input)

Check if the C++ header file has proper header guards.

collect_header_guard_errors(lines)

Find the header guard macro and collect all structural guard errors.

expected_header_guard_macro(path, pattern)

Compute the expected header guard macro name for a file path.

find_define_macro(lines, macro)

Check if the #define for the given macro exists in the lines.

find_header_guard(lines)

Find the header guard macro in the given lines.

Classes

CheckHeaderGuards()

Rule to check for proper header guards in C++ header files.

CheckKeySeqOrder(key_sequence)

Rule to check that a specific key sequence appears only in a given order.

Exceptions

HeaderGuardError

Custom exception for header guard errors.

class devops.cpp.style_rules.CheckKeySeqOrder(key_sequence)[source]

Bases: Rule

Rule to check that a specific key sequence appears only in a given order.

Parameters:

key_sequence (str)

exception devops.cpp.style_rules.HeaderGuardError[source]

Bases: Exception

Custom exception for header guard errors.

devops.cpp.style_rules.find_define_macro(lines, macro)[source]

Check if the #define for the given macro exists in the lines.

Parameters:
  • lines (list[str]) – The lines of the header file.

  • macro (str) – The header guard macro to look for.

Returns:

bool – True if the #define for the macro is found, False otherwise.

Return type:

bool

devops.cpp.style_rules.collect_header_guard_errors(lines)[source]

Find the header guard macro and collect all structural guard errors.

Unlike raising on the first problem found, this gathers every applicable structural issue (missing #define, a #define that doesn’t immediately follow #ifndef, a missing #endif) so callers can report them all together instead of one at a time across repeated runs.

Parameters:

lines (list[str]) – The lines of the header file.

Returns:

tuple[str | None, list[str]] – The header guard macro if an #ifndef was found (else None), and the list of error messages describing every structural problem found. An empty list means the header guard is well-formed.

Return type:

tuple[str | None, list[str]]

devops.cpp.style_rules.find_header_guard(lines)[source]

Find the header guard macro in the given lines.

Parameters:

lines (list[str]) – The lines of the header file.

Returns:

str – The header guard macro if found.

Raises:

HeaderGuardError – If the header guard is not properly defined. If more than one structural problem is present, all of them are reported together in a single error message.

Return type:

str

devops.cpp.style_rules.expected_header_guard_macro(path, pattern)[source]

Compute the expected header guard macro name for a file path.

Parameters:
  • path (Path) – The file path to derive the macro name from.

  • pattern (str or None) – A format string with {path} and {ext} placeholders used to build the macro name, or None to use the default __{path}_{ext}__ pattern. {path} is built from the path with any leading include/, test/ or src/ directory removed and its extension stripped: each remaining directory and the file stem is converted from camelCase/PascalCase to SNAKE_CASE (so velocityVerlet becomes VELOCITY_VERLET, not VELOCITYVERLET), then joined with __. {ext} is the upper-cased extension (HPP, IMPL_HPP, TPP or H).

Returns:

str – The expected header guard macro name.

Return type:

str

devops.cpp.style_rules.check_header_guards(file_rule_input)[source]

Check if the C++ header file has proper header guards.

Parameters:

file_rule_input (FileRuleInput) – The input containing the file content and path to check.

Returns:

ResultType – The result of the header guard check.

Return type:

ResultType

class devops.cpp.style_rules.CheckHeaderGuards[source]

Bases: Rule

Rule to check for proper header guards in C++ header files.