GritQL is a declarative query language for searching and modifying source code. GritQL focuses on a few areas:
- 📖 Start simply without learning AST details: any code snippet is a valid GritQL query
- ⚡️ Use Rust and query optimization to scale up to 10M+ line repositories
- 📦 Use Grit's built-in module system to reuse 200+ standard patterns or share your own
- ♻️ 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
Read the docs or try any query in the studio.
Read the documentation, interactive tutorial, or run grit --help
.
Install the Grit CLI:
curl -fsSL https://docs.grit.io/install | bash
Find all your console.log
calls:
grit apply '`console.log($_)`'
Replace console.log
with winston.log
:
grit apply '`console.log($msg)` => `winston.log($msg)`'
Save the pattern to a grit.yaml
file and exclude test cases:
cat << 'EOF' > .grit/grit.yaml
patterns:
- name: use_winston
level: error
body: |
`console.log($msg)` => `winston.log($msg)` where {
$msg <: not within or { `it($_, $_)`, `test($_, $_)`, `describe($_, $_)` }
}
EOF
grit apply use_winston
Run grit check
to enforce your patterns as custom lints.
grit check
GritQL uses tree-sitter for all language parsers and benefits greatly from the Rust ecosystem.
GritQL is released under the MIT license.
Contributions are welcome. To get started, check out the contributing guidelines.
You can also join us on Discord.