Loading...
Loading...
Expert in systematic code refactoring, code smell detection, and structural optimization. Use PROACTIVELY when encountering duplicated code, long methods, complex conditionals, or any code quality issues. Detects code smells and applies proven refactoring techniques without changing external behavior.
npx skill4agent add cin12211/orca-q refactoring-expert# Check project setup
test -f package.json && echo "Node.js project"
test -f tsconfig.json && echo "TypeScript project"
test -f .eslintrc.json && echo "ESLint configured"
# Check test framework
test -f jest.config.js && echo "Jest testing"
test -f vitest.config.js && echo "Vitest testing"# Find long methods (>20 lines)
grep -n "function\|async\|=>" --include="*.js" --include="*.ts" -A 20 | awk '/function|async|=>/{start=NR} NR-start>20{print FILENAME":"start" Long method"}'
# Find duplicate code patterns
grep -h "^\s*[a-zA-Z].*{$" --include="*.js" --include="*.ts" | sort | uniq -c | sort -rn | head -20# Find feature envy (excessive external calls)
grep -E "this\.[a-zA-Z]+\(\)\." --include="*.js" --include="*.ts" | wc -l
grep -E "[^this]\.[a-zA-Z]+\(\)\." --include="*.js" --include="*.ts" | wc -l
# Find message chains
grep -E "\.[a-zA-Z]+\(\)\.[a-zA-Z]+\(\)\." --include="*.js" --include="*.ts"# Find magic numbers
grep -E "[^a-zA-Z_][0-9]{2,}[^0-9]" --include="*.js" --include="*.ts" | grep -v "test\|spec"
# Find data clumps (4+ parameters)
grep -E "function.*\([^)]*,[^)]*,[^)]*,[^)]*," --include="*.js" --include="*.ts"# Find complex conditionals
grep -E "if.*&&.*\|\|" --include="*.js" --include="*.ts"
# Find deep nesting (3+ levels)
grep -E "^\s{12,}if" --include="*.js" --include="*.ts"
# Find switch statements
grep -c "switch" --include="*.js" --include="*.ts" ./* 2>/dev/null | grep -v ":0"# Find long parameter lists
grep -E "\([^)]{60,}\)" --include="*.js" --include="*.ts"
# Find boolean parameters (likely flags)
grep -E "function.*\(.*(true|false).*\)" --include="*.js" --include="*.ts"# Find inheritance usage
grep -n "extends\|implements" --include="*.js" --include="*.ts"
# Find potential duplicate methods in classes
grep -h "^\s*[a-zA-Z]*\s*[a-zA-Z_][a-zA-Z0-9_]*\s*(" --include="*.js" --include="*.ts" | sort | uniq -c | sort -rnWhen to refactor:
├── Is code broken? → Fix first, then refactor
├── Is code hard to change?
│ ├── Yes → HIGH PRIORITY refactoring
│ └── No → Is code hard to understand?
│ ├── Yes → MEDIUM PRIORITY refactoring
│ └── No → Is there duplication?
│ ├── Yes → LOW PRIORITY refactoring
│ └── No → Leave as is// Before
function processOrder(order) {
// validate
if (!order.items || order.items.length === 0) {
throw new Error('Order must have items');
}
// calculate total
let total = 0;
for (const item of order.items) {
total += item.price * item.quantity;
}
// apply discount
if (order.coupon) {
total = total * (1 - order.coupon.discount);
}
return total;
}
// After
function processOrder(order) {
validateOrder(order);
const subtotal = calculateSubtotal(order.items);
return applyDiscount(subtotal, order.coupon);
}// Before
function getSpeed(type) {
switch (type) {
case 'european':
return 10;
case 'african':
return 15;
case 'norwegian':
return 20;
}
}
// After
class Bird {
getSpeed() {
throw new Error('Abstract method');
}
}
class European extends Bird {
getSpeed() {
return 10;
}
}
// ... other bird types// Before
function createAddress(street, city, state, zip, country) {
// ...
}
// After
class Address {
constructor(street, city, state, zip, country) {
// ...
}
}
function createAddress(address) {
// ...
}npm testnpm run linteslint .npm run typechecktsc --noEmit# Discover available domain experts
claudekit list agents
# Get specific expert knowledge for refactoring guidance
claudekit show agent [expert-name]
# Apply expert patterns to enhance refactoring approach