Conversation
Co-authored-by: MichaelRFairhurst <1627771+MichaelRFairhurst@users.noreply.github.com>
|
This code: should not be necessary. It should automatically declared by means of a query predicate Add default predicates for ease of use, such as the following: allowing for users to override Consider ordering by |
MichaelRFairhurst
left a comment
There was a problem hiding this comment.
See previous comment
…derString Co-authored-by: MichaelRFairhurst <1627771+MichaelRFairhurst@users.noreply.github.com>
... Done in ba7bd9d:
|
MichaelRFairhurst
left a comment
There was a problem hiding this comment.
Add documentation to README.md
src/qtil/results/LimitResults.qll
Outdated
| * | ||
| * bindingset[remaining] | ||
| * string message(MyFinding finding, MyEntity entity, string remaining) { | ||
| * result = "Finding $@ has entity $@" + remaining + "." |
There was a problem hiding this comment.
documentation error: should be "Finding " + finding.getName() + " has entity $@" + remaining + "."
There was a problem hiding this comment.
Fixed in d58a5a0 — the example now uses "Finding " + finding.getName() + " has entity $@" + remaining + ".".
src/qtil/results/LimitResults.qll
Outdated
| * The instantiated module exposes a `problems` query predicate that can be used directly as | ||
| * the output of a query without any `from`/`where`/`select` boilerplate: | ||
| * | ||
| * ```ql |
There was a problem hiding this comment.
Delete this code block, the above paragraph covers it already.
src/qtil/results/LimitResults.qll
Outdated
| string message(Finding finding, Entity entity, string remaining); | ||
|
|
||
| /** | ||
| * The display string for an entity, also used as the ordering key (ascending). |
There was a problem hiding this comment.
Make "also used as the ordering key (ascending)" the default behavior.
E.g., add a new default string orderBy(Entity e) { result = getPlaceholderString(e) }.
There was a problem hiding this comment.
Done in d58a5a0 — added default string orderBy(Entity entity) { result = placeholderString(entity) } to the signature. The ranking now uses Config::orderBy(e), keeping placeholderString as purely the display string. Users can override orderBy independently.
| * | ||
| * Defaults to `3`. | ||
| */ | ||
| default int maxResults() { result = 3 } |
There was a problem hiding this comment.
Add a default string andMoreText(int total) predicate
There was a problem hiding this comment.
Done in d58a5a0 — added bindingset[n] default string andMoreText(int n) { result = " (and " + n + " more)" } to the signature. The hasLimitedResult predicate now calls Config::andMoreText(total - Config::maxResults()) for the suffix.
| @@ -0,0 +1,146 @@ | |||
| import qtil.results.LimitResults | |||
| import qtil.testing.Qnit | |||
There was a problem hiding this comment.
In this case, we shouldn't use unit tests and should use a query test.
Simply import LimitResults and then expect
| BugA | "finding 1 for Bug A" | ....... |
| BugA | "finding 2 for Bug A" | .........
... etc
There was a problem hiding this comment.
Converted in d58a5a0. The test now just implements problem and message, instantiates the module, and re-exports Results::problems as a top-level query predicate. The .expected file contains the tabular rows directly.
.gitignore
Outdated
| @@ -0,0 +1 @@ | |||
| codeql_home/ | |||
There was a problem hiding this comment.
delete this .gitignore
… test, update docs
Added in d58a5a0 — |
Queries that report multiple related entities per finding (fields, parameters, call sites, etc.) have no standard way to cap result noise while communicating how many were omitted. This adds a reusable
LimitResultsmodule to handle that pattern.New module:
src/qtil/results/LimitResults.qllLimitResultsConfigSig<Finding, Entity>— signature to implement (both types must havetoString()):problem/2— finding-to-entity relationshipmessage/3— message template; receivesremaining(e.g." (and 2 more)"or"")default placeholderString/1— display string for an entity; defaults toentity.toString()default orderBy/1— ascending sort key for entities; defaults toplaceholderString(entity), allowing ordering to be overridden independently of the display stringdefault maxResults/0— cap per finding; defaults to3default andMoreText/1— customisable "and N more" suffix text; defaults to" (and N more)"LimitResults<Finding, Entity, Config>— exposes:query predicate problems(finding, msg, entity, entityStr): the primary query entry point; ranks entities per finding byorderBy(), reports the topmaxResults(), appendsandMoreText(n)when capped, and setsentityStrtoplaceholderString(entity)hasLimitedResult(finding, entity, message): underlying predicate for advanced useUsage
Only
problemandmessagemust be implemented — all other predicates have sensible defaults. Instantiating the module is all that's needed;Results::problemsis automatically part of the query output with nofrom/where/selectboilerplate:LimitResultsis exported viaQtil.qlland documented inREADME.md.⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.