@@ -29,15 +29,50 @@ private import codeql.util.Location
29
29
*
30
30
* A query should either perform no alert filtering, or adhere to all the filtering rules in this
31
31
* module and return all and only the accepted alerts.
32
+ *
33
+ * This predicate is suitable for situations where we want to filter alerts at line granularity,
34
+ * such as based on the pull request diff.
32
35
*/
33
36
extensible predicate restrictAlertsTo ( string filePath , int startLineStart , int startLineEnd ) ;
34
37
38
+ /**
39
+ * Holds if the query should produce alerts that match the given locations.
40
+ *
41
+ * This predicate is active if and only if it is nonempty. If this predicate is inactive, it has no
42
+ * effect. If it is active, it accepts any alert that has at least one matching location.
43
+ *
44
+ * Note that an alert that is not accepted by this filtering predicate may still be included in the
45
+ * query results if it is accepted by another active filtering predicate in this module. An alert is
46
+ * excluded from the query results if only if (1) there is at least one active filtering predicate,
47
+ * and (2) it is not accepted by any active filtering predicate.
48
+ *
49
+ * An alert location is a match if it matches a row in this predicate. Each row specifies an exact
50
+ * location: an alert location is a match if its file path matches `filePath`, its start line and
51
+ * column match `startLine` and `startColumn`, and its end line and column match `endLine` and
52
+ * `endColumn`.
53
+ *
54
+ * - filePath: alert location file path (absolute).
55
+ * - startLine: alert location start line number (1-based).
56
+ * - startColumn: alert location start column number (1-based).
57
+ * - endLine: alert location end line number (1-based).
58
+ * - endColumn: alert location end column number (1-based).
59
+ *
60
+ * A query should either perform no alert filtering, or adhere to all the filtering rules in this
61
+ * module and return all and only the accepted alerts.
62
+ *
63
+ * This predicate is suitable for situations where we want to filter by the exact alert location,
64
+ * distinguishing between alerts on the same line.
65
+ */
66
+ extensible predicate restrictAlertsToExactLocation (
67
+ string filePath , int startLine , int startColumn , int endLine , int endColumn
68
+ ) ;
69
+
35
70
/** Module for applying alert location filtering. */
36
71
module AlertFilteringImpl< LocationSig Location> {
37
72
/** Applies alert filtering to the given location. */
38
73
bindingset [ location]
39
74
predicate filterByLocation ( Location location ) {
40
- not restrictAlertsTo ( _, _, _)
75
+ not restrictAlertsTo ( _, _, _) and not restrictAlertsToExactLocation ( _ , _ , _ , _ , _ )
41
76
or
42
77
exists ( string filePath , int startLineStart , int startLineEnd |
43
78
restrictAlertsTo ( filePath , startLineStart , startLineEnd )
@@ -48,5 +83,11 @@ module AlertFilteringImpl<LocationSig Location> {
48
83
or
49
84
location .hasLocationInfo ( filePath , [ startLineStart .. startLineEnd ] , _, _, _)
50
85
)
86
+ or
87
+ exists ( string filePath , int startLine , int startColumn , int endLine , int endColumn |
88
+ restrictAlertsToExactLocation ( filePath , startLine , startColumn , endLine , endColumn )
89
+ |
90
+ location .hasLocationInfo ( filePath , startLine , startColumn , endLine , endColumn )
91
+ )
51
92
}
52
93
}
0 commit comments