You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
♻️ Once you learn GritQL, you can use it to rewrite any target language: JavaScript/TypeScript, Python, JSON, Java, Terraform, Solidity, CSS, Markdown, YAML, Rust, Go, or SQL
đź”§ GritQL makes it easy to include auto-fix rules for faster remediation
Patterns can be combined to create complex queries, including large refactors.
Why GritQL?
GritQL comes from our experiences with conducting large scale refactors and migrations.
Usually, migrations start with exploratory work to figure out the scope of the problem—often using simple grep searches. These are easy to start with, but most migrations end up accumulating additional requirements like ensuring the right packages are imported and excluding cases which don’t have a viable migration path.
Eventually, any complex migration ends up being a full codemod program written with a tool like jscodeshift. This comes with its own problems:
Most of the exploratory work has to be abandoned as you figure out how to represent your original regex search as an AST.
Reading/writing a codemod requires mentally translating from AST names back to what source code actually looks like.
Most frameworks are not composable, so you’re stuck copying patterns back and forth.
Performance is often an afterthought, so iterating on a large codemod can be painfully slow.
Codemod frameworks are language-specific, so if you’re hopping between multiple languages—or trying to migrate a shared API—you have to learn different frameworks.
GritQL is our attempt to develop a powerful middle ground:
Exploratory analysis is easy: just put a code snippet in backticks and use $metavariables for holes you want to represent.
Incrementally add complexity by introducing side conditions with where clauses.
Reuse named patterns to avoid rebuilding queries, and use shared patterns from our standard library for common tasks like ensuring modules are imported.
Written in Rust for maximum performance: rewrite millions of lines of code in seconds.
Acknowledgements
GritQL uses tree-sitter for all language parsers and benefits greatly from the Rust ecosystem.