Habilidades dry-refactoring
♻️

dry-refactoring

Seguro 🌐 Acesso à rede⚙️ Comandos externos

通过 DRY 重构消除代码重复

代码重复会导致维护难题和行为不一致。本技能将引导您通过系统性的四步流程——识别、抽象、替换和验证——进行重构,消除重复代码并提升代码质量。

Suporta: Claude Codex Code(CC)
📊 70 Adequado
1

Baixar o ZIP da skill

2

Upload no Claude

Vá em Configurações → Capacidades → Skills → Upload skill

3

Ative e comece a usar

Testar

A utilizar "dry-refactoring". I have these two functions that look almost identical. Help me refactor them.

Resultado esperado:

  • I can see the duplication between these functions. Let me apply the DRY workflow:
  • Step 1 - Identify: Both functions share the same structure for calculating discounts above a threshold. The only difference is the variable names.
  • Step 2 - Abstract: Create a single function that takes the amount and threshold as parameters.
  • Step 3 - Replace: Update both call sites to use the new abstraction.
  • Step 4 - Verify: Let me help you write tests to confirm the behavior remains identical.

A utilizar "dry-refactoring". My code has the same magic number 0.08 repeated in multiple places for tax calculations.

Resultado esperado:

  • I can help you eliminate these magic numbers. Here is the approach:
  • Step 1 - Identify: The value 0.08 appears in calculate_tax_1, calculate_tax_2, and calculate_total.
  • Step 2 - Abstract: Create a constant TAX_RATE = 0.08 in a central location.
  • Step 3 - Replace: Replace all occurrences with TAX_RATE.
  • Step 4 - Verify: Run tests to confirm tax calculations remain correct.

A utilizar "dry-refactoring". Help me refactor my validation logic that is repeated across three different service files.

Resultado esperado:

  • I see you have similar validation patterns across services. Let me guide you through DRY refactoring:
  • Step 1 - Identify: All three services perform email validation, password validation, and role checks.
  • Step 2 - Abstract: Create a validation utility module with reusable functions.
  • Step 3 - Replace: Import and use the utility functions in each service.
  • Step 4 - Verify: Ensure all validation behavior is preserved and add comprehensive tests.

Auditoria de Segurança

Seguro
v4 • 1/17/2026

Pure documentation skill containing only guidance and code examples for DRY refactoring. No executable code, no network calls, no file access, and no system commands. All 92 static findings are false positives caused by the analyzer misinterpreting markdown documentation patterns as security issues.

2
Arquivos analisados
1,141
Linhas analisadas
2
achados
4
Total de auditorias
Auditado por: claude Ver Histórico de Auditoria →

Pontuação de qualidade

38
Arquitetura
100
Manutenibilidade
87
Conteúdo
32
Comunidade
100
Segurança
83
Conformidade com especificações

O Que Você Pode Construir

清理复制粘贴代码

使用系统性的四步工作流识别并消除散布在代码库中的重复代码块。

标准化重构审查

在审查重构变更时应用一致的标准,确保符合 DRY 原则。

建立团队重构标准

为您的团队定义清晰的指南,系统性地解决遗留系统中的代码重复问题。

Tente Estes Prompts

快速 DRY 检查
Help me identify duplicate code in my function that calculates prices. Here is my code: [paste code]
提取函数
I have three similar validation functions. Help me extract the common logic into a single reusable function following the DRY workflow.
魔法数字清理
My codebase has magic numbers like 0.08 for tax rates appearing in many places. Guide me through replacing them with named constants.
完整重构
Guide me through a complete DRY refactoring of my order calculation module. I want to identify all duplication, abstract it properly, and verify the changes.

Melhores Práticas

  • 应用二次原则:当您第二次编写类似代码时进行重构。
  • 使用渐进式重构:进行小的、可测试的变更,而不是大规模重写。
  • 始终在重构之前编写或更新测试以确保行为得到保留。

Evitar

  • 过度抽象:在理解真正的模式之前就创建通用解决方案。
  • 部分替换:清理部分重复代码却留下另一部分。
  • 忽视性能:通过抽象引入不必要的函数调用开销。

Perguntas Frequentes

本技能支持哪些编程语言?
本技能是与语言无关的。示例使用 JavaScript、Python 和 TypeScript,但这些原则适用于任何编程语言。
多少代码重复才值得进行重构?
使用二次原则:当您第二次编写类似代码时,考虑提取它。小规模的重复会随着时间累积。
我可以将本技能与现有的重构工具一起使用吗?
是的。本技能提供的指导可与任何 IDE 或重构工具配合使用。在使用您喜欢的工具时应用这些原则。
本技能会修改我的文件吗?
不会。本技能提供指导和示例。您需要在编辑器或 IDE 中手动应用更改。
如果我的重复代码有细微变化怎么办?
本技能涵盖边缘情况。使用可选参数、回调函数,或者如果它们有根本不同的逻辑,则保持分离。
这与自动化重构工具有何不同?
自动化工具机械地进行重构。本技能帮助您系统地思考何时抽象、抽象什么以及如何抽象以获得最大的可维护性。

Detalhes do Desenvolvedor

Autor

YYH211

Licença

MIT

Referência

main

Estrutura de arquivos

📄 SKILL.md