一键导入
react-quality
React/TypeScript code quality rules for kattle frontend. Apply when writing or reviewing frontend code.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
React/TypeScript code quality rules for kattle frontend. Apply when writing or reviewing frontend code.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Create a git worktree for a new TASK. Use when starting a new feature, fix, or refactor task that requires isolated development.
Go code quality rules and standards for kattle project. Apply when writing or reviewing Go code.
macOS native memory analysis tools (leaks, heap, vmmap, Instruments). Use for native app memory debugging.
Memory profile snapshot capture and baseline comparison. Use for verification after memory optimization.
Go application memory profiling and analysis. Use when investigating memory leaks or high memory usage.
Run Go and frontend tests for kattle project. Use after code changes to verify correctness.
基于 SOC 职业分类
| name | react-quality |
| description | React/TypeScript code quality rules for kattle frontend. Apply when writing or reviewing frontend code. |
| disable-model-invocation | true |
| user-invocable | false |
| allowed-tools | Read, Edit, Write, Grep, Glob |
This skill enforces critical code quality standards for React and TypeScript in the kattle frontend. Apply these rules rigorously when writing, modifying, or reviewing components.
as)Rule: Use explicit type declarations instead of type assertions.
Why: Type assertions bypass TypeScript's type checking and hide potential bugs.
Bad:
const user = data as User;
const count = value as number;
Good:
const user: User = parseUserData(data);
const count: number = parseInt(value, 10);
Rule: Remove all unused imports from files.
Why: Clutters code, increases bundle size, and creates maintenance confusion.
Check: TypeScript will flag unused imports. Remove them during code review.
Rule: Always check for undefined before accessing array elements or object properties.
Why: Prevents runtime crashes from accessing undefined values.
Bad:
const item = items[0];
const name = user.profile.name; // what if user or profile is undefined?
Good:
const item = items?.[0];
const name = user?.profile?.name ?? 'Unknown';
Rule: Add type annotations for function parameters, return types, and complex state.
Why: Makes code self-documenting and catches type errors early.
Bad:
function processData(data) {
const result = { ...data };
return result;
}
const [state, setState] = useState({});
Good:
interface ProcessedData {
id: string;
timestamp: Date;
value: number;
}
function processData(data: unknown): ProcessedData {
const result: ProcessedData = { ...data as ProcessedData };
return result;
}
interface AppState {
user: User | null;
isLoading: boolean;
}
const [state, setState] = useState<AppState>({
user: null,
isLoading: false,
});
Rule: Always provide stable, unique keys in lists. Never use array indices.
Why: React uses keys to match elements across renders. Unstable keys cause state loss and bugs.
Bad:
{items.map((item, index) => (
<div key={index}>{item.name}</div>
))}
Good:
{items.map((item) => (
<div key={item.id}>{item.name}</div>
))}
Rule: Wrap event handler functions in useCallback to prevent unnecessary re-renders of child components.
Why: Prevents children from re-rendering when parent updates, improving performance.
Bad:
const handleClick = () => {
dispatch(updateState());
};
return <Button onClick={handleClick} />;
Good:
const handleClick = useCallback(() => {
dispatch(updateState());
}, [dispatch]);
return <Button onClick={handleClick} />;
Rule: Use the function form of setState when the new state depends on previous state.
Why: Ensures you're always working with the latest state, preventing race conditions.
Bad:
const [count, setCount] = useState(0);
const increment = () => setCount(count + 1);
Good:
const [count, setCount] = useState(0);
const increment = useCallback(() => {
setCount((prev) => prev + 1);
}, []);
Rule: Always include all external values used in hooks (useEffect, useCallback, useMemo) in their dependency arrays.
Why: Missing dependencies cause stale closures and bugs that are hard to debug.
Bad:
useEffect(() => {
console.log(userId); // userId is missing from deps!
fetchUser();
}, []);
Good:
useEffect(() => {
console.log(userId);
fetchUser();
}, [userId]);
Rule: Split components when they exceed 300 lines. Extract sections into separate components.
Why: Large components are hard to understand, test, and maintain.
Indicators of a "fat" component:
Action: Extract into smaller, focused components with clear interfaces.
Rule: Define explicit interfaces for component props. Never use any or unknown without narrowing.
Why: Makes component contracts clear and catches prop errors early.
Bad:
function Card(props: any) {
return <div>{props.content}</div>;
}
Good:
interface CardProps {
content: string;
variant?: 'default' | 'outlined';
onClick?: (id: string) => void;
}
function Card({ content, variant = 'default', onClick }: CardProps) {
return <div onClick={() => onClick?.(content)}>{content}</div>;
}
Before submitting code or approving a PR, verify:
as type assertionskey propsuseCallback (if passed to children)any types without narrowingApply these rules when:
Prioritize rules 1-8 as they prevent the most common and serious bugs.