getgrit / gritql

GritQL is a query language for searching, linting, and modifying code.
https://docs.grit.io/
MIT License
3.17k stars 82 forks source link

Document comment patterns #571

Open joelburget opened 2 weeks ago

joelburget commented 2 weeks ago

The docs don't cover matching comments. It seems like there is support and I was able to reverse-engineer a bit of it, but wasn't able to figure out how to match comments with a specific format (e.g. TODO\((.*)\) where the capture group is a bug identifier).

joelburget commented 2 weeks ago

`/* TODO$_ */` finds different locations from `// TODO$_` -- both only match that specific type of comment 👎🏻

joelburget commented 2 weeks ago

While we're here I also tried the AST node example from the docs but wasn't able to make it work

Screenshot 2024-11-03 at 7 41 24 AM Screenshot 2024-11-03 at 7 41 40 AM Screenshot 2024-11-03 at 7 42 16 AM
morgante commented 2 weeks ago

By default, Grit treats block comments as different from line comments - since sometimes you want to transform one into the other. We can consider adding an equivalence class, but if you use the AST node it works well.

This should do what you want:

engine marzano(0.1)
language js

string(fragment="str")

I'm unable to replicate your concern with AST nodes:

image