Restructure code to improve quality without changing behavior
Restructures code to improve quality, readability, and maintainability without changing behavior.
/plugin marketplace add TheBushidoCollective/han/plugin install jutsu-scratch@hanhan-core:refactor - Restructure code to improve quality without changing behavior
/refactor [arguments]
Restructure code to improve quality without changing behavior
Improve code structure, readability, and maintainability without changing external behavior.
Use the refactoring skill from bushido to:
Safety first:
When to refactor:
When NOT to refactor:
Extract Function:
// Before
function processOrder(order) {
const tax = order.subtotal * 0.08
const shipping = order.items.length > 5 ? 0 : 9.99
const total = order.subtotal + tax + shipping
return total
}
// After
function processOrder(order) {
const tax = calculateTax(order.subtotal)
const shipping = calculateShipping(order.items)
return order.subtotal + tax + shipping
}
function calculateTax(subtotal) {
return subtotal * 0.08
}
function calculateShipping(items) {
return items.length > 5 ? 0 : 9.99
}
Eliminate Duplication:
// Before
function formatUserName(user) {
return `${user.firstName} ${user.lastName}`
}
function formatAuthorName(author) {
return `${author.firstName} ${author.lastName}`
}
// After
function formatFullName(person) {
return `${person.firstName} ${person.lastName}`
}
Simplify Conditionals:
// Before
if (user.role === 'admin' || user.role === 'moderator' || user.role === 'super_admin') {
// ...
}
// After
const PRIVILEGED_ROLES = ['admin', 'moderator', 'super_admin']
if (PRIVILEGED_ROLES.includes(user.role)) {
// ...
}
When the user says:
# 1. Ensure tests pass
npm test
# 2. Make ONE refactoring change
# (extract function, rename, remove duplication, etc.)
# 3. Run tests again
npm test
# 4. Commit
git add .
git commit -m "refactor: extract calculateTax function"
# 5. Repeat for next change
After refactoring:
## Refactoring: [Brief description]
### Before
[Description of code smell or issue]
### Changes Made
- [Change 1 with reasoning]
- [Change 2 with reasoning]
- [Change 3 with reasoning]
### After
[How the code is better now]
### Verification
[Evidence that behavior unchanged - use proof-of-work skill]
- All tests pass: [test output]
- No functionality changed
- Code is more [readable/maintainable/simple]
/refactorPerforms safe, step-by-step code refactoring with quantitative SOLID principles evaluation. Visualizes technical debt and clarifies improvement priorities.