.claude/skills/refactoring/SKILL.md
Improve code structure without changing behavior. Use when refactoring, cleaning up, simplifying, extracting methods, reducing complexity, removing duplication, or applying DRY principle. Also trigger when files exceed size limits or code smell is detected.
npx skillsauth add dmitryprg-ai/cursor-develop-autorules 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.
Principle: Change structure, not behavior.
If behavior changes, it's not refactoring — it's a feature or bugfix. Mixing both in one commit makes it impossible to tell what changed intentionally vs what broke.
| Refactor When | Do NOT When | |---------------|-------------| | Code works but is hard to understand | Code doesn't work yet (fix first) | | Duplicated code exists | No tests exist (write tests first) | | Long methods (50+ lines) | Under time pressure (risk too high) | | Deep nesting (3+ levels) | "Just because" (needs a reason) |
Tests must exist before refactoring because refactoring without tests is gambling — you have no way to verify behavior stayed the same. Each change should be small enough that if tests break, you know exactly which change caused it.
| Code Smell | Refactoring | |------------|-------------| | Long Method (50+ lines) | Extract Method | | Duplicate Code | Extract shared function/class | | Long Parameter List (4+) | Parameter Object | | Deep Nesting (3+ levels) | Guard Clauses (early return) | | Magic Numbers | Extract Constant |
Plan splitting before the file grows too large:
Split by business domain, not technical layer. CustomerValidation and CustomerFormatting are better than validation-utils and format-utils.
development
Scan codebase for technical debt and fix safely with TDD. Use to find oversized files, duplicated code, code smells, and refactor safely. Workflow - SCAN, TEST CASES, REFACTOR, VERIFY. Keywords - techdebt, tech debt, duplicates, code quality audit.
development
Test-Driven Development workflow with strict Red-Green-Refactor cycle. Use when developing features with TDD, writing tests before code, or when test-driven approach is needed. MANDATORY order - test cases table BEFORE code, failing tests BEFORE implementation.
testing
Review work session quality and capture improvements. Use at end of session, after large tasks, after series of errors, or when user asks for session review, retrospective, lessons learned. Records improvements to backlog.
data-ai
Analyze data, investigate datasets, work with CSV/parquet/pandas/dataframes. Use when analyzing data, exploring datasets, running experiments, or when user mentions data, analysis, parquet, csv, pandas, dataframe, statistics, investigation.