Skip to content
Back to skills

Refactor

ASecurity

- 每次只做一种重构,不混合多种变更,便于验证行为一致 - 代码坏味道识别:重复代码→提取函数、过长函数→拆分、深层嵌套→提前返回/卫语句 - SOLID原则:单一职责(类只做一件事)、开闭(扩展开放修改关闭)、依赖倒置(依赖抽象不依赖具体) - 提取函数:3行以上重复代码或逻辑独立片段,命名体现意图而非实现 - 简化条件:复杂if/else链改为策略模式或查表法 - 消除魔法数字:提取为命名常量,放在文件顶部或配置中 - 参数过多(>4个):封装为数据类/字典/配置对象 - 重构前确保有测试覆盖,重构后运行测试验证行为不变 - 不改变公开API签名,除非调用方也在重构范围内 - 大范围重构分步提交:先提取→再替换调用→最后删除旧代码

  • 687 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added June 5, 2026
toolsapi

Works with

  • api

Security analysis

A100/100

Scanned June 5, 2026

npx -y skills add val1813/kwcode --skill refactor --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Refactor?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Refactor
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/val1813-refactor/badge)](https://www.skillsdirectory.com/skills/val1813-refactor)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: RefactorExpert
version: 1.0.0
trigger_keywords: [重构, refactor, 去重, deduplicate, 代码重构]
trigger_min_confidence: 0.7
pipeline: [locator, generator, verifier]
lifecycle: mature
---

## 领域知识

- 每次只做一种重构,不混合多种变更,便于验证行为一致
- 代码坏味道识别:重复代码→提取函数、过长函数→拆分、深层嵌套→提前返回/卫语句
- SOLID原则:单一职责(类只做一件事)、开闭(扩展开放修改关闭)、依赖倒置(依赖抽象不依赖具体)
- 提取函数:3行以上重复代码或逻辑独立片段,命名体现意图而非实现
- 简化条件:复杂if/else链改为策略模式或查表法
- 消除魔法数字:提取为命名常量,放在文件顶部或配置中
- 参数过多(>4个):封装为数据类/字典/配置对象
- 重构前确保有测试覆盖,重构后运行测试验证行为不变
- 不改变公开API签名,除非调用方也在重构范围内
- 大范围重构分步提交:先提取→再替换调用→最后删除旧代码

## 经验规则(自动生成)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.