react-native-doctor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseReact Native Doctor
React Native Doctor
Scans your React Native and Expo codebase for performance, accessibility, architecture, correctness, and security issues. Outputs a 0–100 score with actionable diagnostics.
扫描你的React Native和Expo代码库,检测性能、可访问性、架构、正确性及安全性问题。输出0-100分的评分,并提供可执行的诊断建议。
Usage
使用方法
bash
npx -y react-native-doc@latest . --verboseFor Expo projects:
bash
npx -y react-native-doc@latest . --verbose --expo-onlybash
npx -y react-native-doc@latest . --verbose针对Expo项目:
bash
npx -y react-native-doc@latest . --verbose --expo-onlyWorkflow
工作流程
- Run the command above at the project root
- Read every diagnostic with file paths and line numbers
- Fix issues starting with errors (highest severity)
- Re-run to verify the score improved
- 在项目根目录运行上述命令
- 查看包含文件路径和行号的每一条诊断信息
- 优先修复错误级别的问题(最高严重性)
- 重新运行工具验证评分是否提升
Rules (70+)
检测规则(70+条)
React Native
React Native
- Correctness: raw text outside , deprecated modules, removed APIs (
<Text>)Dimensions.get - Performance: inline functions, missing
renderItem,keyExtractorfor long lists, inline style objects, anonymous JSX callbacks, heavy array chains in render, single-element style arrays, missingScrollViewon list items,React.memoAPI (preferAnimated)react-native-reanimated - Architecture: legacy shadow properties, hardcoded screen dimensions instead of , excessive
useWindowDimensions()branching, hardcoded colors, prop drilling, god components, unnecessaryPlatform.OSfor derived stateuseEffect - Images: missing explicit width/height on
<Image>
- 正确性:<Text>组件外的纯文本、已弃用模块、已移除API(如)
Dimensions.get - 性能:内联函数、缺失
renderItem、长列表使用keyExtractor、内联样式对象、匿名JSX回调、渲染中的复杂数组链式调用、单元素样式数组、列表项缺失ScrollView、使用React.memoAPI(推荐使用Animated)react-native-reanimated - 架构:遗留阴影属性、硬编码屏幕尺寸(应使用)、过多
useWindowDimensions()分支、硬编码颜色、属性透传、上帝组件、不必要的Platform.OS用于派生状态useEffect - 图片:<Image>组件缺失明确的宽/高
Accessibility
可访问性
- Missing on touchable elements
accessibilityLabel - Missing on interactive components
accessibilityRole - Non-descriptive labels ("button", "tap here", etc.)
- Images without +
accessibleaccessibilityLabel - Small tap targets without (< 44pt)
hitSlop
- 可触摸元素缺失
accessibilityLabel - 交互组件缺失
accessibilityRole - 非描述性标签(如“button”、“tap here”等)
- 图片未设置+
accessibleaccessibilityLabel - 小点击目标未设置(小于44pt)
hitSlop
Navigation (React Navigation)
导航(React Navigation)
- Inline component definitions in
Stack.Screen - Missing defaults on navigators
screenOptions
- 在中内联定义组件
Stack.Screen - 导航器缺失默认配置
screenOptions
Expo
Expo
- Hardcoded colors without dark mode support
useColorScheme() - →
Constants.manifestConstants.expoConfig - missing
_layout.tsxexportErrorBoundary - Hardcoded API keys in source code
- Missing for Expo Router
app/+not-found.tsx
- 硬编码颜色,未通过支持深色模式
useColorScheme() - 应替换为
Constants.manifestConstants.expoConfig - 缺失
_layout.tsx导出ErrorBoundary - 源代码中硬编码API密钥
- Expo Router缺失
app/+not-found.tsx
React (applies to all projects)
React(适用于所有项目)
- Security: , secrets in client bundle
eval() - State & Effects: derived state in , cascading
useEffect, missing deps,setStatein effects, unnecessaryfetchfor derived stateuseEffect - Architecture: nested component definitions, giant components (>200 lines)
- Performance: missing /
useMemo, non-lazy state init, inline objects to memoized componentsuseCallback - Bundle Size: barrel imports, full lodash,
moment.js - Dead Code: unused files, exports, types
- 安全性:使用、客户端包中包含密钥
eval() - 状态与副作用:在中处理派生状态、级联
useEffect、缺失依赖项、在副作用中使用setState、不必要的fetch用于派生状态useEffect - 架构:嵌套组件定义、巨型组件(超过200行)
- 性能:缺失/
useMemo、非惰性状态初始化、向已记忆组件传递内联对象useCallback - 包体积:桶式导入、完整引入lodash、使用
moment.js - 死代码:未使用的文件、导出、类型
Score
评分标准
- 75+: Great
- 50–74: Needs work
- 0–49: Critical
- 75分及以上:优秀
- 50-74分:需要改进
- 0-49分:严重问题
Fix with an AI agent
通过AI Agent自动修复
After scanning, hand off to an agent to fix all issues automatically.
扫描完成后,可交由Agent自动修复所有问题。
Ami
Ami
bash
npx -y react-native-doc@latest . --fixbash
npx -y react-native-doc@latest . --fixCline
Cline
bash
npx -y react-native-doc@latest . --clineIf the CLI is installed (), runs it directly. Otherwise copies the fix prompt to clipboard and opens VS Code/Cline extension.
clinenpm install -g clinebash
npx -y react-native-doc@latest . --cline若已安装 CLI(),则直接运行;否则会将修复提示复制到剪贴板,并打开VS Code/Cline扩展。
clinenpm install -g cline