ast-grep 结构化代码搜索与重写 是做什么的?
使用 ast-grep (sg) 通过 AST 模式匹配在大型代码库中搜索、检查并重写代码。它是基于正则表达式代码转换的极速替代方案,天然理解语法结构。
安装
使用与你环境匹配的上游安装或配置路径:
- npm install --global @ast-grep/cli
- pip install ast-grep-cli
- brew install ast-grep
- cargo install ast-grep --locked
来自上游的要求和注意事项:
- 你可以使用美元符号加字母(例如
$MATCH)作为通配符,匹配任意单个 AST 节点。它类似于[正则表达式中的点](https://regexone.com/lesson... - 你可以从 npm、pip、cargo、[cargo-binstall](... 安装
基本用法或入门说明:
-
bash
-
pnpm approve-builds 可能必需
-
摘自上游文档:https://raw.githubusercontent.com/ast-grep/ast-grep/HEAD/README.md