.claude/skills/refactoring/SKILL.md
Refactoring assessment and patterns. Use after mutation testing validates test strength (MUTATE phase) to assess improvement opportunities.
npx skillsauth add jscriptcoder/jshack.me refactoringInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Refactoring is the final step of TDD. After mutation testing confirms test strength, assess if refactoring adds value.
Having a working baseline before refactoring:
Workflow:
| Priority | Action | Examples | | -------- | ------------ | --------------------------------------------------- | | Critical | Fix now | Mutations, knowledge duplication, >3 levels nesting | | High | This session | Magic numbers, unclear names, >30 line functions | | Nice | Later | Minor naming, single-use helpers | | Skip | Don't change | Already clean code |
Abstract when:
Keep separate when:
// After MUTATE + KILL MUTANTS:
const enrichMachine = (machine: GeneratedMachine, prng: Prng): GeneratedMachine => {
const users = generateUsers(prng, machine.role);
const guestChance = machine.role === 'database' ? 0.5 : 0.3;
const hasGuest = prng.next() < guestChance;
return { ...machine, users: hasGuest ? [...users, generateGuestUser(prng)] : users };
};
// ASSESSMENT:
// ⚠️ High: Magic numbers 0.5, 0.3 → extract constants (GUEST_CHANCE_DB, GUEST_CHANCE_DEFAULT)
// ✅ Skip: Structure is clear enough
// DECISION: Extract constants only
If code isn't driven by a failing test, don't write it.
Key lesson: Every line must have a test that demanded its existence.
❌ Speculative code examples:
✅ Correct approach: Delete speculative code. If the behavior is needed, write a failing test that demands it, then implement.
// ❌ WRONG - Speculative error handling (no test demands this)
if (machine.ports.length === 0) {
throw new Error('Machine has no ports'); // No test for this path!
}
// ✅ CORRECT - Test-driven error handling
// First: write a test that expects this behavior
// Then: implement the guard clause to make it pass
Don't refactor when:
Remember: Refactoring should improve code structure without changing behavior.
refactor: extract permission validation helpers
refactor: simplify NAT resolution flow
refactor: rename ambiguous PRNG parameter names
Format: refactor: <what was changed>
Note: Refactoring commits should NOT be mixed with feature commits.
development
TypeScript strict mode patterns including schema-first development, branded types, type vs interface guidance, and tsconfig strict flags. Use when writing TypeScript code, defining types or schemas, or reviewing type safety. For immutability and pure function patterns, see the functional skill.
development
Testing patterns for behavior-driven tests. Use when writing tests, creating test factories, structuring test files, or deciding what to test. Do NOT use for UI-specific testing (see front-end-testing or react-testing skills).
testing
Evaluates test quality using Dave Farley's 8 properties. Use when reviewing tests, assessing test suite quality, or analyzing test effectiveness against TDD best practices.
development
Test-Driven Development workflow. Use for ALL code changes - features, bug fixes, refactoring. TDD is non-negotiable.