用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/htlin222/dotfiles --skill refactor命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | refactor |
| description | Refactor code for quality and maintainability. Use for cleanup and tech debt reduction. |
Improve code quality without changing behavior.
// Before
function processOrder(order) {
// 50 lines of validation
// 30 lines of calculation
// 20 lines of notification
}
// After
function processOrder(order) {
validateOrder(order);
const total = calculateTotal(order);
notifyCustomer(order, total);
}
// Before
function getPrice(type) {
if (type === "regular") return basePrice;
if (type === "premium") return basePrice * 1.5;
if (type === "vip") return basePrice * 0.8;
}
// After
const pricingStrategies = {
regular: (base) => base,
premium: (base) => base * 1.5,
vip: (base) => base * 0.8,
};
const getPrice = (type) => pricingStrategies[type](basePrice);
// Before
function getUserName(user) {
return user?.profile?.name ?? "Unknown";
}
function getOrderName(order) {
return order?.customer?.name ?? "Unknown";
}
// After
const getName = (obj, path) => path.reduce((o, k) => o?.[k], obj) ?? "Unknown";
const getUserName = (user) => getName(user, ["profile", "name"]);
const getOrderName = (order) => getName(order, ["customer", "name"]);
| Smell | Symptom | Refactoring |
|---|---|---|
| Long Function | >20 lines | Extract Function |
| Large Class | >200 lines | Extract Class |
| Duplicate Code | Same logic repeated | Extract and reuse |
| Long Parameter | >3 params | Use object/builder |
| Feature Envy | Uses other class's data | Move method |
| Primitive Obsession | Strings for everything | Create value objects |
Input: "This function is too long" Action: Identify logical sections, extract into focused functions, verify tests pass
Input: "Reduce duplication in these files" Action: Find common patterns, extract shared utilities, update call sites
基于 SOC 职业分类