Skip to content

Commit 0d7a842

Browse files
committed
Shared: improve documentation in AlertFiltering
1 parent f1e9f0e commit 0d7a842

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

shared/util/codeql/util/AlertFiltering.qll

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,27 @@ module AlertFilteringImpl<LocationSig Location> {
7979
private predicate restrictAlertsToEntireFile(string filePath) { restrictAlertsTo(filePath, 0, 0) }
8080

8181
pragma[nomagic]
82-
private predicate restrictAlertsToStartLine(string filePath, int line) {
82+
private predicate restrictAlertsToLine(string filePath, int line) {
8383
exists(int startLineStart, int startLineEnd |
8484
restrictAlertsTo(filePath, startLineStart, startLineEnd) and
8585
line = [startLineStart .. startLineEnd]
8686
)
8787
}
8888

89-
/** Applies alert filtering to the given location. */
89+
/**
90+
* Holds if the given location intersects the diff range. Testing for full
91+
* intersection rather than only matching the start line means that this
92+
* predicate is more broadly useful than just checking whether a specific
93+
* element is considered to be in the diff range of GitHub Code Scanning:
94+
* - If it's inconvenient to pass the exact `Location` of the element of
95+
* interest, it's valid to use a `Location` of an enclosing element.
96+
* - This predicate could be useful for other systems of alert presentation
97+
* where the rules don't exactly match GitHub Code Scanning.
98+
*
99+
* If there is no diff range, this predicate holds for all locations. Note
100+
* that this predicate has a bindingset and will therefore be inlined;
101+
* callers should include enough context to ensure efficient evaluation.
102+
*/
90103
bindingset[location]
91104
predicate filterByLocation(Location location) {
92105
not restrictAlertsTo(_, _, _) and not restrictAlertsToExactLocation(_, _, _, _, _)
@@ -98,7 +111,7 @@ module AlertFilteringImpl<LocationSig Location> {
98111
exists(int locStartLine, int locEndLine |
99112
location.hasLocationInfo(filePath, locStartLine, _, locEndLine, _)
100113
|
101-
restrictAlertsToStartLine(pragma[only_bind_into](filePath), [locStartLine .. locEndLine])
114+
restrictAlertsToLine(pragma[only_bind_into](filePath), [locStartLine .. locEndLine])
102115
)
103116
)
104117
or

0 commit comments

Comments
 (0)