Review frontend code to check for best practices, potential errors, and improvement suggestions.
Instructions
- Read the specified file or directory
- Check the following aspects:
- Code style consistency (ESLint, Prettier, etc.)
- Potential bugs or errors
- Performance issues
- Security vulnerabilities
- Readability and maintainability
- Frontend-specific issues (such as React hooks rules, state management, component design, etc.)
- TypeScript type safety
- CSS/styling best practices
- Provide specific improvement suggestions
Review points
JavaScript/TypeScript
- Check for unused variables and imports
- Ensure asynchronous operations are used correctly (async/await, Promise)
- Check whether error handling is complete
- Verify that React hooks are used in compliance with the rules
- Check whether state management is reasonable
- Ensure component design follows the single responsibility principle
Performance
- Check for unnecessary component re-renders
- Verify whether appropriate memoization is used
- Check for memory leak risks
- Ensure resources (such as event listeners) are properly cleaned up
Security
- Check for XSS vulnerabilities (such as the use of dangerouslySetInnerHTML)
- Verify that user input is properly validated and escaped
- Check whether API calls are secure
Accessibility
- Check whether appropriate ARIA attributes are used
- Verify the use of semantic HTML tags
- Ensure keyboard navigation support
TypeScript
- Check whether type definitions are complete and accurate
- Verify that abuse of the any type is avoided
- Ensure interfaces and type definitions are clear
Output Format
- Issue severity: 🔴 Critical | 🟡 Warning | 🔵 Suggestion
- Specific location and code snippet
- Issue description
- Improvement suggestions and example code
- Links to related best practices (if applicable)
Examples
Critical issue example
🔴 严重: 潜在 XSS 漏洞
文件: src/components/UserProfile.tsx:25
问题: 使用了 dangerouslySetInnerHTML 且未对内容进行适当清理
建议: 使用 React 组件替代或对内容进行适当的 HTML 转义
Warning issue example
🟡 警告: 性能问题
文件: src/components/ItemList.tsx:42
问题: 在渲染循环中创建新函数,可能导致不必要的重渲染
建议: 将函数移出渲染函数或使用 useCallback 包装
Suggestion for improvement example
🔵 建议: 代码可读性
文件: src/utils/helpers.ts:15
问题: 函数名称不够描述性
建议: 将函数名从 processData 更改为更具体的 transformUserData