From code-standards
Auto-refactor code to fix standards violations (conservative mode)
How this command is triggered — by the user, by Claude, or both
Slash command
/code-standards:fix [file-or-directory]This command is limited to the following tools:
The summary Claude sees in its command listing — used to decide when to auto-load this command
# Code Standards Fix Auto-refactor $ARGUMENTS to fix code standards violations. Uses conservative mode - shows plan first, asks for confirmation before each change. If no argument provided, analyze and offer to fix violations in the current directory. ## Fix Process ### Step 1: Analyze Violations First, perform the same analysis as `/code-standards:check` to identify all violations. Categorize violations by type: - **File too large** - needs splitting - **Function too large** - needs extraction - **High complexity** - needs simplification - **Mixed responsibilities** - needs separatio...
Auto-refactor $ARGUMENTS to fix code standards violations. Uses conservative mode - shows plan first, asks for confirmation before each change.
If no argument provided, analyze and offer to fix violations in the current directory.
First, perform the same analysis as /code-standards:check to identify all violations.
Categorize violations by type:
For each violation, propose a specific fix:
## Fix Plan
Found 4 violations in $ARGUMENTS. Here's the proposed fix plan:
### 1. Split `src/services/order.ts` (912 LOC → ~300 LOC each)
**Current:** Single file handling all order logic
**Proposed:** Split into 3 files:
- `src/services/order-creation.ts` - createOrder, validateOrder
- `src/services/order-processing.ts` - processOrder, handlePayment
- `src/services/order-fulfillment.ts` - shipOrder, trackOrder
**Impact:**
- Creates 3 new files
- Updates imports in 5 dependent files
- Original file will be deleted
### 2. Extract from `processPayment` (complexity 22 → ~8 each)
**Current:** Large switch statement for payment methods
**Proposed:** Strategy pattern with separate handlers:
- `PaymentProcessor` interface
- `CreditCardProcessor`, `PayPalProcessor`, `BankTransferProcessor`
**Impact:**
- Creates 4 new classes
- Simplifies `processPayment` to dispatcher
### 3. Extract validation from `createUser` (78 LOC → ~25 LOC)
**Current:** Validation mixed with user creation
**Proposed:** Extract to `validateUserData()` function
**Impact:**
- Adds 1 new function
- Reduces `createUser` by ~50 LOC
### 4. Split `formatData` helper (62 LOC → ~20 LOC each)
**Current:** Handles multiple data types in one function
**Proposed:** Split by type:
- `formatUserData()`, `formatOrderData()`, `formatProductData()`
**Impact:**
- Adds 3 new functions
- Original function becomes dispatcher
---
**Total changes:** 3 file splits, 2 function extractions, 8 new functions/classes
Use AskUserQuestion for each proposed fix:
Question: "Apply fix #1: Split order.ts into 3 files?"
If "Modify approach", ask what changes they want to the proposed fix.
Before applying fixes:
git stash or commit your changes before applying fixes for easy rollback."For each confirmed fix:
On failure:
git diff."After all fixes:
## Fix Summary
**Applied:** 3 of 4 proposed fixes
**Skipped:** 1 fix (user choice)
### Changes Made
| Fix | Status | Files Changed |
|-----|--------|---------------|
| Split order.ts | Applied | Created 3 files, updated 5 imports |
| Extract payment strategies | Applied | Created 4 classes |
| Extract user validation | Applied | Added 1 function |
| Split formatData | Skipped | - |
### New Files Created
- `src/services/order-creation.ts`
- `src/services/order-processing.ts`
- `src/services/order-fulfillment.ts`
- `src/services/payments/processor.ts`
- `src/services/payments/credit-card.ts`
- `src/services/payments/paypal.ts`
- `src/services/payments/bank-transfer.ts`
### Next Steps
1. Run tests to verify changes
2. Review new file organization
3. Consider adding tests for extracted functions
Reference the skill's references/refactoring-patterns.md for detailed patterns:
npx claudepluginhub hculap/better-code --plugin code-standards/refactor-guidedGuides safe, incremental code refactoring with test verification at each step. Accepts a target file, directory, or description of the refactoring to perform.
/sc-refactorPlans and executes behavior-preserving code refactorings. Automatically detects whether to analyze code for opportunities or perform a specific refactoring (extract, rename, simplify) with pre/post test verification.
/refactorAnalyzes PHP code for smells, SOLID violations, testability issues, and readability, then provides a prioritized refactoring roadmap with automated fix generation commands.
/fixIteratively repairs errors in a project — one fix per iteration, atomic, auto-reverted on failure. Supports bounded iterations, targeted categories, and custom verify/guard commands.
/fixFixes problems via two modes: quick fix (locate → fix → verify) or systematic debug (reproduce → hypothesize → validate → report, read-only).
/fixAuto-fixes code review findings: dispatches agents, post-reviews, commits survivors, reverts regressions, and updates artifact. Supports threshold gating and granular commits.