code-refactoring-refactor-clean
使用 SOLID 原則重構和清理程式碼
將纏結、難以維護的程式碼轉化為乾淨、模組化的架構,使用經過驗證的重構模式和 SOLID 設計原則。此技能提供專業指導,幫助識別程式碼異味、應用設計模式,以及實作增量改進以提升程式碼品質,同時不會破壞現有功能。
Télécharger le ZIP du skill
Importer dans Claude
Allez dans Paramètres → Capacités → Skills → Importer un skill
Activez et commencez à utiliser
Tester
Utilisation de "code-refactoring-refactor-clean". Analyze this 500-line OrderSystem class for code smells and suggest improvements
Résultat attendu:
分析摘要:發現 SRP 違規(驗證、資料庫、郵件、日誌混合)、45 的圈複雜度、0% 的測試覆蓋率。重構計劃:1) 將驗證提取到 OrderValidator (2小時),2) 為資料存取建立儲存庫模式 (4小時),3) 實作相依性注入 (3小時)。預估工作量:9小時,風險:中等(存在一些測試)。
Utilisation de "code-refactoring-refactor-clean". Refactor this function to follow SOLID principles
Résultat attendu:
重構後的程式碼:將 UserManager 拆分為 5 個類別(UserValidator、UserRepository、EmailService、UserActivityLogger、UserService),每個類別各有單一職責。應用相依性注入以實現鬆散耦合。结果:每個方法平均 15 行,複雜度從 25 降至 4,測試覆蓋率提升至 92%。
Utilisation de "code-refactoring-refactor-clean". Apply design patterns to this discount calculation logic
Résultat attendu:
已應用策略模式:建立 DiscountStrategy 介面,包含 PercentageDiscount、FixedDiscount 和 TieredDiscount 的實作。DiscountCalculator 現在接受策略物件,消除條件邏輯。優點:新折扣類型無需修改現有程式碼(開放/封閉原則),可測試性提升 100%。
Audit de sécurité
SûrAll 90 static analysis findings are false positives. The detected patterns appear in markdown documentation files as educational code examples demonstrating refactoring patterns. The skill contains no executable code - only AI prompts and documentation. All patterns (backtick execution, email operations, file access, weak crypto references, reconnaissance commands) are within code blocks in implementation-playbook.md as teaching examples for proper refactoring. No security risks exist.
Problèmes à risque faible (1)
Score de qualité
Ce que vous pouvez construire
舊程式碼現代化
將舊的單體式應用程式轉化為遵循 SOLID 原則和現代設計模式的乾淨、模組化架構
程式碼審查改進
在提取請求審查期間識別並修復程式碼異味、降低複雜度並提升可維護性
入職最佳實踐
透過實際範例和逐步遷移指南學習重構模式和乾淨程式碼原則
Essayez ces prompts
重構此程式碼以提升可讀性並減少重複
分析此程式碼的程式碼異味、SOLID 違規和技術債務。提供優先順序重構計劃。
遵循 SOLID 原則應用適當的設計模式重構此程式碼。展示之前/之後的比較。
完全重構此程式碼,包括測試套件生成、遷移指南和顯示改進的指標報告
Bonnes pratiques
- 始終在重構前後執行現有測試以確保行為保留
- 以小型、增量步驟進行重構,而非大規模重寫
- 使用 implementation-playbook.md 參考資料獲取詳細模式和範例
Éviter
- 不要在沒有測試的情況下重構 - 務必先建立測試覆蓋率
- 避免對簡單解決方案過度工程 - YAGNI(你不需要它)
- 未經明確的利害關係人批准不要變更外部行為