Skip to content

Commit c33952e

Browse files
committed
Add isExcluded/3 that includes the reason for exclusion
This is used for debugging and testing purposes and cannot be used in our standard queries due to the required negation and the possible infinite possible values for reason.
1 parent 9edb1da commit c33952e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Diff for: cpp/common/src/codingstandards/cpp/Exclusions.qll

+12-6
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ predicate isExcluded(Element e) {
2525
}
2626

2727
bindingset[e, query]
28-
predicate isExcluded(Element e, Query query) {
29-
e instanceof ExcludedElement
28+
predicate isExcluded(Element e, Query query) { isExcluded(e, query, _) }
29+
30+
bindingset[e, query]
31+
predicate isExcluded(Element e, Query query, string reason) {
32+
e instanceof ExcludedElement and reason = "Element is an excluded element."
3033
or
31-
e.getFile() instanceof ExcludedFile
34+
e.getFile() instanceof ExcludedFile and reason = "Element is part of an excluded file."
3235
or
33-
not exists(e.getFile())
36+
not exists(e.getFile()) and reason = "Element is not part of the source repository."
3437
or
3538
// There exists a `DeviationRecord` that applies to this element and query, and the query's effective category permits deviation.
3639
query.getEffectiveCategory().permitsDeviation() and
@@ -39,7 +42,8 @@ predicate isExcluded(Element e, Query query) {
3942
exists(string path |
4043
dr.isDeviated(query, path) and
4144
e.getFile().getRelativePath().prefix(path.length()) = path
42-
)
45+
) and
46+
reason = "Query has an associated deviation record for the element's file."
4347
or
4448
// The element is on the same line as a suppression comment
4549
exists(Comment c |
@@ -51,6 +55,8 @@ predicate isExcluded(Element e, Query query) {
5155
e.getLocation().hasLocationInfo(filepath, _, _, endLine, _) and
5256
c.getLocation().hasLocationInfo(filepath, endLine, _, _, _)
5357
)
54-
)
58+
) and
59+
reason =
60+
"Query has an associated deviation record with a code identifier that is applied to the element."
5561
)
5662
}

0 commit comments

Comments
 (0)