agentleFS
wisterx-specwisterx-spec/agent-rails/.agents/skills/scan-unused-exports/SKILL.md

scan-unused-exports

Skill2 starsChanged 7 months agoMITView on GitHub

扫描工具/类型/常量目录中有导出但从未被 import 的函数、类型、常量,输出候选清单

The file

Files
SKILL.md

Scan Unused Exports Skill

单独调用:/scan-unused-exports 在工作流中调用:由 slim 工作流 Phase 3 自动触发 可跳过条件:项目已集成 ESLint no-unused-vars + import/no-unused-modules 规则时,可跳过此 skill,直接用 lint 结果


执行步骤

Step 1:确定扫描目录

扫描以下目录(存在哪个扫哪个):

  • utils/、helpers/、lib/
  • constants/、config/
  • types/、interfaces/、models/(仅 .ts 类型文件)

过滤 .slimignore 豁免路径。

Step 2:提取所有 export 声明

grep -rn "^export\|^export default\| export " {{SCAN_DIRS}} --include="*.{{EXT}}"

提取每个 export 的名称(函数名、类名、类型名、常量名)。

Step 3:全库搜索 import 引用

对每个导出名,在整个仓库搜索:

grep -rn "import.*{.*ExportName.*}" {{PROJECT_ROOT}} --include="*.{{EXT}}"

零引用 → 候选。有引用 → 跳过。

⚠️ 注意:以下情况不能标为"未引用":

  • export default(被 import Xxx from 动态路径导入时难以静态追踪)
  • 被字符串形式动态 require/import 的导出
  • .d.ts 类型声明文件(可能被 IDE 工具链使用)

Step 4:风险分级

  • 🟢 低:工具函数,名称唯一,确认无引用
  • 🟡 中:类型/interface,可能被运行时反射或泛型引用
  • 🔴 高:不建议删除(export default / 类型声明文件)

输出格式

## 未引用导出扫描结果

| 文件 | 导出名 | 类型 | 风险 |
|------|--------|------|------|
| src/utils/legacyFormat.ts | formatOldDate | function | 🟢 低 |
| src/types/deprecated.ts | OldUserType | type | 🟡 中 |

无问题时输出:✅ 未发现明显未引用的导出

约束

  • NEVER 删除任何导出,只输出报告
  • NEVER 将 export default 标为未引用(静态分析不可靠)
  • MUST 将 🔴 高风险项排除在删除建议之外

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.