Skip to content
Back to skills

Refactoring

ASecurity

AI-powered code refactoring and modernization. Use this skill for code cleanup, technical debt reduction, framework migration, and improving code quality.

  • 33 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added February 10, 2026
developmentjavascriptjavashellreactrefactoring

Works with

  • cli

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add lovedragonball/power-ranger-toolkit --skill refactoring --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Refactoring?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Refactoring
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/lovedragonball-refactoring/badge)](https://www.skillsdirectory.com/skills/lovedragonball-refactoring)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: refactoring
description: AI-powered code refactoring and modernization. Use this skill for code cleanup, technical debt reduction, framework migration, and improving code quality.
---

# 🔄 Refactoring Skill

## Refactoring Patterns

### 1. Extract Method/Function
```javascript
// Before ❌
function processOrder(order) {
  // 50 lines of validation
  // 30 lines of calculation
  // 20 lines of formatting
}

// After ✅
function processOrder(order) {
  const validated = validateOrder(order);
  const calculated = calculateTotal(validated);
  return formatOutput(calculated);
}
```

### 2. Simplify Conditionals
```javascript
// Before ❌
if (user && user.role === 'admin' || user && user.role === 'superadmin') {
  if (user.permissions && user.permissions.includes('write')) { ... }
}

// After ✅
const isAdmin = user?.role === 'admin' || user?.role === 'superadmin';
const canWrite = user?.permissions?.includes('write');
if (isAdmin && canWrite) { ... }
```

### 3. Remove Code Smells
| Code Smell | Solution |
|------------|----------|
| Magic Numbers | Extract to named constants |
| Long Parameters | Use object/options pattern |
| Duplicate Code | Extract to shared function |
| Dead Code | Delete unused code |
| Deep Nesting | Early return pattern |

---

## Framework Migration

### React Class → Functional
```javascript
// Before (Class)
class Counter extends Component {
  state = { count: 0 };
  increment = () => this.setState({ count: this.state.count + 1 });
  render() { return <button onClick={this.increment}>{this.state.count}</button> }
}

// After (Functional)
function Counter() {
  const [count, setCount] = useState(0);
  const increment = () => setCount(c => c + 1);
  return <button onClick={increment}>{count}</button>;
}
```

### CommonJS → ESM
```javascript
// Before (CommonJS)
const fs = require('fs');
module.exports = { readFile };

// After (ESM)
import fs from 'fs';
export { readFile };
```

---

## Refactoring Checklist

- [ ] มีหน่วยทดสอบก่อน refactor
- [ ] Refactor ทีละขั้น commit บ่อยๆ
- [ ] ไม่เปลี่ยน behavior เดิม
- [ ] Run tests หลังทุกการเปลี่ยนแปลง
- [ ] Code review อีกรอบ

## Commands

```powershell
# Find duplicate code
npx jscpd ./src

# Find unused exports
npx ts-unused-exports tsconfig.json

# Check complexity
npx eslint --rule 'complexity: ["error", 10]' ./src
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…