Conversation
Co-authored-by: MichaelRFairhurst <1627771+MichaelRFairhurst@users.noreply.github.com> Agent-Logs-Url: https://github.com/advanced-security/codeql-qtil/sessions/2e31ff0c-05bb-412a-9027-d6546a1fff77
MichaelRFairhurst
left a comment
There was a problem hiding this comment.
Add a description as well to README.md, and delete .gitignore
src/qtil/list/PlaceholderList.qll
Outdated
| * The maximum number of placeholders to show per alert. When there are more placeholders than | ||
| * this limit, the message will include "and N more" as plain text. | ||
| * | ||
| * The effective maximum is capped at 3, which is the number of placeholder pairs in the output |
There was a problem hiding this comment.
Increase the maximum to 5
There was a problem hiding this comment.
Done in cf18211 — default and cap are now 5; the output query predicate problems now has 5 placeholder pairs.
| * Count the number of distinct placeholder values for a given `(element, message)` pair. | ||
| */ | ||
| private int countPlaceholders(Element e, string msg) { | ||
| Config::problems(e, msg, _, _) and |
There was a problem hiding this comment.
this line is unnecessary
There was a problem hiding this comment.
Removed from getNthPlaceholder (cf18211). Note: the equivalent line in countPlaceholders must stay — count aggregation doesn't provide binding for the outer string msg variable, unlike rank[n].
src/qtil/list/PlaceholderList.qll
Outdated
| * ascending by `Config::orderBy`, with the placeholder's `toString()` as a secondary sort key. | ||
| */ | ||
| private Placeholder getNthPlaceholder(Element e, string msg, int n) { | ||
| Config::problems(e, msg, _, _) and |
There was a problem hiding this comment.
this line is unnecessary
src/qtil/list/PlaceholderList.qll
Outdated
| * number of additional placeholders not shown (0 or more). | ||
| */ | ||
| bindingset[showCount, moreCount] | ||
| private string expansion(int showCount, int moreCount) { |
There was a problem hiding this comment.
split this into placeholderExpansion (returning $@, $@ and $@, ...) and moreString (returning "" or " and n more".
expansion() can return placeholderExpansion(...) + moreString(...)
There was a problem hiding this comment.
Done in cf18211 — split into placeholderExpansion(n), moreString(moreCount), and expansion(showCount, moreCount) = placeholderExpansion + moreString.
| */ | ||
| private string expandedMsg(Element e, string origMsg) { | ||
| exists(int total, int maxR, int cappedMax, int sc, int mc | | ||
| total = countPlaceholders(e, origMsg) and |
There was a problem hiding this comment.
reuse showCount here
There was a problem hiding this comment.
Done in cf18211 — expandedMsg now calls showCount(e, origMsg) directly and uses it to compute mc.
| @@ -0,0 +1,158 @@ | |||
| import qtil.list.PlaceholderList | |||
| import qtil.testing.Qnit | |||
There was a problem hiding this comment.
Instead of a qnit test, have this be a basic query test.
You can have multiple test queries by defining different query predicates, e.g.
query predicate testMaxTwo = PlaceholderList<...>::problems/4;
And then the resulting set of query predicates will output the expected:
testMaxTwo
| my element has $@ | foo | "" | "" |
| my other element has $@ and $@ | foo | bar | "" |
| my last element has $@, $@, and 1 more | foo | bar | baz
testMaxThree
| my element has $@ | foo | "" | "" |
....
There was a problem hiding this comment.
Done in cf18211 — replaced the Qnit-based test with two query predicate aliases (testDefault and testMaxTwo) and a matching .expected file showing the actual output rows.
…ests, README, remove .gitignore Co-authored-by: MichaelRFairhurst <1627771+MichaelRFairhurst@users.noreply.github.com> Agent-Logs-Url: https://github.com/advanced-security/codeql-qtil/sessions/a14c8c20-be9c-4b06-b4af-53039bacd071
Done in cf18211 — added a |
Adds a generic
PlaceholderListmodule for queries where a single alert element relates to a variable number of placeholder elements — collapsing N input rows per element into one alert row with a formatted list message.New:
src/qtil/list/PlaceholderList.qllPlaceholderListSig<Element, Placeholder>— config signature:predicate problems(Element e, string msg, Placeholder p, string pStr)— one row per placeholderdefault int maxResults()— visible placeholder cap (default 5)default string orderBy(Placeholder p)— sort key (defaultp.toString())PlaceholderList<Element, Placeholder, Config>— produces a fixed-arityquery predicate problems(...)with 5 placeholder pairs. Expands the single$@in the input message:$@$@ and $@$@, $@, and $@$@, $@, $@, and $@$@, $@, $@, $@, and $@$@, $@, $@, $@, and $@ and N moreUnused placeholder slots are padded with the first placeholder and
"".Example usage
Updated:
src/qtil/Qtil.qllAdded
import qtil.list.PlaceholderListto the main module.Updated:
README.mdAdded a
PlaceholderListdescription under the Lists section.⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.