Langsung ke konten
Skillpedia
Testing48k Β· #5937

tdd-workflows-tdd-refactor

Fungsinya

Tool ini membantu meningkatkan kode program Anda agar lebih rapi dan efisien. Caranya dengan menerapkan teknik refactoring sambil memastikan semua test kode Anda tetap lolos.

Kapan dipakai

  • βœ“Saat Anda ingin membuat kode lebih terorganisir.
  • βœ“Saat Anda ingin meningkatkan kecepatan kode.
  • βœ“Saat Anda ingin memastikan perubahan kode tidak merusak apa pun.

Link skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/tdd-workflows-tdd-refactor/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/tdd-workflows-tdd-refactor/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œRefactor kode ini agar lebih rapi dan cepat, tetapi pastikan semua test tetap lolos.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Tool ini menganalisis kode Anda, mengidentifikasi bagian yang bisa diperbaiki (seperti pengulangan atau kompleksitas), lalu menerapkan teknik yang sudah dikenal untuk memperbaikinya. Tool ini menjalankan test sebelum dan sesudah perubahan untuk memastikan semuanya tetap berfungsi.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Use this skill when

  • Working on tdd workflows tdd refactor tasks or workflows
  • Needing guidance, best practices, or checklists for tdd workflows tdd refactor

Do not use this skill when

  • The task is unrelated to tdd workflows tdd refactor
  • You need a different domain or tool outside this scope

Instructions

  • Clarify goals, constraints, and required inputs.
  • Apply relevant best practices and validate outcomes.
  • Provide actionable steps and verification.
  • If detailed examples are required, open resources/implementation-playbook.md.

Refactor code with confidence using comprehensive test safety net:

[Extended thinking: This tool uses the tdd-orchestrator agent (opus model) for sophisticated refactoring while maintaining all tests green. It applies design patterns, improves code quality, and optimizes performance with the safety of comprehensive test coverage.]

Usage

Use Task tool with subagent_type="tdd-orchestrator" to perform safe refactoring.

Prompt: "Refactor this code while keeping all tests green: $ARGUMENTS. Apply TDD refactor phase:

Core Process

1. Pre-Assessment

  • Run tests to establish green baseline
  • Analyze code smells and test coverage
  • Document current performance metrics
  • Create incremental refactoring plan

2. Code Smell Detection

  • Duplicated code β†’ Extract methods/classes
  • Long methods β†’ Decompose into focused functions
  • Large classes β†’ Split responsibilities
  • Long parameter lists β†’ Parameter objects
  • Feature Envy β†’ Move methods to appropriate classes
  • Primitive Obsession β†’ Value objects
  • Switch statements β†’ Polymorphism
  • Dead code β†’ Remove

3. Design Patterns

  • Apply Creational (Factory, Builder, Singleton)
  • Apply Structural (Adapter, Facade, Decorator)
  • Apply Behavioral (Strategy, Observer, Command)
  • Apply Domain (Repository, Service, Value Objects)
  • Use patterns only where they add clear value

4. SOLID Principles

  • Single Responsibility: One reason to change
  • Open/Closed: Open for extension, closed for modification
  • Liskov Substitution: Subtypes substitutable
  • Interface Segregation: Small, focused interfaces
  • Dependency Inversion: Depend on abstractions

5. Refactoring Techniques

  • Extract Method/Variable/Interface
  • Inline unnecessary indirection
  • Rename for clarity
  • Move Method/Field to appropriate classes
  • Replace Magic Numbers with constants
  • Encapsulate fields
  • Replace Conditional with Polymorphism
  • Introduce Null Object

6. Performance Optimization

  • Profile to identify bottlenecks
  • Optimize algorithms and data structures
  • Implement caching where beneficial
  • Reduce database queries (N+1 elimination)
  • Lazy loading and pagination
  • Always measure before and after

7. Incremental Steps

  • Make small, atomic changes
  • Run tests after each modification
  • Commit after each successful refactoring
  • Keep refactoring separate from behavior changes
  • Use scaffolding when needed

8. Architecture Evolution

  • Layer separation and dependency management
  • Module boundaries and interface definition
  • Event-driven patterns for decoupling
  • Database access pattern optimization

9. Safety Verification

  • Run full test suite after each change
  • Performance regression testing
  • Mutation testing for test effectiveness
  • Rollback plan for major changes

10. Advanced Patterns

  • Strangler Fig: Gradual legacy replacement
  • Branch by Abstraction: Large-scale changes
  • Parallel Change: Expand-contract pattern
  • Mikado Method: Dependency graph navigation

Output Requirements

  • Refactored code with improvements applied
  • Test results (all green)
  • Before/after metrics comparison
  • Applied refactoring techniques list
  • Performance improvement measurements
  • Remaining technical debt assessment

Safety Checklist

Before committing:

  • βœ“ All tests pass (100% green)
  • βœ“ No functionality regression
  • βœ“ Performance metrics acceptable
  • βœ“ Code coverage maintained/improved
  • βœ“ Documentation updated

Recovery Protocol

If tests fail:

  • Immediately revert last change
  • Identify breaking refactoring
  • Apply smaller incremental changes
  • Use version control for safe experimentation

Example: Extract Method Pattern

Before:

class OrderProcessor {
  processOrder(order: Order): ProcessResult {
    // Validation
    if (!order.customerId || order.items.length === 0) {
      return { success: false, error: "Invalid order" };
    }

    // Calculate totals
    let subtotal = 0;

…
Pertanyaan umum

Apa itu refactoring?

Refactoring adalah proses menyusun ulang kode program yang sudah ada tanpa mengubah perilaku eksternalnya. Tujuannya adalah meningkatkan kejelasan, mengurangi kompleksitas, dan mempermudah pemeliharaan.

Mengapa penting agar test tetap lolos?

Test yang tetap lolos memastikan perubahan pada kode tidak menimbulkan bug baru atau merusak fungsi yang sudah ada. Test berperan sebagai jaring pengaman.

Peningkatan seperti apa yang bisa didapatkan pada kode?

Kode bisa menjadi lebih mudah dibaca, lebih cepat dijalankan, lebih terorganisir, dan lebih sederhana untuk diubah di masa depan.

Detail

Deskripsi asli dari pembuat

Use when working with tdd workflows tdd refactor

repo: sickn33/agentic-awesome-skills

Popularitas

Bintang GitHub
48k
Peringkat
#5937
Lisensi
MIT
Diperbarui
15/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa