From 30c4dfe4de69ea0f765dcdfbe80b51bcfc4a0d82 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Fri, 4 Sep 2026 19:40:44 +0200 Subject: [PATCH 1/4] Add exclusion check for header files in problems predicate --- .../cpp/rules/includeguardsnotused/IncludeGuardsNotUsed.qll | 1 + 1 file changed, 1 insertion(+) 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 From 448012044e4bdc03d89b623f913043b7526f71d6 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 4 Sep 2026 20:56:34 +0200 Subject: [PATCH 2/4] Add passing and failing tests for IncludeGuardsNotUsed exclusion check feedback (#1195) * Add passing/failing tests for IncludeGuardsNotUsed exclusion behavior --- .../includeguardsnotused/IncludeGuardsNotUsed.expected | 1 + .../headers/excluded/coding-standards.xml | 10 ++++++++++ .../headers/excluded/coding-standards.yml | 3 +++ .../includeguardsnotused/headers/excluded/test8.h | 2 ++ .../test/rules/includeguardsnotused/headers/test8.h | 2 ++ c/common/test/rules/includeguardsnotused/test.c | 6 +++++- .../includeguardsnotused/IncludeGuardsNotUsed.expected | 1 + .../headers/excluded/coding-standards.xml | 10 ++++++++++ .../headers/excluded/coding-standards.yml | 3 +++ .../includeguardsnotused/headers/excluded/test7.hpp | 2 ++ .../test/rules/includeguardsnotused/headers/test7.hpp | 2 ++ cpp/common/test/rules/includeguardsnotused/test.cpp | 6 +++++- 12 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 c/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.xml create mode 100644 c/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.yml create mode 100644 c/common/test/rules/includeguardsnotused/headers/excluded/test8.h create mode 100644 c/common/test/rules/includeguardsnotused/headers/test8.h create mode 100644 cpp/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.xml create mode 100644 cpp/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.yml create mode 100644 cpp/common/test/rules/includeguardsnotused/headers/excluded/test7.hpp create mode 100644 cpp/common/test/rules/includeguardsnotused/headers/test7.hpp diff --git a/c/common/test/rules/includeguardsnotused/IncludeGuardsNotUsed.expected b/c/common/test/rules/includeguardsnotused/IncludeGuardsNotUsed.expected index 8d72392ed5..07d19e7cf3 100644 --- a/c/common/test/rules/includeguardsnotused/IncludeGuardsNotUsed.expected +++ b/c/common/test/rules/includeguardsnotused/IncludeGuardsNotUsed.expected @@ -2,3 +2,4 @@ | headers/test4.h:0:0:0:0 | headers/test4.h | Header file test4.h is missing expected include guard. | headers/test4.h:0:0:0:0 | headers/test4.h | | | headers/test5.h:0:0:0:0 | headers/test5.h | Header file test5.h is missing expected include guard. | headers/test5.h:0:0:0:0 | headers/test5.h | | | headers/test7.h:0:0:0:0 | headers/test7.h | Header file test7.h is never included by reusing the include guard used by $@. | headers/test6.h:0:0:0:0 | headers/test6.h | include guard | +| headers/test8.h:0:0:0:0 | headers/test8.h | Header file test8.h is missing expected include guard. | headers/test8.h:0:0:0:0 | headers/test8.h | | diff --git a/c/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.xml b/c/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.xml new file mode 100644 index 0000000000..adf7df0ce6 --- /dev/null +++ b/c/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/c/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.yml b/c/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.yml new file mode 100644 index 0000000000..d4ea695e26 --- /dev/null +++ b/c/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/c/common/test/rules/includeguardsnotused/headers/excluded/test8.h b/c/common/test/rules/includeguardsnotused/headers/excluded/test8.h new file mode 100644 index 0000000000..9d07b4b188 --- /dev/null +++ b/c/common/test/rules/includeguardsnotused/headers/excluded/test8.h @@ -0,0 +1,2 @@ +// COMPLIANT - excluded via deviation +int g7; diff --git a/c/common/test/rules/includeguardsnotused/headers/test8.h b/c/common/test/rules/includeguardsnotused/headers/test8.h new file mode 100644 index 0000000000..fc82ac2a01 --- /dev/null +++ b/c/common/test/rules/includeguardsnotused/headers/test8.h @@ -0,0 +1,2 @@ +// NON_COMPLIANT +int g6; diff --git a/c/common/test/rules/includeguardsnotused/test.c b/c/common/test/rules/includeguardsnotused/test.c index 8c63904fc4..15b066be14 100644 --- a/c/common/test/rules/includeguardsnotused/test.c +++ b/c/common/test/rules/includeguardsnotused/test.c @@ -11,4 +11,8 @@ #include "headers/test6.h" //NON_COMPLIANT - non unique and reported in alert for the next -#include "headers/test7.h" //NON_COMPLIANT - non unique \ No newline at end of file +#include "headers/test7.h" //NON_COMPLIANT - non unique + +#include "headers/test8.h" //NON_COMPLIANT - missing include guard, not excluded + +#include "headers/excluded/test8.h" //COMPLIANT - missing include guard, but excluded via deviation \ No newline at end of file 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 From 951616a782c3eaf4f90c517e2bdbd1b9b4b8ef40 Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Fri, 4 Sep 2026 21:00:38 +0200 Subject: [PATCH 3/4] remove one duplicate test --- .../includeguardsnotused/IncludeGuardsNotUsed.expected | 1 - .../headers/excluded/coding-standards.xml | 10 ---------- .../headers/excluded/coding-standards.yml | 3 --- .../includeguardsnotused/headers/excluded/test8.h | 2 -- .../test/rules/includeguardsnotused/headers/test8.h | 2 -- c/common/test/rules/includeguardsnotused/test.c | 6 +----- 6 files changed, 1 insertion(+), 23 deletions(-) delete mode 100644 c/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.xml delete mode 100644 c/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.yml delete mode 100644 c/common/test/rules/includeguardsnotused/headers/excluded/test8.h delete mode 100644 c/common/test/rules/includeguardsnotused/headers/test8.h diff --git a/c/common/test/rules/includeguardsnotused/IncludeGuardsNotUsed.expected b/c/common/test/rules/includeguardsnotused/IncludeGuardsNotUsed.expected index 07d19e7cf3..8d72392ed5 100644 --- a/c/common/test/rules/includeguardsnotused/IncludeGuardsNotUsed.expected +++ b/c/common/test/rules/includeguardsnotused/IncludeGuardsNotUsed.expected @@ -2,4 +2,3 @@ | headers/test4.h:0:0:0:0 | headers/test4.h | Header file test4.h is missing expected include guard. | headers/test4.h:0:0:0:0 | headers/test4.h | | | headers/test5.h:0:0:0:0 | headers/test5.h | Header file test5.h is missing expected include guard. | headers/test5.h:0:0:0:0 | headers/test5.h | | | headers/test7.h:0:0:0:0 | headers/test7.h | Header file test7.h is never included by reusing the include guard used by $@. | headers/test6.h:0:0:0:0 | headers/test6.h | include guard | -| headers/test8.h:0:0:0:0 | headers/test8.h | Header file test8.h is missing expected include guard. | headers/test8.h:0:0:0:0 | headers/test8.h | | diff --git a/c/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.xml b/c/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.xml deleted file mode 100644 index adf7df0ce6..0000000000 --- a/c/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - cpp-test-dummy - This header is deliberately excluded to test the exclusion mechanism. - - - diff --git a/c/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.yml b/c/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.yml deleted file mode 100644 index d4ea695e26..0000000000 --- a/c/common/test/rules/includeguardsnotused/headers/excluded/coding-standards.yml +++ /dev/null @@ -1,3 +0,0 @@ -deviations: - - rule-id: cpp-test-dummy - justification: This header is deliberately excluded to test the exclusion mechanism. diff --git a/c/common/test/rules/includeguardsnotused/headers/excluded/test8.h b/c/common/test/rules/includeguardsnotused/headers/excluded/test8.h deleted file mode 100644 index 9d07b4b188..0000000000 --- a/c/common/test/rules/includeguardsnotused/headers/excluded/test8.h +++ /dev/null @@ -1,2 +0,0 @@ -// COMPLIANT - excluded via deviation -int g7; diff --git a/c/common/test/rules/includeguardsnotused/headers/test8.h b/c/common/test/rules/includeguardsnotused/headers/test8.h deleted file mode 100644 index fc82ac2a01..0000000000 --- a/c/common/test/rules/includeguardsnotused/headers/test8.h +++ /dev/null @@ -1,2 +0,0 @@ -// NON_COMPLIANT -int g6; diff --git a/c/common/test/rules/includeguardsnotused/test.c b/c/common/test/rules/includeguardsnotused/test.c index 15b066be14..8c63904fc4 100644 --- a/c/common/test/rules/includeguardsnotused/test.c +++ b/c/common/test/rules/includeguardsnotused/test.c @@ -11,8 +11,4 @@ #include "headers/test6.h" //NON_COMPLIANT - non unique and reported in alert for the next -#include "headers/test7.h" //NON_COMPLIANT - non unique - -#include "headers/test8.h" //NON_COMPLIANT - missing include guard, not excluded - -#include "headers/excluded/test8.h" //COMPLIANT - missing include guard, but excluded via deviation \ No newline at end of file +#include "headers/test7.h" //NON_COMPLIANT - non unique \ No newline at end of file From 95642e97fcc632e10da9df3c53d2067c7ffa579c Mon Sep 17 00:00:00 2001 From: Mauro Baluda Date: Fri, 4 Sep 2026 23:44:10 +0200 Subject: [PATCH 4/4] Add change note --- .../2026-09-04-add-exclusion-check-for-include-guards.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 change_notes/2026-09-04-add-exclusion-check-for-include-guards.md 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