‹ 首页

refactoring

@lexler · 收录于 昨天 · 上游提交 1 周前

Refactoring process. Invoke immediately when user or document mentions refactoring, or proactively when code gets too complex or messy.

适合你,如果代码变得复杂难以维护

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

怎么用

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

当用户要求或代码复杂时,Claude会自动进行代码重构:清理注释、重命名变量、提取方法、删除无用代码等,并确保测试通过。最终输出优化后的代码和重构摘要。

什么时候触发

当用户提到“重构”或代码变得复杂/混乱时,Claude会主动启动重构流程。

装好后可以这样说
Claude会从简单到复杂逐步重构。
Claude会自动识别并重构。
每次重构后都会测试并提交。
技能原文 SKILL.md作者撰写 · Apache-2.0 · 2eae60e

Refactoring Production Code

STARTER_CHARACTER = 🟣

When starting, announce: "🟣 Using REFACTORING skill".

Work autonomously as much as possible. Start with the simplest thing or file and proceed to the more complex ones.

Stages
  1. Prep
  2. Main Refactoring
  3. Final Evaluation
  4. Summary
Test Code Policy

Do not change test code during refactoring, except:

  • Renames that follow production code renames (imports, function calls)
  • Import path updates if something moved

Never change test assertions, test data, or test logic.

1. Prep
  • Determine scope: use specified files, or identify related files (imports, shared functionality), or ask user
  • Add files in scope to todo list
  • Find or create ./test.sh, verify all tests pass
  • Remove comments from files in scope (commit per file)
2. Main Refactoring
Code Style

Prefer self-explanatory, readable code over comments.

  • Use functional helper methods for clarity
  • Remove dead code
  • Extract paragraphs into methods
  • Use better variable names
  • Remove unused imports
  • Remove unhelpful local variables
  • Look for opportunities to simplify
  • Use domain language - name things for what they ARE, not how they're implemented
  • Keep consistent abstraction levels within methods
Process

For each refactor:

  1. Ensure all tests pass
  2. Choose and perform the simplest possible refactoring (one at a time)
  3. Ensure all tests pass after the change
  4. Commit each successful refactor with the message format: "- r <refactoring>" (the message must include the "- r" prefix) Prefer small granular commits. If applying the same refactoring pattern to multiple locations, change one location at a time and commit each separately.
  5. Provide a status update after each refactor
3. Final Evaluation

When you see no more obvious refactoring opportunities, say "🔍 Entering final evaluation."

Shift focus: you've been implementing. Now become a critic. Your job is to find problems, not produce code.

Re-read Code Style guidelines. Look at each file in scope. Consider blind spots - what improvements haven't we even considered that would make the code better, easier, more maintainable?

For each file, find ONE thing that could be better. If you find something:

  1. Fix it using the same refactoring process (test, change, test, commit)
  2. Look again; fixing one thing often reveals the next

Repeat until you find nothing more to improve.

4. Summary

Provide a high-level summary of the refactoring:

  • List each file that was touched
  • Describe the key improvements made in each file
Language-Specific

For Java: See [references/java.md](references/java.md)

按 Apache-2.0 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

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