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/sc-refactorPlans refactoring opportunities in code or executes specific behavior-preserving refactors like extract/rename/simplify, verifying with tests before/after.
/refactorAnalyzes PHP code for smells, SOLID violations, testability issues, readability problems, and provides prioritized refactoring roadmap with generation commands.
/refactor-guidedPerforms safe incremental refactoring on target files directories or descriptions verifying tests at each step with git commits and reverts.
/refactorRefactors code or file via structured workflow (analyze quality/smells, plan changes, add tests, refactor incrementally, verify with tests/report). Outputs analysis/plan/logs. Also supports component and performance modes.
/fixIteratively repairs code errors until zero remain via autonomous loop, applying one atomic fix per iteration with auto-revert on failure. Supports --target, --scope, --category, --iterations flags.
/fixFixes issues automatically by locating root cause, applying minimal changes, and running tests. Also supports systematic debug mode (/fix debug) for analysis without code changes.