react-doctor 0.5.1-dev.486c68f → 0.5.1-dev.7c88165
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +582 -195
- package/dist/index.d.ts +125 -48
- package/dist/index.js +187 -21
- package/dist/lsp.js +89 -16
- package/dist/skills/react-doctor/SKILL.md +10 -9
- package/package.json +6 -6
package/dist/lsp.js
CHANGED
|
@@ -37020,6 +37020,42 @@ var Files = class Files extends Service()("react-doctor/Files") {
|
|
|
37020
37020
|
}));
|
|
37021
37021
|
};
|
|
37022
37022
|
};
|
|
37023
|
+
const HUNK_HEADER_PATTERN = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/;
|
|
37024
|
+
/**
|
|
37025
|
+
* Parses a `git diff --unified=0` patch into the inclusive 1-based line ranges
|
|
37026
|
+
* each file added or modified on the new side. Files are keyed by the path in
|
|
37027
|
+
* the `+++ b/<path>` header (with `--relative`, relative to the diff's cwd).
|
|
37028
|
+
* Added/renamed/modified files appear; pure deletions (`+++ /dev/null`) are
|
|
37029
|
+
* skipped because they have no new-side line to report on.
|
|
37030
|
+
*/
|
|
37031
|
+
const parseChangedLineRanges = (patch) => {
|
|
37032
|
+
const rangesByFile = /* @__PURE__ */ new Map();
|
|
37033
|
+
let currentRanges = null;
|
|
37034
|
+
for (const line of patch.split("\n")) {
|
|
37035
|
+
if (line.startsWith("+++ ")) {
|
|
37036
|
+
const target = line.slice(4).trim();
|
|
37037
|
+
if (target === "/dev/null") {
|
|
37038
|
+
currentRanges = null;
|
|
37039
|
+
continue;
|
|
37040
|
+
}
|
|
37041
|
+
const file = target.startsWith("b/") ? target.slice(2) : target;
|
|
37042
|
+
currentRanges = rangesByFile.get(file) ?? [];
|
|
37043
|
+
rangesByFile.set(file, currentRanges);
|
|
37044
|
+
continue;
|
|
37045
|
+
}
|
|
37046
|
+
if (currentRanges === null) continue;
|
|
37047
|
+
const hunk = HUNK_HEADER_PATTERN.exec(line);
|
|
37048
|
+
if (hunk === null) continue;
|
|
37049
|
+
const start = Number(hunk[1]);
|
|
37050
|
+
const lineCount = hunk[2] === void 0 ? 1 : Number(hunk[2]);
|
|
37051
|
+
if (lineCount <= 0) continue;
|
|
37052
|
+
currentRanges.push([start, start + lineCount - 1]);
|
|
37053
|
+
}
|
|
37054
|
+
return [...rangesByFile].filter(([, ranges]) => ranges.length > 0).map(([file, ranges]) => ({
|
|
37055
|
+
file,
|
|
37056
|
+
ranges
|
|
37057
|
+
}));
|
|
37058
|
+
};
|
|
37023
37059
|
const trimOrNull = (value) => {
|
|
37024
37060
|
const trimmed = value.trim();
|
|
37025
37061
|
return trimmed.length === 0 ? null : trimmed;
|
|
@@ -37385,6 +37421,22 @@ var Git = class Git extends Service()("react-doctor/Git") {
|
|
|
37385
37421
|
status: result.status,
|
|
37386
37422
|
stdout: result.stdout
|
|
37387
37423
|
};
|
|
37424
|
+
}),
|
|
37425
|
+
changedLineRanges: ({ directory, baseRef, cached, files }) => gen(function* () {
|
|
37426
|
+
if (files.length === 0) return [];
|
|
37427
|
+
if (baseRef !== void 0 && !isSafeGitRevision(baseRef)) return null;
|
|
37428
|
+
const result = yield* runGit(directory, [
|
|
37429
|
+
"diff",
|
|
37430
|
+
"--unified=0",
|
|
37431
|
+
"--diff-filter=ACMR",
|
|
37432
|
+
"--relative",
|
|
37433
|
+
...cached ? ["--cached"] : [],
|
|
37434
|
+
...baseRef !== void 0 ? [baseRef] : [],
|
|
37435
|
+
"--",
|
|
37436
|
+
...files
|
|
37437
|
+
]);
|
|
37438
|
+
if (result.status !== 0) return null;
|
|
37439
|
+
return parseChangedLineRanges(result.stdout);
|
|
37388
37440
|
})
|
|
37389
37441
|
});
|
|
37390
37442
|
})).pipe(provide$2(layer$2.pipe(provide$2(mergeAll$1(layer$1, layer)))));
|
|
@@ -37415,7 +37467,8 @@ var Git = class Git extends Service()("react-doctor/Git") {
|
|
|
37415
37467
|
status: matches.length === 0 ? 1 : 0,
|
|
37416
37468
|
stdout
|
|
37417
37469
|
};
|
|
37418
|
-
})
|
|
37470
|
+
}),
|
|
37471
|
+
changedLineRanges: () => succeed$2(snapshot.changedLineRanges ?? [])
|
|
37419
37472
|
}));
|
|
37420
37473
|
};
|
|
37421
37474
|
const estimateArgsLength = (args) => args.reduce((total, argument) => total + argument.length + 1, 0);
|
|
@@ -38408,6 +38461,7 @@ const shouldSuppressLocalUseHookDiagnostic = (diagnostic, rootDirectory) => {
|
|
|
38408
38461
|
};
|
|
38409
38462
|
const FILEPATH_WITH_LOCATION_PATTERN = /\S+\.\w+:\d+:\d+[\s\S]*$/;
|
|
38410
38463
|
const REACT_COMPILER_TITLE = "React Compiler can't optimize this";
|
|
38464
|
+
const REACT_COMPILER_TODO_TITLE = "React Compiler doesn't support this syntax";
|
|
38411
38465
|
const REACT_COMPILER_MESSAGE = "This component misses React Compiler's automatic memoization & re-renders more than it should. Rewrite the flagged code so the compiler can optimize it.";
|
|
38412
38466
|
const PLUGIN_CATEGORY_MAP = {
|
|
38413
38467
|
react: "Bugs",
|
|
@@ -38435,7 +38489,10 @@ const getRuleRecommendation = (ruleName, project) => {
|
|
|
38435
38489
|
};
|
|
38436
38490
|
const getRuleCategory = (ruleName) => reactDoctorPlugin.rules[ruleName]?.category;
|
|
38437
38491
|
const getRuleTitle = (ruleName) => reactDoctorPlugin.rules[ruleName]?.title;
|
|
38438
|
-
const resolveDiagnosticTitle = (plugin, rule) =>
|
|
38492
|
+
const resolveDiagnosticTitle = (plugin, rule) => {
|
|
38493
|
+
if (plugin !== "react-hooks-js") return getRuleTitle(rule);
|
|
38494
|
+
return rule === "todo" ? REACT_COMPILER_TODO_TITLE : REACT_COMPILER_TITLE;
|
|
38495
|
+
};
|
|
38439
38496
|
const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
|
|
38440
38497
|
const cleaned = resolveCleanedDiagnostic(typeof message === "string" ? message : "", typeof help === "string" ? help : "", plugin, rule, project);
|
|
38441
38498
|
return {
|
|
@@ -39194,25 +39251,36 @@ const decodeArtifact = decodeUnknownOption(Struct({ score: optional(Struct({
|
|
|
39194
39251
|
const SCORE_AXES = [
|
|
39195
39252
|
{
|
|
39196
39253
|
key: "supplyChain",
|
|
39197
|
-
label: "supply chain"
|
|
39254
|
+
label: "supply chain",
|
|
39255
|
+
gates: true
|
|
39198
39256
|
},
|
|
39199
39257
|
{
|
|
39200
39258
|
key: "vulnerability",
|
|
39201
|
-
label: "vulnerability"
|
|
39259
|
+
label: "vulnerability",
|
|
39260
|
+
gates: true
|
|
39202
39261
|
},
|
|
39203
39262
|
{
|
|
39204
39263
|
key: "maintenance",
|
|
39205
|
-
label: "maintenance"
|
|
39264
|
+
label: "maintenance",
|
|
39265
|
+
gates: false
|
|
39206
39266
|
},
|
|
39207
39267
|
{
|
|
39208
39268
|
key: "quality",
|
|
39209
|
-
label: "quality"
|
|
39269
|
+
label: "quality",
|
|
39270
|
+
gates: false
|
|
39210
39271
|
},
|
|
39211
39272
|
{
|
|
39212
39273
|
key: "license",
|
|
39213
|
-
label: "license"
|
|
39274
|
+
label: "license",
|
|
39275
|
+
gates: false
|
|
39214
39276
|
}
|
|
39215
39277
|
];
|
|
39278
|
+
const GATED_AXES = SCORE_AXES.filter((axis) => axis.gates);
|
|
39279
|
+
const worstGatedAxis = (score) => {
|
|
39280
|
+
let worst = GATED_AXES[0];
|
|
39281
|
+
for (const axis of GATED_AXES) if (score[axis.key] < score[worst.key]) worst = axis;
|
|
39282
|
+
return worst;
|
|
39283
|
+
};
|
|
39216
39284
|
const clampScore = (value) => {
|
|
39217
39285
|
if (!Number.isFinite(value)) return 50;
|
|
39218
39286
|
return Math.min(Math.max(value, 0), 100);
|
|
@@ -39328,15 +39396,14 @@ const fetchSocketScore = (dependency) => tryPromise(async (signal) => {
|
|
|
39328
39396
|
"socket.purl": toPurl(dependency)
|
|
39329
39397
|
} }));
|
|
39330
39398
|
const formatAxisScores = (score) => SCORE_AXES.map((axis) => `${axis.label} ${toHundred(score[axis.key])}`).join(", ");
|
|
39331
|
-
const buildLowScoreDiagnostic = (dependency, score, options) => {
|
|
39332
|
-
const overall = toHundred(score.overall);
|
|
39399
|
+
const buildLowScoreDiagnostic = (dependency, score, failingAxis, options) => {
|
|
39333
39400
|
const packagePageUrl = `${SOCKET_PACKAGE_PAGE_BASE}/${dependency.name}/overview/${dependency.version}`;
|
|
39334
39401
|
return {
|
|
39335
39402
|
filePath: "package.json",
|
|
39336
39403
|
plugin: SUPPLY_CHAIN_PLUGIN,
|
|
39337
39404
|
rule: SUPPLY_CHAIN_RULE,
|
|
39338
39405
|
severity: options.severity,
|
|
39339
|
-
message: `\`${dependency.name}\` (declared in package.json as "${dependency.spec}", scored at ${dependency.version}) has a Socket
|
|
39406
|
+
message: `\`${dependency.name}\` (declared in package.json as "${dependency.spec}", scored at ${dependency.version}) has a Socket ${failingAxis.label} score of ${toHundred(score[failingAxis.key])}/100 (below the minimum of ${options.minScore}). Axis scores — ${formatAxisScores(score)}.`,
|
|
39340
39407
|
help: `Update or replace the \`"${dependency.name}": "${dependency.spec}"\` entry in package.json. Review ${dependency.name} on Socket: ${packagePageUrl}. Or raise \`supplyChain.minScore\` if you have vetted and accepted this package.`,
|
|
39341
39408
|
url: packagePageUrl,
|
|
39342
39409
|
line: dependency.line,
|
|
@@ -39348,7 +39415,9 @@ const buildLowScoreDiagnostic = (dependency, score, options) => {
|
|
|
39348
39415
|
* Scores every direct dependency in the project's `package.json` against
|
|
39349
39416
|
* Socket.dev's free PURL endpoint (the same one Socket Firewall's free tier
|
|
39350
39417
|
* uses — no API key) and returns a diagnostic for each dependency whose
|
|
39351
|
-
* Socket
|
|
39418
|
+
* worst Socket *security* axis — supply chain or vulnerability — is below
|
|
39419
|
+
* the configured `minScore`. The quality / maintenance / license axes are
|
|
39420
|
+
* reported as context but never gate (see GATED_AXES).
|
|
39352
39421
|
*
|
|
39353
39422
|
* Lookups run with bounded concurrency via `Effect.forEach`. The check is
|
|
39354
39423
|
* total/fail-open: each per-package lookup already recovers to `null`
|
|
@@ -39366,8 +39435,9 @@ const checkSupplyChain = (input) => gen(function* () {
|
|
|
39366
39435
|
for (let index = 0; index < dependencies.length; index += 1) {
|
|
39367
39436
|
const score = scores[index];
|
|
39368
39437
|
if (!score) continue;
|
|
39369
|
-
|
|
39370
|
-
|
|
39438
|
+
const worstAxis = worstGatedAxis(score);
|
|
39439
|
+
if (toHundred(score[worstAxis.key]) >= options.minScore) continue;
|
|
39440
|
+
diagnostics.push(buildLowScoreDiagnostic(dependencies[index], score, worstAxis, options));
|
|
39371
39441
|
}
|
|
39372
39442
|
return diagnostics;
|
|
39373
39443
|
});
|
|
@@ -39375,7 +39445,8 @@ const checkSupplyChain = (input) => gen(function* () {
|
|
|
39375
39445
|
* `SupplyChain` scores the project's direct dependencies against Socket.dev's
|
|
39376
39446
|
* free, keyless PURL endpoint — the same lookup Socket Firewall's free tier
|
|
39377
39447
|
* (`sfw`) performs — and streams a diagnostic for each dependency whose
|
|
39378
|
-
* Socket
|
|
39448
|
+
* worst Socket security axis (supply chain or vulnerability) falls below
|
|
39449
|
+
* the configured `supplyChain.minScore`.
|
|
39379
39450
|
*
|
|
39380
39451
|
* Runs by default (one network request per dependency); the orchestrator
|
|
39381
39452
|
* provides `layerOf([])` only when the user opts out via
|
|
@@ -41642,6 +41713,8 @@ const METRIC = {
|
|
|
41642
41713
|
cliInvoked: "cli.invoked",
|
|
41643
41714
|
cliError: "cli.error",
|
|
41644
41715
|
projectDetected: "project.detected",
|
|
41716
|
+
projectPathSelected: "project.path_selected",
|
|
41717
|
+
projectConfigSelected: "project.config_selected",
|
|
41645
41718
|
scanCompleted: "scan.completed",
|
|
41646
41719
|
scanDuration: "scan.duration",
|
|
41647
41720
|
scanPhaseDuration: "scan.phase_duration",
|
|
@@ -41985,5 +42058,5 @@ const startLanguageServer = () => {
|
|
|
41985
42058
|
};
|
|
41986
42059
|
//#endregion
|
|
41987
42060
|
export { startLanguageServer };
|
|
41988
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
41989
|
-
//# debugId=
|
|
42061
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="1e6dd9cd-7bbf-509d-9302-bdf56d4cf879")}catch(e){}}();
|
|
42062
|
+
//# debugId=1e6dd9cd-7bbf-509d-9302-bdf56d4cf879
|
|
@@ -10,13 +10,13 @@ Scans React codebases for security, performance, correctness, and architecture i
|
|
|
10
10
|
|
|
11
11
|
## After making React code changes:
|
|
12
12
|
|
|
13
|
-
Run `npx react-doctor@latest --verbose --
|
|
13
|
+
Run `npx react-doctor@latest --verbose --scope changed` and check the score did not regress.
|
|
14
14
|
|
|
15
15
|
If the score dropped, fix the regressions before committing.
|
|
16
16
|
|
|
17
17
|
## For general cleanup or code improvement:
|
|
18
18
|
|
|
19
|
-
Run `npx react-doctor@latest --verbose` (
|
|
19
|
+
Run `npx react-doctor@latest --verbose` (the default `--scope full`) to scan the full codebase. Fix issues by severity — errors first, then warnings.
|
|
20
20
|
|
|
21
21
|
## /doctor — full local triage workflow
|
|
22
22
|
|
|
@@ -39,12 +39,13 @@ When the user wants to understand a rule, disagrees with one, or wants to disabl
|
|
|
39
39
|
## Command
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
|
-
npx react-doctor@latest --verbose --
|
|
42
|
+
npx react-doctor@latest --verbose --scope changed
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
| Flag
|
|
46
|
-
|
|
|
47
|
-
| `.`
|
|
48
|
-
| `--verbose`
|
|
49
|
-
| `--
|
|
50
|
-
| `--
|
|
45
|
+
| Flag | Purpose |
|
|
46
|
+
| ----------------- | ---------------------------------------------------------------- |
|
|
47
|
+
| `.` | Scan current directory |
|
|
48
|
+
| `--verbose` | Show affected files and line numbers per rule |
|
|
49
|
+
| `--scope changed` | Only report issues introduced vs the base branch (default: full) |
|
|
50
|
+
| `--scope lines` | Only report issues on the changed lines |
|
|
51
|
+
| `--score` | Output only the numeric score |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-doctor",
|
|
3
|
-
"version": "0.5.1-dev.
|
|
3
|
+
"version": "0.5.1-dev.7c88165",
|
|
4
4
|
"description": "Your agent writes bad React. This catches it",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"accessibility",
|
|
@@ -54,17 +54,17 @@
|
|
|
54
54
|
"agent-install": "0.0.5",
|
|
55
55
|
"conf": "^15.1.0",
|
|
56
56
|
"confbox": "^0.2.4",
|
|
57
|
-
"deslop-js": "^0.0.
|
|
57
|
+
"deslop-js": "^0.0.23",
|
|
58
58
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
59
59
|
"jiti": "^2.7.0",
|
|
60
60
|
"magicast": "^0.5.3",
|
|
61
|
-
"oxlint": "
|
|
61
|
+
"oxlint": ">=1.66.0 <1.67.0",
|
|
62
62
|
"prompts": "^2.4.2",
|
|
63
63
|
"typescript": ">=5.0.4 <7",
|
|
64
64
|
"vscode-languageserver": "^9.0.1",
|
|
65
65
|
"vscode-languageserver-textdocument": "^1.0.12",
|
|
66
66
|
"vscode-uri": "^3.1.0",
|
|
67
|
-
"oxlint-plugin-react-doctor": "0.5.1-dev.
|
|
67
|
+
"oxlint-plugin-react-doctor": "0.5.1-dev.7c88165"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@types/babel__code-frame": "^7.27.0",
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
"@xterm/headless": "^6.0.0",
|
|
73
73
|
"commander": "^14.0.3",
|
|
74
74
|
"ora": "^9.4.0",
|
|
75
|
-
"@react-doctor/
|
|
75
|
+
"@react-doctor/api": "0.5.1",
|
|
76
76
|
"@react-doctor/language-server": "0.5.1",
|
|
77
|
-
"@react-doctor/
|
|
77
|
+
"@react-doctor/core": "0.5.1"
|
|
78
78
|
},
|
|
79
79
|
"engines": {
|
|
80
80
|
"node": "^20.19.0 || >=22.13.0"
|