一键导入
expert-code-quality
代码质量专家,整合Martin Fowler重构技术和GoF设计模式,帮助开发者系统性地提升代码质量。当用户询问代码审查、重构、设计模式、代码异味、SOLID原则或软件架构改进时触发此技能。支持中文触发:代码质量、代码审查、重构、设计模式、代码异味、SOLID原则、架构改进。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
代码质量专家,整合Martin Fowler重构技术和GoF设计模式,帮助开发者系统性地提升代码质量。当用户询问代码审查、重构、设计模式、代码异味、SOLID原则或软件架构改进时触发此技能。支持中文触发:代码质量、代码审查、重构、设计模式、代码异味、SOLID原则、架构改进。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
"PDD框架下的业务分析Skill,运用专业方法论进行需求分析和业务建模。当用户输入/analyze、/audit、/doc等命令,或需要对业务流程、管理制度、Excel表单进行专业分析时触发。支持中文触发:业务分析、需求分析、需求建模、5W1H分析、MECE、流程分析。"
"PDD熵减智能体,持续监控和偿还技术债务,防止系统腐化。当用户需要代码清理、文档更新、技术债务管理、架构对齐、熵减、垃圾回收、清理技术债务时自动触发。即使用户只说'熵减'、'清理技术债务'或'垃圾回收',也应触发此Skill。支持中文触发:熵减、技术债务、代码清理、文档更新、架构对齐、垃圾回收。"
根据开发规格实现功能点代码的核心Skill。当用户想要开始编码实现、根据规格文档生成代码、实现功能点时调用此Skill。此Skill会自动调用pdd-template-engine生成基础代码框架,然后由software-engineer补充业务逻辑。即使只有规格文档没有明确说'实现',只要涉及代码生成、功能开发,都应触发此Skill。支持中文触发:实现功能点、编码实现、开始编码、功能开发、代码实现、PDD实现。
PRD驱动开发的主入口Skill,协调整个开发流程。当用户想要基于PRD文档进行功能开发、从需求文档生成代码、执行PDD方法论流程、开发业务模块、实现完整功能、'搞个功能'、'资产转让'、'国有产权转让'、'帮我搞个资产转让的功能'时必须调用此Skill。即使用户没有明确说'使用PDD',只要涉及PRD文档、需求文档、功能点开发、规格文档、模块开发、根据文档开发、业务功能实现、'开发ZCCZ'、'我想开发'、'搞个功能'等场景,都应触发此Skill。此Skill会自动协调pdd-ba、pdd-extract-features、pdd-generate-spec、pdd-implement-feature等子Skill完成从需求分析到代码交付的完整流程。注意:单一接口设计、调试问题、文档查询等场景不应触发此Skill。支持中文触发:PRD驱动开发、PDD开发、功能开发、启动PDD。
"交通事故责任评估与判定专业技能。当用户需要交通事故责任分析、事故现场照片评估、交通法规咨询、事故责任划分、法律依据查询时触发此技能。适用于车辆碰撞事故、行人事故、非机动车事故等各类道路交通事故的责任认定场景。无论用户使用'交通事故'、'车祸'、'责任判定'、'交通法规'、'事故定责'等何种表述,只要涉及交通事故评估或责任认定,均应调用此技能。支持中文触发:交通事故、车祸、责任判定、交通法规、事故定责、责任划分、事故评估、追尾、碰撞、违章、赔偿。"
自动化重构专家技能,将收集到的质量改进任务转化为具体的代码操作。当用户需要代码重构、消除重复、简化复杂度时自动触发。即使用户只说'重构代码'、'消除重复'或'简化代码',也应触发此Skill。支持中文触发:重构代码、消除重复、简化复杂度、自动重构、代码重构、PDD重构。
| name | expert-code-quality |
| description | 代码质量专家,整合Martin Fowler重构技术和GoF设计模式,帮助开发者系统性地提升代码质量。当用户询问代码审查、重构、设计模式、代码异味、SOLID原则或软件架构改进时触发此技能。支持中文触发:代码质量、代码审查、重构、设计模式、代码异味、SOLID原则、架构改进。 |
| license | MIT |
| author | neuqik@hotmail.com |
| version | 2.0 |
This skill integrates two foundational software engineering disciplines:
Combined, they form a powerful toolkit for writing clean, maintainable, and extensible code.
expert-code-quality/
├── SKILL.md # Skill definition file
├── LICENSE # MIT License
└── references/ # Reference documents
├── refactoring-catalog.md # Complete catalog of refactoring techniques
├── design-patterns.md # 23 GoF patterns
├── code-smells.md # Detailed description of code smells
└── solid-principles.md # In-depth analysis of SOLID principles
Automatic Triggers:
Manual Triggers:
/code-quality, /refactor, /pattern, etc.Method-Level Smells:
| Smell | Detection Pattern | Severity |
|---|---|---|
| Long Method | Method > 20 lines | High |
| Duplicated Code | Similar code blocks | Critical |
| Long Parameter List | Parameters > 4 | Medium |
| Switch Statements | Large switch/case blocks | Medium |
Class-Level Smells:
| Smell | Detection Pattern | Severity |
|---|---|---|
| Large Class | Class > 300 lines or > 10 fields | High |
| Divergent Change | One class changes for multiple reasons | High |
| Shotgun Surgery | One change requires modifying many classes | High |
| Feature Envy | Method uses data from other classes more | Medium |
Relationship-Level Smells:
| Smell | Detection Pattern | Severity |
|---|---|---|
| Inappropriate Intimacy | Classes access each other's private parts | Medium |
| Message Chains | a.b().c().d() chains | Medium |
| Middle Man | Class only does delegation | Low |
| Data Clumps | Same data items always appear together | Medium |
When reviewing code, check:
Two Hats (Kent Beck):
| Hat | Activity | Rule |
|---|---|---|
| Adding Features | Add new functionality | Don't modify existing code |
| Refactoring | Improve structure | Don't add new features |
Never wear both hats at the same time!
Refactoring Rhythm:
Test → Small Change → Test → Small Change → Test
Composing Methods:
| Refactoring | When to Use | Steps |
|---|---|---|
| Extract Method | Method too long, code block needs naming | 1.Create new method 2.Copy code 3.Replace original code with call |
| Inline Method | Method body as clear as its name | 1.Replace calls with method body 2.Delete method |
| Replace Temp with Query | Temporary variable holds expression | 1.Extract expression to method 2.Replace temp with call |
| Replace Method with Method Object | Too many temporaries in long method | 1.Create class for method 2.Temporaries become fields |
Moving Features:
| Refactoring | When to Use | Steps |
|---|---|---|
| Move Method | Method uses other class more | 1.Copy to target 2.Delegate in source 3.Delete source method |
| Extract Class | Class does too much | 1.Create new class 2.Move fields/methods 3.Link classes |
| Hide Delegate | Client knows delegation chain | 1.Add delegate method 2.Hide chain |
Simplifying Conditionals:
| Refactoring | When to Use | Steps |
|---|---|---|
| Decompose Conditional | Complex conditional logic | 1.Extract condition 2.Extract then/else |
| Consolidate Conditional | Multiple checks with same result | 1.Combine with && or || 2.Extract method |
| Replace Nested Conditional with Guard Clauses | Deeply nested if-else | 1.Add guard clause returns 2.Flatten structure |
| Replace Conditional with Polymorphism | Switch by type | 1.Create subclasses 2.Move behavior to each subclass |
Found code smell?
│
├─ Do you have tests?
│ ├─ No → Write tests first
│ └─ Yes → Continue
│
├─ Do you understand the code?
│ ├─ No → Refactor to understand
│ └─ Yes → Continue
│
└─ Choose refactoring approach:
│
├─ Method too long → Extract Method
├─ Duplicated code → Extract Method / Pull Up
├─ Class too large → Extract Class
├─ Parameter list too long → Introduce Parameter Object
├─ Switch statement → Replace with Polymorphism
└─ Complex conditionals → Decompose / Guard Clauses
Before applying patterns, ensure understanding of SOLID principles:
| Principle | Name | Description |
|---|---|---|
| S | Single Responsibility | One reason to change |
| O | Open/Closed | Open for extension, closed for modification |
| L | Liskov Substitution | Subtypes must be substitutable |
| I | Interface Segregation | Small, focused interfaces |
| D | Dependency Inversion | Depend on abstractions |
| Problem | Pattern | Key Benefit |
|---|---|---|
| Need single instance | Singleton | Controlled access |
| Flexible object creation | Factory Method | Decouple creation |
| Create families of objects | Abstract Factory | Consistent products |
| Build complex objects | Builder | Step-by-step construction |
| Incompatible interfaces | Adapter | Make incompatible work |
| Dynamically add responsibilities | Decorator | Flexible extension |
| Control access | Proxy | Indirection layer |
| Simplify complex system | Facade | Simple interface |
| Tree structure | Composite | Uniform handling |
| Switch algorithms | Strategy | Interchangeable behaviors |
| Event notification | Observer | Loose coupling |
| Encapsulate requests | Command | Undo/redo support |
| State-dependent behavior | State | Clear state transitions |
| Smell | Pattern Solution |
|---|---|
| Large switch statement | State, Strategy |
| Multiple conditionals | Strategy, State, Null Object |
| Tight coupling | Observer, Mediator, Facade |
| Difficult object creation | Factory, Builder |
| Hard to extend class | Decorator, Adapter |
| Complex subsystem | Facade |
| Need varying algorithms | Strategy, Template Method |
Creational Patterns:
| Pattern | When to Use |
|---|---|
| Singleton | Need single instance |
| Factory Method | Don't know exact class to create |
| Abstract Factory | Need families of related objects |
| Builder | Complex object with many options |
| Prototype | Clone existing objects |
Structural Patterns:
| Pattern | When to Use |
|---|---|
| Adapter | Incompatible interfaces |
| Decorator | Dynamically add responsibilities |
| Proxy | Control access, lazy loading |
| Facade | Simplify complex interfaces |
| Composite | Tree structure, uniform handling |
| Flyweight | Many similar objects, share state |
| Bridge | Separate abstraction from implementation |
Behavioral Patterns:
| Pattern | When to Use |
|---|---|
| Strategy | Interchangeable algorithms |
| Observer | One-to-many notifications |
| Command | Encapsulate requests, undo/redo |
| State | State-dependent behavior |
| Template Method | Algorithm skeleton, varying steps |
| Iterator | Uniform collection traversal |
| Mediator | Complex object interactions |
| Memento | Save/restore state |
| Chain of Resp. | Request has multiple handlers |
| Visitor | Add operations to object structure |
1. IDENTIFY
└── Detect code smells
└── Use smell checklist
└── Rate severity (Critical/High/Medium/Low)
2. DIAGNOSE
└── Understand root cause
└── Why does this smell exist?
└── What problems will it cause?
3. PLAN
└── Choose refactoring or pattern
└── Consider dependencies
└── Estimate impact
4. PREPARE
└── Ensure tests exist
└── Run tests to verify behavior
└── Create tests if missing
5. EXECUTE
└── Apply small changes
└── Test after each change
└── Keep code working
6. VERIFY
└── Run all tests
└── Check for new smells
└── Confirm improvement
Detected code smell
│
▼
┌───────────────────┐
│ Is this a method │
│ level problem? │
└────────┬──────────┘
│
┌────┴────┐
│ Yes │ No
▼ ▼
Extract Is this a class
Method level problem?
│
┌────┴────┐
│ Yes │ No
▼ ▼
Extract Is this a
Class relationship
problem?
│
┌────┴────┐
│ Yes │ No
▼ ▼
Move/Hide Consider
Delegate Pattern
│
▼
┌──────────────┐
│ Which │
│ pattern fits │
│ best? │
└──────┬───────┘
│
┌───────────────┼───────────────┐
▼ ▼ ▼
Creational Structural Behavioral
Patterns Patterns Patterns
| Collaborating Skill | Collaboration Mode | Description |
|---|---|---|
| test-driven-development | Sequential | Write tests before refactoring |
| systematic-debugging | Consultation | Find root cause before fixing |
| requesting-code-review | Reference | Get feedback on refactored code |
| pdd-code-reviewer | Reference | Get PDD project code review |
| software-engineer | Delegation | Quality check after code implementation |
Code quality issue detected
↓
Invoke expert-code-quality
↓
Identify code smells + Recommend refactoring/patterns
↓
(If tests needed first) → Invoke test-driven-development
↓
(If code implementation needed) → Invoke software-engineer
↓
Complete code quality improvement
| Scenario | Primary Action |
|---|---|
| Found duplicated code | Extract Method |
| Method too long | Extract Method |
| Class too large | Extract Class |
| Parameter list too long | Introduce Parameter Object |
| Switch by type | Replace with Polymorphism |
| Need single instance | Consider Singleton |
| Need flexible creation | Factory Method or Builder |
| Incompatible interfaces | Adapter |
| Need to add behavior | Decorator |
| Complex subsystem | Facade |
| Need varying algorithms | Strategy |
| Need event notification | Observer |
| Anti-Pattern | Description | Correct Approach |
|---|---|---|
| Big Bang Refactoring | Rewrite everything at once | Small incremental changes |
| Refactoring Without Tests | Change code without safety net | Write tests first |
| Over-Refactoring | Refactor clean code | Stop when code is clear |
| Refactoring Addiction | Only refactor, never deliver | Balance refactoring with features |
| Random Refactoring | No clear goal | Identify smells first |
| Anti-Pattern | Description | Correct Approach |
|---|---|---|
| Pattern Obsession | Use patterns everywhere | Use patterns to solve problems |
| Singleton Abuse | Everything is singleton | Use only when truly needed |
| Factory Overkill | Factory for single product | Use factory for multiple products |
| Decorator Nesting | Too many decorator layers | Limit nesting depth |
| Premature Pattern | Use pattern before needed | Let patterns emerge from refactoring |
Before approving code, verify:
Before refactoring:
Before applying pattern:
Remember: Good code isn't about being clever—it's about being clear. Refactoring and patterns are tools to achieve clarity, not ends in themselves.