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

Invalid replace when output pattern has missing curly #581

Closed tennox closed 1 day ago

tennox commented 3 days ago

I found weird behaviour when I was missing a closing curly in my output pattern:

`const navigate = useNavigate()` 
=> `const {locnav, location, navigate = useLocationNavigate()`

It didn't fail but weirdly removes a completely unrelated statement's const prefix: https://app.grit.io/studio?key=ndJC5UF8gvqYnDDY0urXP

I can see if that's a too weird edge-case and I should just fix my code, but I wanted to let you know in case you want to refine your UX :thinking:

morgante commented 1 day ago

Thanks for the report. We have some matching heuristics around rewrites that this is capturing, but those heuristics are only really designed to work with well-structured rewrites.