Skip to content

Commit e7d90ba

Browse files
Merge pull request #1194 from github/mbaluda/exp37-c
Fix: Adds exclusion check in IncludeGuardsNotUsed
2 parents 81c8723 + 95642e9 commit e7d90ba

8 files changed

Lines changed: 26 additions & 1 deletion

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `DIR-4-10`, `M16-2-3`, and `RULE-19-2-1`:
2+
- Header files matched by a configured exclusion are no longer reported.

cpp/common/src/codingstandards/cpp/rules/includeguardsnotused/IncludeGuardsNotUsed.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class BlockedIncludeGuard extends HeaderFile {
2424
}
2525

2626
query predicate problems(HeaderFile file, string message, HeaderFile other, string name) {
27+
not isExcluded(file, getQuery()) and
2728
not file instanceof CorrectIncludeGuard and
2829
if file instanceof BlockedIncludeGuard
2930
then

cpp/common/test/rules/includeguardsnotused/IncludeGuardsNotUsed.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
| 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 | |
33
| 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 | |
44
| 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 | |
5+
| 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 | |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" ?>
2+
<codingstandards>
3+
<!--GENERATED: DO NOT MODIFY. Changes should be made to coding-standards.yml instead.-->
4+
<deviations>
5+
<deviations-entry>
6+
<rule-id>cpp-test-dummy</rule-id>
7+
<justification>This header is deliberately excluded to test the exclusion mechanism.</justification>
8+
</deviations-entry>
9+
</deviations>
10+
</codingstandards>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
deviations:
2+
- rule-id: cpp-test-dummy
3+
justification: This header is deliberately excluded to test the exclusion mechanism.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// COMPLIANT - excluded via deviation
2+
int g7;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// NON_COMPLIANT
2+
int g6;

cpp/common/test/rules/includeguardsnotused/test.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@
99

1010
#include "headers/test5.hpp" //COMPLIANT - non unique precedes malformed
1111

12-
#include "headers/test6.hpp" //COMPLIANT - non unique
12+
#include "headers/test6.hpp" //COMPLIANT - non unique
13+
14+
#include "headers/test7.hpp" //NON_COMPLIANT - missing include guard, not excluded
15+
16+
#include "headers/excluded/test7.hpp" // COMPLIANT - excluded via deviation

0 commit comments

Comments
 (0)