feat: github-env: use tree-sitter queries#354
Conversation
Signed-off-by: William Woodruff <william@yossarian.net>
| Ok(Self { | ||
| bash_parser: RefCell::new(bash_parser), | ||
| pwsh_parser: RefCell::new(pwsh_parser), | ||
| bash_redirect_query_span_idx: bash_redirect_query |
There was a problem hiding this comment.
NB: I cache these capture indices at the struct level because they vary between individual queries, and because extracting them is technically fallible (although infallible in practice, as long as there's no typo). But it's definitely a bit of an eyesore.
|
NB tree-sitter/tree-sitter#4034 -- that'll allow us to remove the |
Signed-off-by: William Woodruff <william@yossarian.net>
|
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
ubiratansoares
left a comment
There was a problem hiding this comment.
Hey @woodruffw! Thanks for tagging me for input!
I was not aware of TS query capabilities, always learning I guess 😄
Imho, this approach looks amazing. I'm sold tbh, regardless the downsides!
I do agree that TS queries might be not as intituitive to augment or troubleshoot compared to walking nodes directly, but they look like a solid take for tackling more false positives we may have in the future.
Perf-wise, I think we should not bother that much for now, afterall zizmor is already pretty fast elsewhere.
Since tree-sitter/tree-sitter#4034 was already merged, perhaps you want to wait until the next tree-sitter release to merge this. Otherwise, LGTM 🚀
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
Signed-off-by: William Woodruff <william@yossarian.net>
Very WIP.This experimentally replaces the stack-of-nodes approach with hand-written TS queries, which can be more precise about matches and their sub-captures (e.g. allowing us to match only when the RHS is actually a variable expansion).
It also adds some examples of false positives that the previous approach flagged. These FPs aren't likely to occur in the wild, however, so the direct benefit for actual users is pretty small.
The larger impact here is indirect:
At the same time, there are some downsides to this approach:
CC @ubiratansoares for thoughts on this approach -- I think it makes things somewhat easier/more general overall, but it has downsides. I'm curious what you think about these tradeoffs 🙂
(I also still need to do the same for the PowerShell codepath.)