‹ 首页

ast-grep

@code-yeongyu · 收录于 3 周前 · 上游提交 今天

Use ast-grep (sg) for AST-aware code search and rewrite across 25 languages. Trigger for structural code matching or deterministic codemods: find every function/call/class/import shaped like X, rewrite console.log to logger.info, strip `as any`, migrate require() to import, find empty catch blocks or missing await, and scan/apply YAML rules. Prefer this over rg/grep when the target is syntax shape rather than text; use rg for string contents, comments, filenames, or regex-style byte searches.

适合你,如果需要在多语言项目中按代码结构而非文本进行搜索和替换

/ 通过 npx 安装 校验哈希
npx oh-my-skill add code-yeongyu/oh-my-openagent/ast-grep
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- code-yeongyu/oh-my-openagent/ast-grep
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify code-yeongyu/oh-my-openagent/ast-grep
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
66743GitHub stars
~3K最小装载
~23.8K含声明引用
~28.5K文本包总量
镜像托管

怎么用

商店整理自技能原文 · 版本 ace1339 · 表述以原文为准
它做什么

装上后,Claude可以使用ast-grep工具,根据代码的结构特征(而非纯文本)来搜索和批量改写。例如,它能找到所有符合特定模式(如接受某个参数的函数)的代码,并把它们替换成另一种形式。

什么时候触发

当你需要基于代码语法结构进行搜索或修改时触发,例如查找所有特定形状的函数、调用、类,或执行确定的代码迁移(如将console.log改写为logger.info)。注意:如果目标是文本内容(如注释、字符串),应改用rg/grep。

装好后可以这样说
这会在目标代码中执行模式替换。
会搜索并返回匹配的函数定义。
会删除所有匹配的“as any”语句。

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。