react-native-doctor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

React 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 . --verbose
For Expo projects:
bash
npx -y react-native-doc@latest . --verbose --expo-only
bash
npx -y react-native-doc@latest . --verbose
针对Expo项目:
bash
npx -y react-native-doc@latest . --verbose --expo-only

Workflow

工作流程

  1. Run the command above at the project root
  2. Read every diagnostic with file paths and line numbers
  3. Fix issues starting with errors (highest severity)
  4. Re-run to verify the score improved
  1. 在项目根目录运行上述命令
  2. 查看包含文件路径和行号的每一条诊断信息
  3. 优先修复错误级别的问题(最高严重性)
  4. 重新运行工具验证评分是否提升

Rules (70+)

检测规则(70+条)

React Native

React Native

  • Correctness: raw text outside
    <Text>
    , deprecated modules, removed APIs (
    Dimensions.get
    )
  • Performance: inline
    renderItem
    functions, missing
    keyExtractor
    ,
    ScrollView
    for long lists, inline style objects, anonymous JSX callbacks, heavy array chains in render, single-element style arrays, missing
    React.memo
    on list items,
    Animated
    API (prefer
    react-native-reanimated
    )
  • Architecture: legacy shadow properties, hardcoded screen dimensions instead of
    useWindowDimensions()
    , excessive
    Platform.OS
    branching, hardcoded colors, prop drilling, god components, unnecessary
    useEffect
    for derived state
  • Images: missing explicit width/height on
    <Image>
  • 正确性<Text>组件外的纯文本、已弃用模块、已移除API(如
    Dimensions.get
  • 性能:内联
    renderItem
    函数、缺失
    keyExtractor
    、长列表使用
    ScrollView
    、内联样式对象、匿名JSX回调、渲染中的复杂数组链式调用、单元素样式数组、列表项缺失
    React.memo
    、使用
    Animated
    API(推荐使用
    react-native-reanimated
  • 架构:遗留阴影属性、硬编码屏幕尺寸(应使用
    useWindowDimensions()
    )、过多
    Platform.OS
    分支、硬编码颜色、属性透传、上帝组件、不必要的
    useEffect
    用于派生状态
  • 图片<Image>组件缺失明确的宽/高

Accessibility

可访问性

  • Missing
    accessibilityLabel
    on touchable elements
  • Missing
    accessibilityRole
    on interactive components
  • Non-descriptive labels ("button", "tap here", etc.)
  • Images without
    accessible
    +
    accessibilityLabel
  • Small tap targets without
    hitSlop
    (< 44pt)
  • 可触摸元素缺失
    accessibilityLabel
  • 交互组件缺失
    accessibilityRole
  • 非描述性标签(如“button”、“tap here”等)
  • 图片未设置
    accessible
    +
    accessibilityLabel
  • 小点击目标未设置
    hitSlop
    (小于44pt)

Navigation (React Navigation)

导航(React Navigation)

  • Inline component definitions in
    Stack.Screen
  • Missing
    screenOptions
    defaults on navigators
  • Stack.Screen
    中内联定义组件
  • 导航器缺失
    screenOptions
    默认配置

Expo

Expo

  • Hardcoded colors without
    useColorScheme()
    dark mode support
  • Constants.manifest
    Constants.expoConfig
  • _layout.tsx
    missing
    ErrorBoundary
    export
  • Hardcoded API keys in source code
  • Missing
    app/+not-found.tsx
    for Expo Router
  • 硬编码颜色,未通过
    useColorScheme()
    支持深色模式
  • Constants.manifest
    应替换为
    Constants.expoConfig
  • _layout.tsx
    缺失
    ErrorBoundary
    导出
  • 源代码中硬编码API密钥
  • Expo Router缺失
    app/+not-found.tsx

React (applies to all projects)

React(适用于所有项目)

  • Security:
    eval()
    , secrets in client bundle
  • State & Effects: derived state in
    useEffect
    , cascading
    setState
    , missing deps,
    fetch
    in effects, unnecessary
    useEffect
    for derived state
  • Architecture: nested component definitions, giant components (>200 lines)
  • Performance: missing
    useMemo
    /
    useCallback
    , non-lazy state init, inline objects to memoized components
  • 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 . --fix
bash
npx -y react-native-doc@latest . --fix

Cline

Cline

bash
npx -y react-native-doc@latest . --cline
If the
cline
CLI is installed (
npm install -g cline
), runs it directly. Otherwise copies the fix prompt to clipboard and opens VS Code/Cline extension.
bash
npx -y react-native-doc@latest . --cline
若已安装
cline
CLI(
npm install -g cline
),则直接运行;否则会将修复提示复制到剪贴板,并打开VS Code/Cline扩展。