plugins/ce/skills/refactoring-code/SKILL.md
Improves code structure while preserving behavior through test verification. Use when cleaning up code, reducing duplication, simplifying complexity, or reorganizing modules.
npx skillsauth add rileyhilliard/claude-essentials refactoring-codeInstall 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.
Core principle: Refactoring changes structure, not functionality. If behavior changes, you're rewriting.
Target: If $ARGUMENTS is provided, use it as the refactoring target. Otherwise, check for unstaged changes. If none, diff against main: git diff --name-only $([ "$(git rev-parse --abbrev-ref HEAD)" = "main" ] && echo "HEAD^" || echo "main...HEAD")
Refactoring Progress:
- [ ] Phase 1: Understand current behavior
- [ ] Phase 2: Verify behavior-driven tests exist
- [ ] Phase 3: Identify issues
- [ ] Phase 4: Plan incremental steps
- [ ] Phase 5: Execute with continuous verification
Tests must verify BEHAVIOR, not implementation:
// ✅ Behavior-driven - survives refactoring
test('displays error when API returns 404', async () => {
server.use(http.get('/api/users', () => new HttpResponse(null, { status: 404 })));
render(<UserList />);
expect(await screen.findByText(/not found/i)).toBeInTheDocument();
});
// ❌ Implementation-detail - breaks during refactoring
test('sets error state', () => {
wrapper.instance().handleError(new Error('404'));
expect(wrapper.state('error')).toBe('404');
});
If tests are missing: Add behavior-driven tests first using Skill(ce:writing-tests).
| Issue | Indicators | Fix |
|-------|------------|-----|
| Complexity | Deep nesting, >50 line functions | Extract smaller functions |
| Duplication | Copy-pasted code | Extract shared utility |
| Poor naming | x, data, temp | Rename to intent |
| Type gaps | any types, assertions | Add proper types |
If something breaks: STOP. Use Skill(ce:systematic-debugging). Don't proceed until understood.
| Smell | Refactoring | |-------|-------------| | Long function | Extract smaller functions | | Duplicate code | Extract to shared utility | | Deep nesting | Early returns, guard clauses | | Magic numbers | Named constants | | Large component | Split into smaller components | | Long parameter list | Parameter object |
Stop when code is clear, duplication eliminated, types explicit, tests pass.
Don't continue if:
For React/TypeScript patterns, see references/react-typescript.md.
development
Selects and applies professional journalistic story structures (WSJ Formula, Inverted Pyramid, Hourglass, Tick-Tock, etc.) based on the content being written. Use when writing articles, blog posts, features, essays, long-form content, news stories, trend pieces, investigative reports, profiles, or any narrative prose longer than a few paragraphs. Also use when the user asks for help structuring a piece, choosing a story framework, organizing a draft, outlining an article, or wants to know which article format fits their content. Trigger on requests like "help me structure this," "what format should I use," "write a feature about," "draft a blog post on," or any mention of story structure, article architecture, or narrative frameworks. Complements the writer skill (which handles tone and anti-AI rhetoric) by providing the structural blueprint.
testing
Writing style and tone guide for human-sounding content. Use when writing documentation, READMEs, commit messages, PR descriptions, blog posts, LinkedIn posts, social media content, or any user-facing content.
data-ai
Create implementation plans with tasks grouped by subsystem. Related tasks share agent context; groups parallelize across subsystems.
development
Debugging framework that finds root causes before proposing fixes. Use when investigating bugs, errors, unexpected behavior, failed tests, or when previous fixes haven't worked.