GritQL and the Grit CLI search, lint, and rewrite source with pattern queries. Code snippets in backticks act as queries across many languages.
Overview
GritQL is a declarative query language for searching and modifying source code. The Grit CLI applies patterns locally or from configuration files such as grit.yaml, and grit check can enforce saved patterns as custom lints.
Queries can start as literal code snippets with metavariable holes, then grow with where clauses for side conditions. Rewrites use arrow syntax to replace matched code, and patterns can be combined for larger refactors. The engine uses tree-sitter parsers and is written in Rust for performance on very large repositories.
Target languages named in the documentation include JavaScript and TypeScript, Python, JSON, Java, Terraform, Solidity, CSS, Markdown, YAML, Rust, Go, and SQL. A standard pattern library and module sharing are available, plus VS Code integration and CI usage guides.
Typical uses described include large migrations, custom lint rules, dependency upgrade codemods, and systematic code quality fixes with optional auto-fix behavior.
Key features
- Backtick code snippet queries
- Pattern rewrite with arrow syntax
- Where clauses for extra conditions
- grit check custom lint enforcement
- Multi-language tree-sitter parsing
- Rust engine for large repos
- Standard pattern library
- CLI apply and check commands
Use cases
- Large-scale API migrations
- Enforcing team lint patterns
- Removing or replacing code idioms
- Dependency upgrade codemods
- Exploratory code search in repos