diff --git a/CHANGELOG.md b/CHANGELOG.md index e7f36ac..0b1656b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. ## Next Release +### Features + +#### CPP Rules + +- make it possible to check header guards also for `.tpp` and `.impl.hpp` files + ## [0.1.0](https://github.com/repo/owner/releases/tag/0.1.0) - 2026-01-18 diff --git a/src/devops/cpp/style_rules.py b/src/devops/cpp/style_rules.py index 75fd7f6..ffc944e 100644 --- a/src/devops/cpp/style_rules.py +++ b/src/devops/cpp/style_rules.py @@ -145,10 +145,21 @@ def check_header_guards(file_rule_input: FileRuleInput) -> ResultType: expected_macro = str(path).upper() expected_macro = expected_macro.removeprefix("INCLUDE/") expected_macro = expected_macro.removeprefix("TEST/") + expected_macro = expected_macro.removeprefix("SRC/") expected_macro = expected_macro.replace("/", "__") - expected_macro = expected_macro.removesuffix(".HPP") - expected_macro = expected_macro.removesuffix(".H") - expected_macro = "__" + expected_macro + "_HPP__" + + if expected_macro.endswith(".IMPL.HPP"): + expected_macro = expected_macro.removesuffix(".IMPL.HPP") + expected_macro = "__" + expected_macro + "_IMPL_HPP__" + elif expected_macro.endswith(".HPP"): + expected_macro = expected_macro.removesuffix(".HPP") + expected_macro = "__" + expected_macro + "_HPP__" + elif expected_macro.endswith(".TPP"): + expected_macro = expected_macro.removesuffix(".TPP") + expected_macro = "__" + expected_macro + "_TPP__" + elif expected_macro.endswith(".H"): + expected_macro = expected_macro.removesuffix(".H") + expected_macro = "__" + expected_macro + "_H__" if guard_macro != expected_macro: msg = ( diff --git a/src/devops/files/files.py b/src/devops/files/files.py index cb53400..6d54aad 100644 --- a/src/devops/files/files.py +++ b/src/devops/files/files.py @@ -85,7 +85,7 @@ def determine_file_type(filename: str | Path) -> FileType: """ filename = str(filename) - if filename.endswith((".h", ".hpp")): + if filename.endswith((".h", ".hpp", ".tpp", ".impl.hpp")): return FileType.CPPHeader if filename.endswith((".cpp", ".cxx", ".cc", ".c")): return FileType.CPPSource diff --git a/tests/cpp/test_style_rules.py b/tests/cpp/test_style_rules.py index 8e4f8cd..8990eef 100644 --- a/tests/cpp/test_style_rules.py +++ b/tests/cpp/test_style_rules.py @@ -610,8 +610,8 @@ class MockClass {}; def test_check_header_guards_with_h_extension(self) -> None: """Test header guards with .h extension.""" - file_content = """#ifndef __MYHEADER_HPP__ -#define __MYHEADER_HPP__ + file_content = """#ifndef __MYHEADER_H__ +#define __MYHEADER_H__ void myFunction();