@@ -29,15 +29,50 @@ private import codeql.util.Location
2929 *
3030 * A query should either perform no alert filtering, or adhere to all the filtering rules in this
3131 * 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.
3235 */
3336extensible predicate restrictAlertsTo ( string filePath , int startLineStart , int startLineEnd ) ;
3437
38+ /**
39+ * Restricts alerts to specific locations in specific files.
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+
3570/** Module for applying alert location filtering. */
3671module AlertFilteringImpl< LocationSig Location> {
3772 /** Applies alert filtering to the given location. */
3873 bindingset [ location]
3974 predicate filterByLocation ( Location location ) {
40- not restrictAlertsTo ( _, _, _)
75+ not restrictAlertsTo ( _, _, _) and not restrictAlertsToExactLocation ( _ , _ , _ , _ , _ )
4176 or
4277 exists ( string filePath , int startLineStart , int startLineEnd |
4378 restrictAlertsTo ( filePath , startLineStart , startLineEnd )
@@ -48,5 +83,11 @@ module AlertFilteringImpl<LocationSig Location> {
4883 or
4984 location .hasLocationInfo ( filePath , [ startLineStart .. startLineEnd ] , _, _, _)
5085 )
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+ )
5192 }
5293}
0 commit comments