Skip to content

Commit b9b9394

Browse files
committed
AlertFiltering: allow multiple filtering predicates
This commit rephrases the documentation for the restrictAlertsTo predicate and renames the predicate columns for clarity. The new documentation should be equivalent to the old documentation, except allowing for the possibility that there may be multiple alert filtering predicates.
1 parent 253ccd1 commit b9b9394

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

shared/util/codeql/util/AlertFiltering.qll

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,31 @@
66
private import codeql.util.Location
77

88
/**
9-
* Restricts alerts to a specific location in specific files.
9+
* Holds if the query should produce alerts that match the given line ranges.
1010
*
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.
1413
*
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.
1818
*
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.)
2025
*
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.
2332
*/
24-
extensible predicate restrictAlertsTo(string filePath, int startLine, int endLine);
33+
extensible predicate restrictAlertsTo(string filePath, int startLineStart, int startLineEnd);
2534

2635
/** Module for applying alert location filtering. */
2736
module AlertFilteringImpl<LocationSig Location> {
@@ -30,14 +39,14 @@ module AlertFilteringImpl<LocationSig Location> {
3039
predicate filterByLocation(Location location) {
3140
not restrictAlertsTo(_, _, _)
3241
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)
3544
|
36-
startLine = 0 and
37-
endLine = 0 and
45+
startLineStart = 0 and
46+
startLineEnd = 0 and
3847
location.hasLocationInfo(filePath, _, _, _, _)
3948
or
40-
location.hasLocationInfo(filePath, [startLine .. endLine], _, _, _)
49+
location.hasLocationInfo(filePath, [startLineStart .. startLineEnd], _, _, _)
4150
)
4251
}
4352
}

0 commit comments

Comments
 (0)