diagnosing-react-code
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDiagnosing React code
诊断 React 代码
react-doctor scans a React package and prints a 0-100 score plus diagnostics
for security, performance, correctness, and architecture. It needs Node
.
^20.19.0 || >=22.13.0react-doctor 会扫描 React 包,并输出 0-100 的评分以及安全性、性能、正确性和架构方面的诊断结果。它需要 Node 。
^20.19.0 || >=22.13.0Before the first run
首次运行前
- The first run in a session downloads and executes a third-party package from npm. Ask the user before it, naming the pinned version.
- By default the score comes from the react-doctor score API and the
supply-chain scan queries Socket.dev; when the user wants nothing sent off
the machine, add (the run then reports no score).
--no-score --no-supply-chain
- 当前会话中的首次运行会从 npm 下载并执行一个第三方包。执行前应询问用户,并说明所固定的版本。
- 默认情况下,评分来自 react-doctor score API,供应链扫描会查询 Socket.dev;如果用户不希望向本机之外发送任何数据,请添加 (此时运行结果不会报告评分)。
--no-score --no-supply-chain
Run
运行
Run inside the package whose lists in
or ; at a monorepo root the tool prompts for a project.
package.jsonreactdependenciespeerDependenciesbash
npx -y react-doctor@0.9.17 --verbose --scope changed- The pin keeps scores comparable across runs. Never fall back to ; upgrade only by changing the pin deliberately. If a flag is rejected, check
@latestand adjust.npx -y react-doctor@0.9.17 --help - lists every rule and file; the default shows only the top 3.
--verbose - reports only new findings in files changed against the auto-detected base ref (
--scope changedto set it). Use--base <ref>for a whole-package health check. It replaces the deprecated--scope full.--diff
在 的 或 中列有 的包内运行;在 monorepo 根目录运行时,该工具会提示选择项目。
package.jsondependenciespeerDependenciesreactbash
npx -y react-doctor@0.9.17 --verbose --scope changed- 固定版本可确保不同运行之间的评分具有可比性。切勿回退到 ;仅在有意升级时修改固定版本。如果某个参数被拒绝,请检查
@latest并进行调整。npx -y react-doctor@0.9.17 --help - 会列出每条规则及其对应文件;默认仅显示前 3 条。
--verbose - 仅报告相对于自动检测的基准 ref 所变更文件中的新发现(可使用
--scope changed设置基准 ref)。使用--base <ref>可对整个包进行健康检查。该参数取代了已弃用的--scope full。--diff
Fix loop
修复循环
- Record the baseline score and error and warning counts.
- Fix error diagnostics, security and correctness first. Fix warnings only in code the current task changed.
- Re-run the same command until it reports no errors and the score is at least the baseline. Stop after three fix rounds that leave errors, or when a fix would change behavior outside the task, and report what remains.
Report the version and scope, the score from baseline to final (or "not
computed: --no-score"), each fixed diagnostic, and each remaining one with
why it was not fixed, as .
<severity> <rule> <file>:<line>- 记录基准评分以及错误和警告数量。
- 修复错误诊断,优先处理安全性和正确性问题。仅修复当前任务所改动代码中的警告。
- 使用相同命令重复运行,直到不再报告错误,且评分不低于基准评分。如果经过三轮修复后仍有错误,或某项修复会改变任务范围之外的行为,则停止修复,并报告剩余问题。
报告版本和扫描范围、从基准到最终的评分(或“not computed: --no-score”)、每项已修复的诊断,以及每项未修复的诊断及其未修复原因,格式为 。
<severity> <rule> <file>:<line>