用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/aiskillstore/marketplace --skill clean-code命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Maintain a portable task-state ledger for long, multi-step work. Use when a task spans many files, produces large logs, needs a reliable handoff, or requires traceable evidence without repeatedly loading full outputs. Creates concise state records and private evidence references with explicit limits, redaction checks, and retention guidance.
【收纳储物必看】装修前不会规划收纳,入住半年家变仓库?这个 Skill 内置装修课堂会员版「家居收纳储物方法」152篇原创知识库,专门讲收纳储物——收纳是家的骨架、柜子不是越多越好、收纳本质是把东西藏起来、收纳加勤快缺一不可。问玄关鞋柜怎么装、问厨房9个收纳位置、问衣柜衣帽间怎么做、问小户型怎么榨干每1平米、问收纳避坑和鸡肋神器,全部覆盖。适合正在装修、准备收纳规划、家里东西多总是乱、想做满墙柜/通顶柜/800库的业主。
【儿童房装修必看】家里有小孩、正准备要孩子、或想给儿童房做环保安全装修?这个 Skill 内置装修课堂知识库,专门讲"适童化"——儿童是最易受甲醛伤害的人群,儿童房必须实木/ENF/控总量。问儿童房怎么装环保、问儿童房墙面地面用什么、问儿童家具选实木还是人造板、问孩子学习/游戏专区怎么规划、问有娃家庭怎么防磕碰防污染,全部覆盖。适合家里有娃、备孕婚房、想装出健康儿童房的业主。
正在显示 SKILL.md
基于 SOC 职业分类
| name | clean-code |
| description | Clean code principles adapted for TypeScript-first, functional development. |
Clean code principles adapted for TypeScript-first, functional development.
Every piece of knowledge should have a single, unambiguous representation.
// Bad: Duplicated validation logic
const validateUserEmail = (email: string) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
const isValidEmail = (email: string) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
// Bad: Magic numbers everywhere
if (password.length < 8) { ... }
if (retries > 3) { ... }
if (timeout > 30000) { ... }
// Good: Single source of truth
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const validateEmail = (email: string): boolean => EMAIL_REGEX.test(email);
// Good: Named constants
const PASSWORD_MIN_LENGTH = 8;
const MAX_RETRIES = 3;
const REQUEST_TIMEOUT_MS = 30_000;
if (password.length < PASSWORD_MIN_LENGTH) { ... }
if (retries > MAX_RETRIES) { ... }
if (timeout > REQUEST_TIMEOUT_MS) { ... }
// Before: Duplicated fetch logic
const fetchUsers = async () => {
const response = await fetch('/api/users');
if (!response.ok) throw new Error('Failed to fetch');
return response.json();
};
const fetchOrders = async () => {
const response = await fetch('/api/orders');
if (!response.ok) throw new Error('Failed to fetch');
return response.json();
};
// After: Extracted common logic
const fetchJson = async <T>(url: string): Promise<T> => {
const response = await fetch(url);
if (!response.ok) throw new Error(`Failed to fetch: ${url}`);
return response.json();
};
const = () => fetchJson<[]>();
= () => fetchJson<[]>();
Prefer simple solutions over clever ones. Complexity should be justified.
// Bad: Overly clever one-liner
const transform = (arr: number[]) =>
arr.reduce((acc, val, idx) => ({ ...acc, [idx]: val ** 2 }), {});
// Bad: Premature abstraction
interface DataTransformer<T, U> {
transform(input: T): U;
validate(input: T): boolean;
normalize(input: T): T;
}
class UserNameTransformer implements DataTransformer<User, string> {
// 50 lines for a simple name extraction...
}
// Good: Clear and readable
const squareValues = (arr: number[]): Record<number, number> => {
const result: Record<number, number> = {};
for (let i = 0; i < arr.length; i++) {
result[i] = arr[i] ** 2;
}
return result;
};
// Good: Simple function for simple task
const getUserFullName = (user: User): string =>
`${user.firstName} ${user.lastName}`;
// Before: Complex nested conditions
const getDiscount = (user: User, order: Order) => {
if (user.isPremium) {
if (order.total > 100) {
if (order.items.length > 5) {
return 0.25;
}
return 0.20;
}
return 0.15;
} else {
if (order.total > 200) {
return 0.10;
}
return 0;
}
};
// After: Early returns, clear conditions
const getDiscount = (user: User, order: Order): number => {
if (!user.isPremium) {
return order.total > 200 ? 0.10 : 0;
}
if (order.total <= 100) return 0.15;
if (order.items.length > ) ;
;
};
Don't build features until they're actually needed.
// Bad: Configurable everything "just in case"
interface UserServiceConfig {
maxRetries: number;
retryDelay: number;
cacheEnabled: boolean;
cacheTTL: number;
logLevel: 'debug' | 'info' | 'warn' | 'error';
metricsEnabled: boolean;
circuitBreakerThreshold: number;
// ... 20 more options never used
}
// Bad: Premature generalization
const createGenericCRUDService = <T extends Entity>(
repository: Repository<T>,
validator: Validator<T>,
transformer: Transformer<T>,
hooks: Hooks<T>,
cache: Cache<T>,
) => { ... };
// Used only for User entity
// Good: Build what you need now
const createUserService = (db: Database) => ({
findById: (id: string) => db.users.findFirst({ where: { id } }),
create: (data: CreateUserData) => db.users.create({ data }),
});
// Good: Add features when needed
// v1: Simple implementation
const fetchData = async (url: string) => {
const response = await fetch(url);
return response.json();
};
// v2: Add retry only when you actually need it
const fetchDataWithRetry = async (url: string, retries = 3) => {
for (let i = 0; i < retries; i++) {
try {
const response = await fetch(url);
return response.json();
} catch (error) {
(i === retries - ) error;
}
}
};
// Bad
const d = new Date();
const u = getUser();
const doStuff = () => { ... };
// Good
const createdAt = new Date();
const currentUser = getUser();
const sendNotification = () => { ... };
// Bad: Does multiple things
const processUser = async (user: User) => {
// Validate
// Transform
// Save
// Notify
// Log
// 100 lines...
};
// Good: Single purpose, small
const validateUser = (user: User): Result<User, ValidationError> => { ... };
const saveUser = (db: Database) => (user: User): Promise<User> => { ... };
const notifyUser = (notifier: Notifier) => (user: User): Promise<void> => { ... };
// Bad: Swallowing errors
try {
await riskyOperation();
} catch (e) {
console.log('error');
}
// Bad: Generic error
throw new Error('Something went wrong');
// Good: Typed errors with context
type OperationError =
| { code: 'VALIDATION_FAILED'; field: string; message: string }
| { code: 'NOT_FOUND'; resourceId: string }
| { code: 'PERMISSION_DENIED'; userId: string; action: string };
const performOperation = (): Result<Data, OperationError> => {
if (!isValid(input)) {
return Result.fail({
code: 'VALIDATION_FAILED',
field: 'email',
message: 'Invalid email format',
});
}
// ...
};
// Bad: Obvious comments
// Increment counter
counter++;
// Add user to array
users.push(user);
// Good: Explain WHY, not WHAT
// Skip validation for admin users per security policy SEC-123
if (user.role === 'admin') return true;
// Using insertion sort because array is nearly sorted (< 10 elements typically)
insertionSort(items);
// Bad: Inconsistent, hard to scan
const config={debug:true,timeout:1000,retries:3};
// Good: Consistent, easy to scan
const config = {
debug: true,
timeout: 1000,
retries: 3,
};
src/
api/ # HTTP layer (Express/Fastify handlers)
routes/
middleware/
services/ # Business logic (pure when possible)
repositories/ # Data access
types/ # Shared type definitions
utils/ # Pure utility functions
// Pure core - easy to test
const calculateOrderTotal = (items: OrderItem[]): number =>
items.reduce((sum, item) => sum + item.price * item.quantity, 0);
const validateOrder = (order: Order): Result<Order, ValidationError> => {
if (!order.items.length) return Result.fail({ code: 'EMPTY_ORDER' });
return Result.ok(order);
};
// Impure shell - handles I/O
const createOrderHandler = (deps: Dependencies) =>
async (req: Request, res: Response) => {
const validation = validateOrder(req.body);
if (validation.isFailure) {
return res.status(400).json(validation.error);
}
const total = (validation..);
saved = deps..({ ...validation., total });
res.().(saved);
};