diff --git a/change_notes/2026-09-04-add-exclusion-check-for-include-guards.md b/change_notes/2026-09-04-add-exclusion-check-for-include-guards.md new file mode 100644 index 0000000000..ff25ef3480 --- /dev/null +++ b/change_notes/2026-09-04-add-exclusion-check-for-include-guards.md @@ -0,0 +1,2 @@ +- `DIR-4-10`, `M16-2-3`, and `RULE-19-2-1`: + - Header files matched by a configured exclusion are no longer reported. \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/rules/includeguardsnotused/IncludeGuardsNotUsed.qll b/cpp/common/src/codingstandards/cpp/rules/includeguardsnotused/IncludeGuardsNotUsed.qll index f2e4fa277e..fefe57b319 100644 --- a/cpp/common/src/codingstandards/cpp/rules/includeguardsnotused/IncludeGuardsNotUsed.qll +++ b/cpp/common/src/codingstandards/cpp/rules/includeguardsnotused/IncludeGuardsNotUsed.qll @@ -24,6 +24,7 @@ class BlockedIncludeGuard extends HeaderFile { } query predicate problems(HeaderFile file, string message, HeaderFile other, string name) { + not isExcluded(file, getQuery()) and not file instanceof CorrectIncludeGuard and if file instanceof BlockedIncludeGuard then diff --git a/cpp/common/test/rules/includeguardsnotused/IncludeGuardsNotUsed.expected b/cpp/common/test/rules/includeguardsnotused/IncludeGuardsNotUsed.expected index f915e37ec1..dda204cd18 100644 --- a/cpp/common/test/rules/includeguardsnotused/IncludeGuardsNotUsed.expected +++ b/cpp/common/test/rules/includeguardsnotused/IncludeGuardsNotUsed.expected @@ -2,3 +2,4 @@ | headers/test4.hpp:0:0:0:0 | headers/test4.hpp | Header file test4.hpp is missing expected include guard. | headers/test4.hpp:0:0:0:0 | headers/test4.hpp | | | headers/test5.hpp:0:0:0:0 | headers/test5.hpp | Header file test5.hpp is missing expected include guard. | headers/test5.hpp:0:0:0:0 | headers/test5.hpp | | | headers/test6.hpp:0:0:0:0 | headers/test6.hpp | Header file test6.hpp is missing expected include guard. | headers/test6.hpp:0:0:0:0 | headers/test6.hpp | | +| headers/test7.hpp:0:0:0:0 | headers/test7.hpp | Header file test7.hpp is missing expected include guard. | headers/test7.hpp:0:0:0:0 | headers/test7.hpp | | diff --git a/cpp/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.xml b/cpp/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.xml new file mode 100644 index 0000000000..adf7df0ce6 --- /dev/null +++ b/cpp/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.xml @@ -0,0 +1,10 @@ + + + + + + cpp-test-dummy + This header is deliberately excluded to test the exclusion mechanism. + + + diff --git a/cpp/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.yml b/cpp/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.yml new file mode 100644 index 0000000000..d4ea695e26 --- /dev/null +++ b/cpp/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.yml @@ -0,0 +1,3 @@ +deviations: + - rule-id: cpp-test-dummy + justification: This header is deliberately excluded to test the exclusion mechanism. diff --git a/cpp/common/test/rules/includeguardsnotused/headers/excluded/test7.hpp b/cpp/common/test/rules/includeguardsnotused/headers/excluded/test7.hpp new file mode 100644 index 0000000000..9d07b4b188 --- /dev/null +++ b/cpp/common/test/rules/includeguardsnotused/headers/excluded/test7.hpp @@ -0,0 +1,2 @@ +// COMPLIANT - excluded via deviation +int g7; diff --git a/cpp/common/test/rules/includeguardsnotused/headers/test7.hpp b/cpp/common/test/rules/includeguardsnotused/headers/test7.hpp new file mode 100644 index 0000000000..fc82ac2a01 --- /dev/null +++ b/cpp/common/test/rules/includeguardsnotused/headers/test7.hpp @@ -0,0 +1,2 @@ +// NON_COMPLIANT +int g6; diff --git a/cpp/common/test/rules/includeguardsnotused/test.cpp b/cpp/common/test/rules/includeguardsnotused/test.cpp index 356710eb5f..82170197f2 100644 --- a/cpp/common/test/rules/includeguardsnotused/test.cpp +++ b/cpp/common/test/rules/includeguardsnotused/test.cpp @@ -9,4 +9,8 @@ #include "headers/test5.hpp" //COMPLIANT - non unique precedes malformed -#include "headers/test6.hpp" //COMPLIANT - non unique \ No newline at end of file +#include "headers/test6.hpp" //COMPLIANT - non unique + +#include "headers/test7.hpp" //NON_COMPLIANT - missing include guard, not excluded + +#include "headers/excluded/test7.hpp" // COMPLIANT - excluded via deviation \ No newline at end of file