6
6
private import codeql.util.Location
7
7
8
8
/**
9
- * Restricts alerts to a specific location in specific files .
9
+ * Holds if the query should produce alerts that match the given line ranges .
10
10
*
11
- * If this predicate is empty, accept all alerts. Otherwise, accept alerts only at the specified
12
- * locations. Note that alert restrictions apply only to the start line of an alert (even if the
13
- * alert location spans multiple lines) because alerts are displayed on their start lines.
11
+ * This predicate is active if and only if it is nonempty. If this predicate is inactive, it has no
12
+ * effect. If it is active, it accepts any alert that has at least one matching location.
14
13
*
15
- * - filePath: Absolute path of the file to restrict alerts to.
16
- * - startLine: Start line number (starting with 1, inclusive) to restrict alerts to.
17
- * - endLine: End line number (starting with 1, inclusive) to restrict alerts to.
14
+ * Note that an alert that is not accepted by this filtering predicate may still be included in the
15
+ * query results if it is accepted by another active filtering predicate in this module. An alert is
16
+ * excluded from the query results if only if (1) there is at least one active filtering predicate,
17
+ * and (2) it is not accepted by any active filtering predicate.
18
18
*
19
- * If startLine and endLine are both 0, accept alerts anywhere in the file.
19
+ * An alert location is a match if it matches a row in this predicate. If `startLineStart` and
20
+ * `startLineEnd` are both 0, the row specifies a whole-file match, and a location is a match if
21
+ * its file path matches `filePath`. Otherwise, the row specifies a line-range match, and a
22
+ * location is a match if its file path matches `filePath`, and its start line is between
23
+ * `startLineStart` and `startLineEnd`, inclusive. (Note that only start line of the location is
24
+ * used for matching because an alert is displayed on the first line of its location.)
20
25
*
21
- * A query should either completely ignore this predicate (i.e., perform no filtering whatsoever),
22
- * or only return alerts that meet the filtering criteria as specified above.
26
+ * - filePath: alert location file path (absolute).
27
+ * - startLineStart: inclusive start of the range for alert location start line number (1-based).
28
+ * - startLineEnd: inclusive end of the range for alert location start line number (1-based).
29
+ *
30
+ * A query should either perform no alert filtering, or adhere to all the filtering rules in this
31
+ * module and return all and only the accepted alerts.
23
32
*/
24
- extensible predicate restrictAlertsTo ( string filePath , int startLine , int endLine ) ;
33
+ extensible predicate restrictAlertsTo ( string filePath , int startLineStart , int startLineEnd ) ;
25
34
26
35
/** Module for applying alert location filtering. */
27
36
module AlertFilteringImpl< LocationSig Location> {
@@ -30,14 +39,14 @@ module AlertFilteringImpl<LocationSig Location> {
30
39
predicate filterByLocation ( Location location ) {
31
40
not restrictAlertsTo ( _, _, _)
32
41
or
33
- exists ( string filePath , int startLine , int endLine |
34
- restrictAlertsTo ( filePath , startLine , endLine )
42
+ exists ( string filePath , int startLineStart , int startLineEnd |
43
+ restrictAlertsTo ( filePath , startLineStart , startLineEnd )
35
44
|
36
- startLine = 0 and
37
- endLine = 0 and
45
+ startLineStart = 0 and
46
+ startLineEnd = 0 and
38
47
location .hasLocationInfo ( filePath , _, _, _, _)
39
48
or
40
- location .hasLocationInfo ( filePath , [ startLine .. endLine ] , _, _, _)
49
+ location .hasLocationInfo ( filePath , [ startLineStart .. startLineEnd ] , _, _, _)
41
50
)
42
51
}
43
52
}
0 commit comments