在大规模迁移之前,使用结构化 GritQL 模式搜索并重写代码
Use GritQL when an agent needs reviewable structural search and rewrite passes across a large codebase before a migration, policy cleanup, or API change, instead of relying on regex or hand edits.
Prerequisites
Grit CLI, a local repository to search or rewrite, and a review loop for inspecting the diffs produced by structural patterns.
Installation
Requirements and caveats from upstream:
- ♻️ 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,...
- Patterns can be combined to create complex queries, including large refactors.
- Reading/writing a codemod requires mentally translating from AST names back to what source code actually looks like.
Basic usage or getting-started notes:
- Read the documentation, interactive tutorial, or run grit --help.
- sh
- Search for all your console.log calls by putting the desired pattern in backticks:
- Source: https://github.com/1991513ccie-png/skills
- Extracted from upstream docs: https://raw.githubusercontent.com/biomejs/gritql/HEAD/README.md
Documentation
- https://docs.grit.io/language/overview