OpenSource-Hub

react-doctor

命令行工具

millionco/react-doctor

扫描React代码库并输出健康评分与可操作诊断。

项目简介

React Doctor 是一款 CLI 工具,可扫描 React 代码库并生成 0-100 的健康评分与可操作诊断。它检查状态、性能、可访问性、安全性和死代码,支持 Next.js、Vite 和 React Native。它可集成到 CI/CD 管道和编程代理中,以强制实施最佳实践。

README 预览

\n  \n  \n  \n\n\n[](https://npmjs.com/package/react-doctor)\n[](https://npmjs.com/package/react-doctor)\n\nYour agent writes bad React, this catches it.\n\nOne command scans your codebase and outputs a **0 to 100 health score** with actionable diagnostics.\n\nWorks with Next.js, Vite, and React Native.\n\n### [See it in action →](https://react.doctor)\n\n## Install\n\nRun this at your project root:\n\n```bash\nnpx -y react-doctor@latest .\n```\n\nYou'll get a score (75+ Great, 50 to 74 Needs work, under 50 Critical) and a list of issues across state & effects, performance, architecture, security, accessibility, and dead code. Rules toggle automatically based on your framework and React version.\n\nhttps://github.com/user-attachments/assets/07cc88d9-9589-44c3-aa73-5d603cb1c570\n\n## Install for your coding agent\n\nTeach your coding agent React best practices so it stops writing the bad code in the first place.\n\n```bash\nnpx -y react-doctor@latest install\n```\n\nYou'll be prompted to pick which detected agents to install for. Pass `--yes` to skip prompts.\n\nWorks with Claude Code, Cursor, Codex, OpenCode, and 50+ other agents.\n\n## GitHub Actions\n\nA composite action ships with this repository. Drop it into `.github/workflows/react-doctor.yml`:\n\n```yaml\nname: React Doctor\n\non:\n  pull_request:\n  push:\n    branches: [main]\n\npermissions:\n  contents: read\n  pull-requests: write # required to post PR comments\n\njobs:\n  react-doctor:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v5\n        with:\n          fetch-depth: 0 # required for `diff`\n      - uses: millionco/react-doctor@main\n        with:\n          diff: main\n          github-token: ${{ secrets.GITHUB_TOKEN }}\n```\n\nWhen `github-token` is set on `pull_request` events, findings are posted (and updated) as a PR comment. The action also exposes a `score` output (0–100) you can use in subsequent steps.\n\n**Inputs:** `directory`, `verbose`, `project`, `diff`, `gith

常见问题 (4)

故障排除
为什么 react-doctor 的 unused-file 规则在 Windows 上几乎将每个文件都标记为未使用?

这是deslop-js在Windows上已知的路径分隔符不匹配错误(反斜杠与正斜杠导致导入图边缘丢失)。该修复已合并到deslop-js主分支(PR #16),并将包含在下一个react-doctor版本中。在此之前,作为临时解决方案,请在WSL或Unix环境中运行react-doctor,或手动应用来自millionco/deslop-js#16的补丁。

来源 Issue #652
故障排除
如何选择交互式CLI清单中的所有项目?

按下 'a' 键以切换选择当前列表中的所有选项。此键盘快捷键在交互界面中有效。

来源 Issue #647
security
在GitHub Actions工作流中使用@main分支是否存在安全风险,如何安全地固定actions?

是的,使用诸如@main之类的可变分支引用操作,如果上游仓库被攻破,可能导致供应链攻击。而应固定到具体的发布标签(例如@v1.2.3)或完整的提交SHA。对于react-doctor,应使用uses: millionco/react-doctor@<tag-or-sha>而不是@main

来源 Issue #299
故障排除
运行 npx react-doctor@latest 时如何修复 "Cannot find package 'oxc-parser'" 错误?

此bug影响react-doctor@0.2.14,其中oxc-parser被错误地列在devDependencies而非dependencies中。变通方法:在运行react-doctor之前,手动在你的项目中安装oxc-parser(npm install oxc-parser 或 pnpm add oxc-parser)。或者,降级到react-doctor@0.2.3或更早版本。关注issue #629以获取永久修复。

来源 Issue #629