react-doctor 0.3.0 → 0.4.0-dev.a5c6993
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/README.md +18 -2
- package/bin/react-doctor.js +9 -1
- package/dist/cli.js +625 -233
- package/dist/index.d.ts +141 -12
- package/dist/index.js +189 -60
- package/dist/lsp.js +10804 -0
- package/package.json +8 -4
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
|
|
2
|
-
!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]="
|
|
2
|
+
!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]="3c457dc9-865a-5459-b923-a0fb762b158f")}catch(e){}}();
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { execFile, execFileSync, spawn, spawnSync } from "node:child_process";
|
|
5
5
|
import * as path$1 from "node:path";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import * as fs$1 from "node:fs";
|
|
8
|
-
import fs from "node:fs";
|
|
8
|
+
import fs, { mkdtempSync, rmSync } from "node:fs";
|
|
9
9
|
import process$1 from "node:process";
|
|
10
10
|
import * as Schema from "effect/Schema";
|
|
11
11
|
import reactDoctorPlugin, { ALL_REACT_DOCTOR_RULE_KEYS, FRAMEWORK_SPECIFIC_RULE_KEYS, MOTION_LIBRARY_PACKAGES, REACT_COMPILER_RULES, REACT_DOCTOR_RULES } from "oxlint-plugin-react-doctor";
|
|
@@ -34,11 +34,11 @@ import * as ChildProcess from "effect/unstable/process/ChildProcess";
|
|
|
34
34
|
import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner";
|
|
35
35
|
import * as ts from "typescript";
|
|
36
36
|
import { gzipSync } from "node:zlib";
|
|
37
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
38
|
+
import * as Exit from "effect/Exit";
|
|
37
39
|
import * as Sentry from "@sentry/node";
|
|
38
40
|
import { performance } from "node:perf_hooks";
|
|
39
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
40
41
|
import * as Tracer from "effect/Tracer";
|
|
41
|
-
import * as Exit from "effect/Exit";
|
|
42
42
|
import { promisify, stripVTControlCharacters } from "node:util";
|
|
43
43
|
import tty from "node:tty";
|
|
44
44
|
import { codeFrameColumns } from "@babel/code-frame";
|
|
@@ -3085,6 +3085,16 @@ const { program: program$1, createCommand, createArgument, createOption, Command
|
|
|
3085
3085
|
//#endregion
|
|
3086
3086
|
//#region ../core/dist/schemas.js
|
|
3087
3087
|
const Severity = Schema.Literals(["error", "warning"]);
|
|
3088
|
+
var DiagnosticRelatedLocation = class extends Schema.Class("DiagnosticRelatedLocation")({
|
|
3089
|
+
filePath: Schema.String,
|
|
3090
|
+
line: Schema.Number,
|
|
3091
|
+
column: Schema.Number,
|
|
3092
|
+
offset: Schema.optional(Schema.Number),
|
|
3093
|
+
length: Schema.optional(Schema.Number),
|
|
3094
|
+
endLine: Schema.optional(Schema.Number),
|
|
3095
|
+
endColumn: Schema.optional(Schema.Number),
|
|
3096
|
+
message: Schema.String
|
|
3097
|
+
}) {};
|
|
3088
3098
|
var Diagnostic = class extends Schema.Class("Diagnostic")({
|
|
3089
3099
|
filePath: Schema.String,
|
|
3090
3100
|
plugin: Schema.String,
|
|
@@ -3096,13 +3106,19 @@ var Diagnostic = class extends Schema.Class("Diagnostic")({
|
|
|
3096
3106
|
url: Schema.optional(Schema.String),
|
|
3097
3107
|
line: Schema.Number,
|
|
3098
3108
|
column: Schema.Number,
|
|
3109
|
+
offset: Schema.optional(Schema.Number),
|
|
3110
|
+
length: Schema.optional(Schema.Number),
|
|
3111
|
+
endLine: Schema.optional(Schema.Number),
|
|
3112
|
+
endColumn: Schema.optional(Schema.Number),
|
|
3099
3113
|
category: Schema.String,
|
|
3100
|
-
suppressionHint: Schema.optional(Schema.String)
|
|
3114
|
+
suppressionHint: Schema.optional(Schema.String),
|
|
3115
|
+
relatedLocations: Schema.optional(Schema.Array(DiagnosticRelatedLocation))
|
|
3101
3116
|
}) {};
|
|
3102
3117
|
const JsonReportMode = Schema.Literals([
|
|
3103
3118
|
"full",
|
|
3104
3119
|
"diff",
|
|
3105
|
-
"staged"
|
|
3120
|
+
"staged",
|
|
3121
|
+
"baseline"
|
|
3106
3122
|
]);
|
|
3107
3123
|
var JsonReportSummary = class extends Schema.Class("JsonReportSummary")({
|
|
3108
3124
|
errorCount: Schema.Number,
|
|
@@ -3121,7 +3137,9 @@ var JsonReportDiffInfo = class extends Schema.Class("JsonReportDiffInfo")({
|
|
|
3121
3137
|
var JsonReportError = class extends Schema.Class("JsonReportError")({
|
|
3122
3138
|
message: Schema.String,
|
|
3123
3139
|
name: Schema.String,
|
|
3124
|
-
chain: Schema.Array(Schema.String)
|
|
3140
|
+
chain: Schema.Array(Schema.String),
|
|
3141
|
+
/** Sentry event id for the crash, when one was reported. */
|
|
3142
|
+
sentryEventId: Schema.optional(Schema.NullOr(Schema.String))
|
|
3125
3143
|
}) {};
|
|
3126
3144
|
/**
|
|
3127
3145
|
* Schema for a single project entry within a JsonReport. `project` is
|
|
@@ -3158,7 +3176,33 @@ var JsonReportV1 = class extends Schema.Class("JsonReportV1")({
|
|
|
3158
3176
|
elapsedMilliseconds: Schema.Number,
|
|
3159
3177
|
error: Schema.NullOr(JsonReportError)
|
|
3160
3178
|
}) {};
|
|
3161
|
-
Schema.
|
|
3179
|
+
var JsonReportBaseline = class extends Schema.Class("JsonReportBaseline")({
|
|
3180
|
+
baseRef: Schema.String,
|
|
3181
|
+
newCount: Schema.Number,
|
|
3182
|
+
fixedCount: Schema.Number,
|
|
3183
|
+
baseTotalCount: Schema.Number
|
|
3184
|
+
}) {};
|
|
3185
|
+
/**
|
|
3186
|
+
* Baseline (PR-introduced-issues-only) report — `schemaVersion: 2`. A
|
|
3187
|
+
* superset of v1: same fields, plus a `baseline` block. `diagnostics` /
|
|
3188
|
+
* `summary` counts are the introduced findings only; `summary.score` stays
|
|
3189
|
+
* the head project-health score. Consumers branch on `schemaVersion`.
|
|
3190
|
+
*/
|
|
3191
|
+
var JsonReportV2 = class extends Schema.Class("JsonReportV2")({
|
|
3192
|
+
schemaVersion: Schema.Literal(2),
|
|
3193
|
+
version: Schema.String,
|
|
3194
|
+
ok: Schema.Boolean,
|
|
3195
|
+
directory: Schema.String,
|
|
3196
|
+
mode: JsonReportMode,
|
|
3197
|
+
diff: Schema.NullOr(JsonReportDiffInfo),
|
|
3198
|
+
baseline: JsonReportBaseline,
|
|
3199
|
+
projects: Schema.Array(JsonReportProjectEntry),
|
|
3200
|
+
diagnostics: Schema.Array(Diagnostic),
|
|
3201
|
+
summary: JsonReportSummary,
|
|
3202
|
+
elapsedMilliseconds: Schema.Number,
|
|
3203
|
+
error: Schema.NullOr(JsonReportError)
|
|
3204
|
+
}) {};
|
|
3205
|
+
Schema.Union([JsonReportV1, JsonReportV2]);
|
|
3162
3206
|
//#endregion
|
|
3163
3207
|
//#region ../../node_modules/.pnpm/picomatch@4.0.4/node_modules/picomatch/lib/constants.js
|
|
3164
3208
|
var require_constants = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
@@ -9281,6 +9325,11 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9281
9325
|
branch
|
|
9282
9326
|
]).pipe(Effect.map((result) => result.status === 0));
|
|
9283
9327
|
const headSha = (directory) => runGit(directory, ["rev-parse", "HEAD"]).pipe(Effect.map((result) => result.status === 0 ? trimOrNull(result.stdout) : null));
|
|
9328
|
+
const mergeBase = (input) => isSafeGitRevision(input.ref) ? runGit(input.directory, [
|
|
9329
|
+
"merge-base",
|
|
9330
|
+
input.ref,
|
|
9331
|
+
"HEAD"
|
|
9332
|
+
]).pipe(Effect.map((result) => result.status === 0 ? trimOrNull(result.stdout) : null)) : Effect.succeed(null);
|
|
9284
9333
|
const githubRepo = (directory) => runGit(directory, [
|
|
9285
9334
|
"config",
|
|
9286
9335
|
"--get",
|
|
@@ -9356,6 +9405,7 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9356
9405
|
return {
|
|
9357
9406
|
currentBranch: yield* currentBranch(input.directory),
|
|
9358
9407
|
baseBranch: baseRef,
|
|
9408
|
+
diffBaseRef,
|
|
9359
9409
|
changedFiles: splitNullSeparated(diff.stdout),
|
|
9360
9410
|
isCurrentChanges: false
|
|
9361
9411
|
};
|
|
@@ -9367,6 +9417,7 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9367
9417
|
githubRepo,
|
|
9368
9418
|
githubViewerPermission,
|
|
9369
9419
|
branchExists,
|
|
9420
|
+
mergeBase,
|
|
9370
9421
|
diffSelection: ({ directory, explicitBaseBranch }) => Effect.gen(function* () {
|
|
9371
9422
|
if (explicitBaseBranch !== void 0 && explicitBaseBranch.trim().length === 0) return yield* Effect.fail(new ReactDoctorError({ reason: new GitBaseBranchInvalid({ detail: "Diff base branch cannot be empty." }) }));
|
|
9372
9423
|
if (explicitBaseBranch !== void 0) {
|
|
@@ -9424,6 +9475,7 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9424
9475
|
return {
|
|
9425
9476
|
currentBranch: resolvedCurrentBranch,
|
|
9426
9477
|
baseBranch,
|
|
9478
|
+
diffBaseRef: mergeBaseRef,
|
|
9427
9479
|
changedFiles: splitNullSeparated(diff.stdout),
|
|
9428
9480
|
isCurrentChanges: false
|
|
9429
9481
|
};
|
|
@@ -9445,6 +9497,12 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9445
9497
|
directory,
|
|
9446
9498
|
maxStdoutBytes: options?.maxBufferBytes
|
|
9447
9499
|
}).pipe(Effect.map((result) => result.status === 0 ? result.stdout : null)),
|
|
9500
|
+
showRefContent: ({ directory, ref, relativePath, options }) => isSafeGitRevision(ref) ? runCommand({
|
|
9501
|
+
command: "git",
|
|
9502
|
+
args: ["show", `${ref}:./${relativePath}`],
|
|
9503
|
+
directory,
|
|
9504
|
+
maxStdoutBytes: options?.maxBufferBytes
|
|
9505
|
+
}).pipe(Effect.map((result) => result.status === 0 ? result.stdout : null)) : Effect.succeed(null),
|
|
9448
9506
|
grep: (input) => Effect.gen(function* () {
|
|
9449
9507
|
const args = ["grep"];
|
|
9450
9508
|
if (input.listMatchingFiles ?? true) args.push("-l");
|
|
@@ -9480,9 +9538,11 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9480
9538
|
githubRepo: () => Effect.succeed(snapshot.githubRepo ?? null),
|
|
9481
9539
|
githubViewerPermission: () => Effect.succeed(snapshot.githubViewerPermission ?? null),
|
|
9482
9540
|
branchExists: (_directory, branch) => Effect.succeed(snapshot.branchExists?.get(branch) ?? false),
|
|
9541
|
+
mergeBase: ({ ref }) => Effect.succeed(snapshot.mergeBase?.get(ref) ?? null),
|
|
9483
9542
|
diffSelection: () => Effect.succeed(snapshot.diffSelection ?? null),
|
|
9484
9543
|
stagedFilePaths: () => Effect.succeed(snapshot.stagedFiles ?? []),
|
|
9485
9544
|
showStagedContent: (_directory, relativePath) => Effect.succeed(snapshot.stagedContent?.get(relativePath) ?? null),
|
|
9545
|
+
showRefContent: ({ ref, relativePath }) => Effect.succeed(snapshot.refContent?.get(`${ref}:${relativePath}`) ?? null),
|
|
9486
9546
|
grep: () => Effect.sync(() => {
|
|
9487
9547
|
const matches = snapshot.grepMatches;
|
|
9488
9548
|
if (matches === null || matches === void 0) return null;
|
|
@@ -10537,6 +10597,30 @@ const parseRuleCode = (code) => {
|
|
|
10537
10597
|
};
|
|
10538
10598
|
};
|
|
10539
10599
|
const resolveDiagnosticCategory = (plugin, rule) => getRuleCategory(rule) ?? lookupOwnString(PLUGIN_CATEGORY_MAP, plugin) ?? "Bugs";
|
|
10600
|
+
/**
|
|
10601
|
+
* Maps oxlint's non-primary labels (`labels[1..]`) into related source
|
|
10602
|
+
* locations. Editors surface these as a diagnostic's
|
|
10603
|
+
* `relatedInformation`; non-editor consumers ignore the field. Labels
|
|
10604
|
+
* with empty text still carry a useful jump target, so they're kept
|
|
10605
|
+
* with a neutral message.
|
|
10606
|
+
*/
|
|
10607
|
+
const buildRelatedLocations = (labels, filePath) => {
|
|
10608
|
+
if (labels.length <= 1) return [];
|
|
10609
|
+
const related = [];
|
|
10610
|
+
for (let labelIndex = 1; labelIndex < labels.length; labelIndex++) {
|
|
10611
|
+
const label = labels[labelIndex];
|
|
10612
|
+
if (!label?.span) continue;
|
|
10613
|
+
related.push({
|
|
10614
|
+
filePath,
|
|
10615
|
+
line: label.span.line ?? 0,
|
|
10616
|
+
column: label.span.column ?? 0,
|
|
10617
|
+
offset: label.span.offset,
|
|
10618
|
+
length: label.span.length,
|
|
10619
|
+
message: label.label ?? ""
|
|
10620
|
+
});
|
|
10621
|
+
}
|
|
10622
|
+
return related;
|
|
10623
|
+
};
|
|
10540
10624
|
const isOxlintOutput = (value) => {
|
|
10541
10625
|
if (typeof value !== "object" || value === null) return false;
|
|
10542
10626
|
const candidate = value;
|
|
@@ -10573,8 +10657,11 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
10573
10657
|
const { plugin, rule } = parseRuleCode(diagnostic.code);
|
|
10574
10658
|
const primaryLabel = diagnostic.labels[0];
|
|
10575
10659
|
const cleaned = cleanDiagnosticMessage(diagnostic.message, diagnostic.help, plugin, rule, project);
|
|
10660
|
+
const normalizedFilePath = diagnostic.filename.replaceAll("\\", "/");
|
|
10661
|
+
const primarySpan = primaryLabel?.span;
|
|
10662
|
+
const relatedLocations = buildRelatedLocations(diagnostic.labels, normalizedFilePath);
|
|
10576
10663
|
return {
|
|
10577
|
-
filePath:
|
|
10664
|
+
filePath: normalizedFilePath,
|
|
10578
10665
|
plugin,
|
|
10579
10666
|
rule,
|
|
10580
10667
|
severity: diagnostic.severity,
|
|
@@ -10582,9 +10669,14 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
10582
10669
|
message: cleaned.message,
|
|
10583
10670
|
help: cleaned.help,
|
|
10584
10671
|
url: diagnostic.url,
|
|
10585
|
-
line:
|
|
10586
|
-
column:
|
|
10587
|
-
|
|
10672
|
+
line: primarySpan?.line ?? 0,
|
|
10673
|
+
column: primarySpan?.column ?? 0,
|
|
10674
|
+
...primarySpan ? {
|
|
10675
|
+
offset: primarySpan.offset,
|
|
10676
|
+
length: primarySpan.length
|
|
10677
|
+
} : {},
|
|
10678
|
+
category: resolveDiagnosticCategory(plugin, rule),
|
|
10679
|
+
...relatedLocations.length > 0 ? { relatedLocations } : {}
|
|
10588
10680
|
};
|
|
10589
10681
|
});
|
|
10590
10682
|
};
|
|
@@ -11313,7 +11405,7 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
11313
11405
|
directory: scanDirectory,
|
|
11314
11406
|
repo
|
|
11315
11407
|
}).pipe(Effect.orElseSucceed(() => null)) : Effect.succeed(null));
|
|
11316
|
-
const lintIncludePaths = computeJsxIncludePaths([...input.includePaths]) ?? resolveLintIncludePaths(scanDirectory, resolvedConfig.config);
|
|
11408
|
+
const lintIncludePaths = (input.skipJsxIncludeFilter ? input.includePaths.length > 0 ? [...input.includePaths] : void 0 : computeJsxIncludePaths([...input.includePaths])) ?? resolveLintIncludePaths(scanDirectory, resolvedConfig.config);
|
|
11317
11409
|
const scannedFilePaths = input.suppressScanSummary ? (lintIncludePaths ?? (yield* filesService.listSourceFiles(scanDirectory))).map((relativePath) => path$1.resolve(scanDirectory, relativePath)) : [];
|
|
11318
11410
|
const beforeLint = hooks.beforeLint ?? NO_HOOKS.beforeLint;
|
|
11319
11411
|
const afterLint = hooks.afterLint ?? NO_HOOKS.afterLint;
|
|
@@ -11559,19 +11651,60 @@ var NodeResolver = class NodeResolver extends Context.Service()("react-doctor/No
|
|
|
11559
11651
|
});
|
|
11560
11652
|
};
|
|
11561
11653
|
/**
|
|
11562
|
-
* Zip-Slip defense:
|
|
11563
|
-
*
|
|
11564
|
-
*
|
|
11565
|
-
*
|
|
11566
|
-
* working tree) can include `..` segments that escape the temp
|
|
11567
|
-
* tree. Resolve the candidate against the temp dir and reject any
|
|
11568
|
-
* result that lands outside it before `writeFileSync` runs.
|
|
11654
|
+
* Zip-Slip defense: relative paths come from git (`diff --name-only`), which
|
|
11655
|
+
* normalizes during ordinary adds, but a crafted index/pack/symlinked tree can
|
|
11656
|
+
* smuggle `..` segments that escape the temp root. Resolve against the temp dir
|
|
11657
|
+
* and reject anything that lands outside before writing.
|
|
11569
11658
|
*/
|
|
11570
11659
|
const isPathInsideDirectory = (childAbsolutePath, parentAbsolutePath) => {
|
|
11571
|
-
const relative = path
|
|
11572
|
-
return Boolean(relative) && !relative.startsWith("..") && !path
|
|
11660
|
+
const relative = path.relative(parentAbsolutePath, childAbsolutePath);
|
|
11661
|
+
return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
11573
11662
|
};
|
|
11574
11663
|
/**
|
|
11664
|
+
* Writes a set of source files (supplied by `readContent` — e.g.
|
|
11665
|
+
* `git show <ref>:<path>` for a baseline tree, or `git show :<path>` for the
|
|
11666
|
+
* index) into a temp tree that mirrors the project layout, copying the
|
|
11667
|
+
* well-known project-config files from `directory` so oxlint resolves
|
|
11668
|
+
* tsconfig / lint config identically to the working tree. Shared by the staged
|
|
11669
|
+
* and baseline scan paths so the zip-slip guard lives in one audited place.
|
|
11670
|
+
* Per-file read failures skip that file (the scan proceeds with whatever read
|
|
11671
|
+
* cleanly) rather than sinking the whole snapshot.
|
|
11672
|
+
*/
|
|
11673
|
+
const materializeSourceTree = (input) => Effect.gen(function* () {
|
|
11674
|
+
const materializedFiles = [];
|
|
11675
|
+
const resolvedTempDirectory = path.resolve(input.tempDirectory);
|
|
11676
|
+
for (const relativePath of input.files) {
|
|
11677
|
+
const content = yield* input.readContent(relativePath).pipe(Effect.orElseSucceed(() => null));
|
|
11678
|
+
if (content === null) continue;
|
|
11679
|
+
const candidateTargetPath = path.resolve(resolvedTempDirectory, relativePath);
|
|
11680
|
+
if (!isPathInsideDirectory(candidateTargetPath, resolvedTempDirectory)) continue;
|
|
11681
|
+
yield* Effect.sync(() => {
|
|
11682
|
+
fs.mkdirSync(path.dirname(candidateTargetPath), { recursive: true });
|
|
11683
|
+
fs.writeFileSync(candidateTargetPath, content);
|
|
11684
|
+
});
|
|
11685
|
+
materializedFiles.push(relativePath);
|
|
11686
|
+
}
|
|
11687
|
+
yield* Effect.sync(() => {
|
|
11688
|
+
for (const configFilename of STAGED_FILES_PROJECT_CONFIG_FILENAMES) {
|
|
11689
|
+
const sourcePath = path.join(input.directory, configFilename);
|
|
11690
|
+
const targetPath = path.join(resolvedTempDirectory, configFilename);
|
|
11691
|
+
if (fs.existsSync(sourcePath) && !fs.existsSync(targetPath)) fs.cpSync(sourcePath, targetPath);
|
|
11692
|
+
}
|
|
11693
|
+
});
|
|
11694
|
+
return {
|
|
11695
|
+
tempDirectory: input.tempDirectory,
|
|
11696
|
+
materializedFiles,
|
|
11697
|
+
cleanup: () => {
|
|
11698
|
+
try {
|
|
11699
|
+
fs.rmSync(input.tempDirectory, {
|
|
11700
|
+
recursive: true,
|
|
11701
|
+
force: true
|
|
11702
|
+
});
|
|
11703
|
+
} catch {}
|
|
11704
|
+
}
|
|
11705
|
+
};
|
|
11706
|
+
});
|
|
11707
|
+
/**
|
|
11575
11708
|
* `StagedFiles` materializes the git-staged source files of a
|
|
11576
11709
|
* directory into a temp tree (mirroring the project layout and
|
|
11577
11710
|
* carrying over a fixed set of project config files) so oxlint can
|
|
@@ -11588,40 +11721,16 @@ var StagedFiles = class StagedFiles extends Context.Service()("react-doctor/Stag
|
|
|
11588
11721
|
const git = yield* Git;
|
|
11589
11722
|
return StagedFiles.of({
|
|
11590
11723
|
discoverSourceFiles: (directory) => git.stagedFilePaths(directory).pipe(Effect.map((entries) => entries.filter(isLintableSourceFile))),
|
|
11591
|
-
materialize: ({ directory, stagedFiles, tempDirectory }) =>
|
|
11592
|
-
|
|
11593
|
-
|
|
11594
|
-
|
|
11595
|
-
|
|
11596
|
-
|
|
11597
|
-
|
|
11598
|
-
|
|
11599
|
-
|
|
11600
|
-
|
|
11601
|
-
fs$1.writeFileSync(candidateTargetPath, content);
|
|
11602
|
-
});
|
|
11603
|
-
materializedFiles.push(relativePath);
|
|
11604
|
-
}
|
|
11605
|
-
yield* Effect.sync(() => {
|
|
11606
|
-
for (const configFilename of STAGED_FILES_PROJECT_CONFIG_FILENAMES) {
|
|
11607
|
-
const sourcePath = path$1.join(directory, configFilename);
|
|
11608
|
-
const targetPath = path$1.join(resolvedTempDirectory, configFilename);
|
|
11609
|
-
if (fs$1.existsSync(sourcePath) && !fs$1.existsSync(targetPath)) fs$1.cpSync(sourcePath, targetPath);
|
|
11610
|
-
}
|
|
11611
|
-
});
|
|
11612
|
-
return {
|
|
11613
|
-
tempDirectory,
|
|
11614
|
-
stagedFiles: materializedFiles,
|
|
11615
|
-
cleanup: () => {
|
|
11616
|
-
try {
|
|
11617
|
-
fs$1.rmSync(tempDirectory, {
|
|
11618
|
-
recursive: true,
|
|
11619
|
-
force: true
|
|
11620
|
-
});
|
|
11621
|
-
} catch {}
|
|
11622
|
-
}
|
|
11623
|
-
};
|
|
11624
|
-
})
|
|
11724
|
+
materialize: ({ directory, stagedFiles, tempDirectory }) => materializeSourceTree({
|
|
11725
|
+
directory,
|
|
11726
|
+
files: stagedFiles,
|
|
11727
|
+
tempDirectory,
|
|
11728
|
+
readContent: (relativePath) => git.showStagedContent(directory, relativePath, { maxBufferBytes: GIT_SHOW_MAX_BUFFER_BYTES })
|
|
11729
|
+
}).pipe(Effect.map((tree) => ({
|
|
11730
|
+
tempDirectory: tree.tempDirectory,
|
|
11731
|
+
stagedFiles: tree.materializedFiles,
|
|
11732
|
+
cleanup: tree.cleanup
|
|
11733
|
+
})))
|
|
11625
11734
|
});
|
|
11626
11735
|
}));
|
|
11627
11736
|
/**
|
|
@@ -11668,18 +11777,22 @@ const safeGetErrorChain = (error) => {
|
|
|
11668
11777
|
};
|
|
11669
11778
|
const buildJsonReportError = (input) => {
|
|
11670
11779
|
const chain = safeGetErrorChain(input.error);
|
|
11780
|
+
const sentryEventId = input.sentryEventId ?? null;
|
|
11671
11781
|
const errorPayload = isReactDoctorError(input.error) ? {
|
|
11672
11782
|
message: formatReactDoctorError(input.error),
|
|
11673
11783
|
name: `ReactDoctorError(${input.error.reason._tag})`,
|
|
11674
|
-
chain
|
|
11784
|
+
chain,
|
|
11785
|
+
sentryEventId
|
|
11675
11786
|
} : input.error instanceof Error ? {
|
|
11676
11787
|
message: input.error.message || input.error.name || "Error",
|
|
11677
11788
|
name: input.error.name || "Error",
|
|
11678
|
-
chain
|
|
11789
|
+
chain,
|
|
11790
|
+
sentryEventId
|
|
11679
11791
|
} : {
|
|
11680
11792
|
message: safeStringify(input.error),
|
|
11681
11793
|
name: "Error",
|
|
11682
|
-
chain
|
|
11794
|
+
chain,
|
|
11795
|
+
sentryEventId
|
|
11683
11796
|
};
|
|
11684
11797
|
return {
|
|
11685
11798
|
schemaVersion: 1,
|
|
@@ -11755,12 +11868,10 @@ const buildJsonReport = (input) => {
|
|
|
11755
11868
|
const flattenedDiagnostics = projects.flatMap((entry) => entry.diagnostics);
|
|
11756
11869
|
const worstScoredProject = findWorstScoredProject(projects);
|
|
11757
11870
|
const summary = summarizeDiagnostics(flattenedDiagnostics, worstScoredProject?.score?.score ?? null, worstScoredProject?.score?.label ?? null);
|
|
11758
|
-
|
|
11759
|
-
schemaVersion: 1,
|
|
11871
|
+
const shared = {
|
|
11760
11872
|
version: input.version,
|
|
11761
11873
|
ok: true,
|
|
11762
11874
|
directory: input.directory,
|
|
11763
|
-
mode: input.mode,
|
|
11764
11875
|
diff: toJsonDiff(input.diff),
|
|
11765
11876
|
projects,
|
|
11766
11877
|
diagnostics: flattenedDiagnostics,
|
|
@@ -11768,6 +11879,22 @@ const buildJsonReport = (input) => {
|
|
|
11768
11879
|
elapsedMilliseconds: input.totalElapsedMilliseconds,
|
|
11769
11880
|
error: null
|
|
11770
11881
|
};
|
|
11882
|
+
if (input.baseline) return {
|
|
11883
|
+
schemaVersion: 2,
|
|
11884
|
+
mode: "baseline",
|
|
11885
|
+
baseline: {
|
|
11886
|
+
baseRef: input.baseline.baseRef,
|
|
11887
|
+
newCount: summary.totalDiagnosticCount,
|
|
11888
|
+
fixedCount: input.baseline.fixedCount,
|
|
11889
|
+
baseTotalCount: input.baseline.baseTotalCount
|
|
11890
|
+
},
|
|
11891
|
+
...shared
|
|
11892
|
+
};
|
|
11893
|
+
return {
|
|
11894
|
+
schemaVersion: 1,
|
|
11895
|
+
mode: input.mode,
|
|
11896
|
+
...shared
|
|
11897
|
+
};
|
|
11771
11898
|
};
|
|
11772
11899
|
/**
|
|
11773
11900
|
* Single source of truth for the skipped-check accounting shared by the
|
|
@@ -11789,6 +11916,45 @@ const buildSkippedChecks = (input) => {
|
|
|
11789
11916
|
skippedCheckReasons
|
|
11790
11917
|
};
|
|
11791
11918
|
};
|
|
11919
|
+
const fingerprintDiagnostic = (diagnostic, lineText) => {
|
|
11920
|
+
const ruleKey = `${diagnostic.plugin}/${diagnostic.rule}`;
|
|
11921
|
+
const snippet = lineText === null ? "" : createHash("sha1").update(lineText.trim()).digest("hex");
|
|
11922
|
+
return `${diagnostic.filePath}\u0000${ruleKey}\u0000${snippet}`;
|
|
11923
|
+
};
|
|
11924
|
+
/**
|
|
11925
|
+
* Diffs a head scan against a base scan to isolate the diagnostics a change
|
|
11926
|
+
* introduced (and count the ones it resolved). Matching is a multiset over a
|
|
11927
|
+
* position-independent fingerprint — `(filePath, plugin/rule, hash(flagged
|
|
11928
|
+
* line text))` — so inserting lines above an existing issue doesn't make it
|
|
11929
|
+
* look new, while a genuinely new occurrence (new line text, or one more of
|
|
11930
|
+
* the same) surfaces. Identical repeated findings are matched by count.
|
|
11931
|
+
*
|
|
11932
|
+
* v1 limitation: the fingerprint keys on the head-relative `filePath`, and base
|
|
11933
|
+
* content is read at that same path. A file renamed by the change therefore has
|
|
11934
|
+
* no base match, so its pre-existing findings are reported as new. This
|
|
11935
|
+
* over-reports (never hides a real issue) and is rare; rename-aware base
|
|
11936
|
+
* resolution is a follow-up.
|
|
11937
|
+
*/
|
|
11938
|
+
const computeDiagnosticDelta = (input) => {
|
|
11939
|
+
const unmatchedBaseByFingerprint = /* @__PURE__ */ new Map();
|
|
11940
|
+
for (const diagnostic of input.baseDiagnostics) {
|
|
11941
|
+
const key = fingerprintDiagnostic(diagnostic, input.readBaseLine(diagnostic.filePath, diagnostic.line));
|
|
11942
|
+
unmatchedBaseByFingerprint.set(key, (unmatchedBaseByFingerprint.get(key) ?? 0) + 1);
|
|
11943
|
+
}
|
|
11944
|
+
const newDiagnostics = [];
|
|
11945
|
+
for (const diagnostic of input.headDiagnostics) {
|
|
11946
|
+
const key = fingerprintDiagnostic(diagnostic, input.readHeadLine(diagnostic.filePath, diagnostic.line));
|
|
11947
|
+
const availableMatches = unmatchedBaseByFingerprint.get(key) ?? 0;
|
|
11948
|
+
if (availableMatches > 0) unmatchedBaseByFingerprint.set(key, availableMatches - 1);
|
|
11949
|
+
else newDiagnostics.push(diagnostic);
|
|
11950
|
+
}
|
|
11951
|
+
let fixedCount = 0;
|
|
11952
|
+
for (const remaining of unmatchedBaseByFingerprint.values()) fixedCount += remaining;
|
|
11953
|
+
return {
|
|
11954
|
+
newDiagnostics,
|
|
11955
|
+
fixedCount
|
|
11956
|
+
};
|
|
11957
|
+
};
|
|
11792
11958
|
/**
|
|
11793
11959
|
* Programmatic façade over `Git.diffSelection`. Async because the
|
|
11794
11960
|
* Git service runs through Effect's `ChildProcess` (true subprocess
|
|
@@ -11811,6 +11977,7 @@ const getDiffInfo = (directory, explicitBaseBranch) => Effect.runPromise(Effect.
|
|
|
11811
11977
|
return {
|
|
11812
11978
|
currentBranch: selection.currentBranch,
|
|
11813
11979
|
baseBranch: selection.baseBranch,
|
|
11980
|
+
...selection.diffBaseRef !== void 0 ? { diffBaseRef: selection.diffBaseRef } : {},
|
|
11814
11981
|
changedFiles: [...selection.changedFiles],
|
|
11815
11982
|
...selection.isCurrentChanges ? { isCurrentChanges: true } : {}
|
|
11816
11983
|
};
|
|
@@ -11870,10 +12037,9 @@ const CI_PROVIDER_BY_ENVIRONMENT_VARIABLE = [
|
|
|
11870
12037
|
];
|
|
11871
12038
|
const GITHUB_ACTION_MARKER_ENVIRONMENT_VARIABLE = "REACT_DOCTOR_GITHUB_ACTION";
|
|
11872
12039
|
const ACTION_INPUT_ENVIRONMENT_VARIABLES = {
|
|
11873
|
-
|
|
11874
|
-
nonBlocking: "REACT_DOCTOR_ACTION_NON_BLOCKING",
|
|
12040
|
+
blocking: "REACT_DOCTOR_ACTION_BLOCKING",
|
|
11875
12041
|
comment: "REACT_DOCTOR_ACTION_COMMENT",
|
|
11876
|
-
|
|
12042
|
+
reviewComments: "REACT_DOCTOR_ACTION_REVIEW_COMMENTS",
|
|
11877
12043
|
version: "REACT_DOCTOR_ACTION_VERSION"
|
|
11878
12044
|
};
|
|
11879
12045
|
const CODING_AGENT_BY_ENVIRONMENT_VARIABLE = [
|
|
@@ -11945,6 +12111,7 @@ const isNonInteractiveEnvironment = () => NON_INTERACTIVE_ENVIRONMENT_VARIABLES.
|
|
|
11945
12111
|
//#endregion
|
|
11946
12112
|
//#region src/cli/utils/constants.ts
|
|
11947
12113
|
const STAGED_FILES_TEMP_DIR_PREFIX = "react-doctor-staged-";
|
|
12114
|
+
const BASELINE_FILES_TEMP_DIR_PREFIX = "react-doctor-baseline-";
|
|
11948
12115
|
const CI_TRUST_COMPANIES = "PayPal, Rippling, and Alibaba";
|
|
11949
12116
|
const WELCOME_EXPLANATION_HOLD_MS = 1e3;
|
|
11950
12117
|
const CATEGORY_COUNTUP_SETTLE_HOLD_MS = 1e3;
|
|
@@ -11962,6 +12129,7 @@ const METRIC = {
|
|
|
11962
12129
|
scanScore: "scan.score",
|
|
11963
12130
|
scanClean: "scan.clean",
|
|
11964
12131
|
scanCheckSkipped: "scan.check_skipped",
|
|
12132
|
+
baselineDegraded: "baseline.degraded",
|
|
11965
12133
|
ruleFired: "rule.fired",
|
|
11966
12134
|
lintFailed: "lint.failed",
|
|
11967
12135
|
deadCodeFailed: "deadcode.failed",
|
|
@@ -11976,7 +12144,11 @@ const METRIC = {
|
|
|
11976
12144
|
installAgentHooks: "install.agent_hooks",
|
|
11977
12145
|
installDependency: "install.dependency",
|
|
11978
12146
|
rulesChanged: "rules.changed",
|
|
11979
|
-
rulesQueried: "rules.queried"
|
|
12147
|
+
rulesQueried: "rules.queried",
|
|
12148
|
+
lspSessionStarted: "lsp.session.started",
|
|
12149
|
+
lspScanCompleted: "lsp.scan.completed",
|
|
12150
|
+
lspScanDuration: "lsp.scan.duration",
|
|
12151
|
+
lspScanDiagnostics: "lsp.scan.diagnostics"
|
|
11980
12152
|
};
|
|
11981
12153
|
//#endregion
|
|
11982
12154
|
//#region src/cli/utils/noop-console.ts
|
|
@@ -12019,7 +12191,7 @@ const makeNoopConsole = () => ({
|
|
|
12019
12191
|
});
|
|
12020
12192
|
//#endregion
|
|
12021
12193
|
//#region src/cli/utils/version.ts
|
|
12022
|
-
const VERSION = "0.
|
|
12194
|
+
const VERSION = "0.4.0-dev.a5c6993";
|
|
12023
12195
|
//#endregion
|
|
12024
12196
|
//#region src/cli/utils/json-mode.ts
|
|
12025
12197
|
let context = null;
|
|
@@ -12077,7 +12249,7 @@ const writeJsonReport = (report) => {
|
|
|
12077
12249
|
const serialized = context?.compact ? JSON.stringify(report) : JSON.stringify(report, null, 2);
|
|
12078
12250
|
process.stdout.write(`${serialized}\n`);
|
|
12079
12251
|
};
|
|
12080
|
-
const writeJsonErrorReport = (error) => {
|
|
12252
|
+
const writeJsonErrorReport = (error, sentryEventId) => {
|
|
12081
12253
|
if (!context) return;
|
|
12082
12254
|
try {
|
|
12083
12255
|
writeJsonReport(buildJsonReportError({
|
|
@@ -12085,7 +12257,8 @@ const writeJsonErrorReport = (error) => {
|
|
|
12085
12257
|
directory: context.directory,
|
|
12086
12258
|
error,
|
|
12087
12259
|
elapsedMilliseconds: performance.now() - context.startTime,
|
|
12088
|
-
mode: context.mode
|
|
12260
|
+
mode: context.mode,
|
|
12261
|
+
sentryEventId
|
|
12089
12262
|
}));
|
|
12090
12263
|
} catch {
|
|
12091
12264
|
process.stdout.write(INTERNAL_ERROR_JSON_FALLBACK);
|
|
@@ -12356,15 +12529,14 @@ const scrubSentryMetric = (metric) => {
|
|
|
12356
12529
|
}
|
|
12357
12530
|
};
|
|
12358
12531
|
//#endregion
|
|
12359
|
-
//#region src/
|
|
12360
|
-
|
|
12361
|
-
|
|
12362
|
-
|
|
12363
|
-
|
|
12364
|
-
|
|
12365
|
-
|
|
12366
|
-
|
|
12367
|
-
const isEnvFlagEnabled = (value) => value === "1" || value?.toLowerCase() === "true";
|
|
12532
|
+
//#region src/cli/utils/sentry-config.ts
|
|
12533
|
+
/**
|
|
12534
|
+
* Shared Sentry configuration resolution — release, environment, and tracing
|
|
12535
|
+
* sample rate — derived from `VERSION` and the standard `SENTRY_*` env
|
|
12536
|
+
* overrides. Lives apart from `instrument.ts` (the CLI's run-context-aware
|
|
12537
|
+
* init) so both the CLI and the editor language server can resolve identical
|
|
12538
|
+
* release/environment values without the LSP pulling in CLI run-context code.
|
|
12539
|
+
*/
|
|
12368
12540
|
/**
|
|
12369
12541
|
* A version is a "dev" build when it's the unbuilt placeholder (`0.0.0`) or
|
|
12370
12542
|
* carries a prerelease suffix (e.g. the `-dev.<sha>` snapshots published from
|
|
@@ -12377,13 +12549,13 @@ const isDevVersion = (version) => version === "0.0.0" || version.includes("-");
|
|
|
12377
12549
|
* uploads source-map artifacts under, so stack frames symbolicate. Honors the
|
|
12378
12550
|
* standard `SENTRY_RELEASE` override.
|
|
12379
12551
|
*/
|
|
12380
|
-
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.
|
|
12552
|
+
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.4.0-dev.a5c6993`;
|
|
12381
12553
|
/**
|
|
12382
12554
|
* Deployment environment shown in Sentry's environment filter. Defaults to
|
|
12383
12555
|
* `production` for tagged releases and `development` for dev/unbuilt versions,
|
|
12384
12556
|
* overridable via the standard `SENTRY_ENVIRONMENT` env var.
|
|
12385
12557
|
*/
|
|
12386
|
-
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.
|
|
12558
|
+
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.4.0-dev.a5c6993") ? "development" : "production");
|
|
12387
12559
|
/**
|
|
12388
12560
|
* Performance-tracing sample rate in `[0, 1]`. Reads `SENTRY_TRACES_SAMPLE_RATE`
|
|
12389
12561
|
* (set to `0` to disable tracing) and falls back to
|
|
@@ -12397,6 +12569,16 @@ const resolveTracesSampleRate = () => {
|
|
|
12397
12569
|
if (Number.isNaN(parsed) || parsed < 0 || parsed > 1) return 1;
|
|
12398
12570
|
return parsed;
|
|
12399
12571
|
};
|
|
12572
|
+
//#endregion
|
|
12573
|
+
//#region src/instrument.ts
|
|
12574
|
+
let isInitialized = false;
|
|
12575
|
+
let resolvedTracesSampleRate = 0;
|
|
12576
|
+
const shouldEnableSentry = () => {
|
|
12577
|
+
if (process.argv.includes("--no-score") || process.argv.includes("--no-telemetry")) return false;
|
|
12578
|
+
if (process.env.VITEST || process.env.NODE_ENV === "test") return false;
|
|
12579
|
+
return true;
|
|
12580
|
+
};
|
|
12581
|
+
const isEnvFlagEnabled = (value) => value === "1" || value?.toLowerCase() === "true";
|
|
12400
12582
|
/**
|
|
12401
12583
|
* Whether performance traces will actually be recorded — Sentry is live and the
|
|
12402
12584
|
* resolved sample rate is above zero. Used to gate the per-run root span and
|
|
@@ -15838,6 +16020,7 @@ const recordScanMetrics = (input) => {
|
|
|
15838
16020
|
if (result.diagnostics.length === 0 && !hasSkippedChecks) recordCount(METRIC.scanClean, 1, { mode: input.mode });
|
|
15839
16021
|
if (result.score) recordDistribution(METRIC.scanScore, result.score.score, { attributes: { mode: input.mode } });
|
|
15840
16022
|
else if (!input.noScore && !input.didLintFail) recordCount(METRIC.scoreUnavailable, 1, { mode: input.mode });
|
|
16023
|
+
if (input.baselineDegraded) recordCount(METRIC.baselineDegraded, 1);
|
|
15841
16024
|
if (input.didLintFail) recordCount(METRIC.lintFailed, 1, { reasonKind: input.lintFailureReasonKind });
|
|
15842
16025
|
if (input.didDeadCodeFail) recordCount(METRIC.deadCodeFailed, 1);
|
|
15843
16026
|
for (const check of result.skippedChecks) recordCount(METRIC.scanCheckSkipped, 1, {
|
|
@@ -15846,19 +16029,74 @@ const recordScanMetrics = (input) => {
|
|
|
15846
16029
|
});
|
|
15847
16030
|
};
|
|
15848
16031
|
//#endregion
|
|
15849
|
-
//#region src/cli/utils/
|
|
15850
|
-
|
|
15851
|
-
|
|
15852
|
-
|
|
15853
|
-
|
|
16032
|
+
//#region src/cli/utils/cli-logger.ts
|
|
16033
|
+
/**
|
|
16034
|
+
* Thin synchronous façade over Effect's `Console` module. Used by
|
|
16035
|
+
* the imperative CLI helper files (`select-projects`, `run-explain`,
|
|
16036
|
+
* `install-react-doctor`, the legacy paths in `cli/commands/inspect.ts`)
|
|
16037
|
+
* that aren't yet Effect-typed. Every call drains into a single
|
|
16038
|
+
* `Console.*` Effect via `Effect.runSync`, so the underlying logging
|
|
16039
|
+
* pipeline is identical to the canonical `yield* Console.log(...)`
|
|
16040
|
+
* call sites in the renderers. Convert callers to `Effect.gen` to
|
|
16041
|
+
* drop the bridge.
|
|
16042
|
+
*/
|
|
16043
|
+
const cliLogger = {
|
|
16044
|
+
log: (message) => {
|
|
16045
|
+
Effect.runSync(Console.log(message));
|
|
16046
|
+
},
|
|
16047
|
+
warn: (message) => {
|
|
16048
|
+
Effect.runSync(Console.warn(highlighter.warn(message)));
|
|
16049
|
+
},
|
|
16050
|
+
error: (message) => {
|
|
16051
|
+
Effect.runSync(Console.error(highlighter.error(message)));
|
|
16052
|
+
},
|
|
16053
|
+
info: (message) => {
|
|
16054
|
+
Effect.runSync(Console.info(highlighter.info(message)));
|
|
16055
|
+
},
|
|
16056
|
+
dim: (message) => {
|
|
16057
|
+
Effect.runSync(Console.log(highlighter.gray(message)));
|
|
16058
|
+
},
|
|
16059
|
+
success: (message) => {
|
|
16060
|
+
Effect.runSync(Console.log(highlighter.success(message)));
|
|
16061
|
+
},
|
|
16062
|
+
break: () => {
|
|
16063
|
+
Effect.runSync(Console.log(""));
|
|
16064
|
+
}
|
|
15854
16065
|
};
|
|
15855
16066
|
//#endregion
|
|
15856
|
-
//#region src/cli/utils/
|
|
15857
|
-
const
|
|
16067
|
+
//#region src/cli/utils/resolve-blocking-level.ts
|
|
16068
|
+
const VALID_BLOCKING_LEVELS = new Set([
|
|
15858
16069
|
"error",
|
|
15859
16070
|
"warning",
|
|
15860
16071
|
"none"
|
|
15861
16072
|
]);
|
|
16073
|
+
const DEFAULT_BLOCKING_LEVEL = "error";
|
|
16074
|
+
const isValidBlockingLevel = (level) => VALID_BLOCKING_LEVELS.has(level);
|
|
16075
|
+
const pickBlockingLevel = (flags, userConfig) => flags.blocking ?? flags.failOn ?? userConfig?.blocking ?? userConfig?.failOn;
|
|
16076
|
+
const resolveBlockingLevel = (flags, userConfig) => {
|
|
16077
|
+
const sourceValue = pickBlockingLevel(flags, userConfig) ?? DEFAULT_BLOCKING_LEVEL;
|
|
16078
|
+
if (isValidBlockingLevel(sourceValue)) return sourceValue;
|
|
16079
|
+
cliLogger.warn(`Invalid blocking level "${sourceValue}". Expected one of: error, warning, none. Falling back to "${DEFAULT_BLOCKING_LEVEL}".`);
|
|
16080
|
+
return DEFAULT_BLOCKING_LEVEL;
|
|
16081
|
+
};
|
|
16082
|
+
//#endregion
|
|
16083
|
+
//#region src/cli/utils/should-block-ci.ts
|
|
16084
|
+
const shouldBlockCi = (diagnostics, blockingLevel) => {
|
|
16085
|
+
if (blockingLevel === "none") return false;
|
|
16086
|
+
if (blockingLevel === "warning") return diagnostics.length > 0;
|
|
16087
|
+
return diagnostics.some((diagnostic) => diagnostic.severity === "error");
|
|
16088
|
+
};
|
|
16089
|
+
//#endregion
|
|
16090
|
+
//#region src/cli/utils/to-category-key.ts
|
|
16091
|
+
/**
|
|
16092
|
+
* Lowercase, key-safe form of a rule category for the `diag.category.*`
|
|
16093
|
+
* telemetry attribute namespace (categories carry spaces / capitals, e.g.
|
|
16094
|
+
* "Performance" → `performance`, "Dead Code" → `dead_code`). Shared by the
|
|
16095
|
+
* CLI run event and the editor LSP wide event so both namespace identically.
|
|
16096
|
+
*/
|
|
16097
|
+
const toCategoryKey = (category) => category.toLowerCase().replace(/[^a-z0-9]+/g, "_");
|
|
16098
|
+
//#endregion
|
|
16099
|
+
//#region src/cli/utils/build-run-event.ts
|
|
15862
16100
|
const readEnvBoolean = (name) => {
|
|
15863
16101
|
const value = process.env[name];
|
|
15864
16102
|
if (value === void 0) return null;
|
|
@@ -15870,12 +16108,11 @@ const resolveVersionPin = (versionInput) => {
|
|
|
15870
16108
|
if (/^(\.\.?\/|\/)/.test(versionInput)) return "local";
|
|
15871
16109
|
return "pinned";
|
|
15872
16110
|
};
|
|
15873
|
-
const
|
|
15874
|
-
const fromAction = process.env[ACTION_INPUT_ENVIRONMENT_VARIABLES.
|
|
15875
|
-
if (fromAction !== void 0 &&
|
|
15876
|
-
return userConfig?.failOn ?? "
|
|
16111
|
+
const resolveTelemetryBlocking = (userConfig) => {
|
|
16112
|
+
const fromAction = process.env[ACTION_INPUT_ENVIRONMENT_VARIABLES.blocking];
|
|
16113
|
+
if (fromAction !== void 0 && isValidBlockingLevel(fromAction)) return fromAction;
|
|
16114
|
+
return userConfig?.blocking ?? userConfig?.failOn ?? "error";
|
|
15877
16115
|
};
|
|
15878
|
-
const toCategoryKey = (category) => category.toLowerCase().replace(/[^a-z0-9]+/g, "_");
|
|
15879
16116
|
const buildOutcomeAttributes = (input) => {
|
|
15880
16117
|
if (input.result === void 0) {
|
|
15881
16118
|
const error = input.error;
|
|
@@ -15889,9 +16126,9 @@ const buildOutcomeAttributes = (input) => {
|
|
|
15889
16126
|
}
|
|
15890
16127
|
const result = input.result;
|
|
15891
16128
|
const summary = summarizeDiagnostics(result.diagnostics);
|
|
15892
|
-
const
|
|
16129
|
+
const blockingLevel = resolveTelemetryBlocking(input.userConfig);
|
|
15893
16130
|
const gateDiagnostics = filterDiagnosticsForSurface(result.diagnostics, "ciFailure", input.userConfig);
|
|
15894
|
-
const wouldBlock = !input.scoreOnly &&
|
|
16131
|
+
const wouldBlock = !input.scoreOnly && !input.gateExempt && shouldBlockCi(gateDiagnostics, blockingLevel);
|
|
15895
16132
|
const hasSkippedChecks = result.skippedChecks.length > 0;
|
|
15896
16133
|
const isClean = result.diagnostics.length === 0 && !hasSkippedChecks;
|
|
15897
16134
|
const outcome = wouldBlock ? "blocked" : isClean ? "clean" : "ok";
|
|
@@ -15912,7 +16149,7 @@ const buildOutcomeAttributes = (input) => {
|
|
|
15912
16149
|
outcome,
|
|
15913
16150
|
exitCode: wouldBlock ? 1 : 0,
|
|
15914
16151
|
wouldBlock,
|
|
15915
|
-
|
|
16152
|
+
blocking: blockingLevel,
|
|
15916
16153
|
scanClean: isClean,
|
|
15917
16154
|
totalDiagnostics: summary.totalDiagnosticCount,
|
|
15918
16155
|
errorCount: summary.errorCount,
|
|
@@ -15933,6 +16170,12 @@ const buildOutcomeAttributes = (input) => {
|
|
|
15933
16170
|
didDeadCodeFail: input.didDeadCodeFail ?? null
|
|
15934
16171
|
};
|
|
15935
16172
|
for (const [category, count] of countByCategory) attributes[`diag.category.${toCategoryKey(category)}`] = count;
|
|
16173
|
+
if (result.baselineDelta) {
|
|
16174
|
+
attributes["baseline.new"] = summary.totalDiagnosticCount;
|
|
16175
|
+
attributes["baseline.fixed"] = result.baselineDelta.fixedCount;
|
|
16176
|
+
attributes["baseline.baseTotal"] = result.baselineDelta.baseTotalCount;
|
|
16177
|
+
attributes["baseline.degraded"] = false;
|
|
16178
|
+
} else if (input.gateExempt) attributes["baseline.degraded"] = true;
|
|
15936
16179
|
return attributes;
|
|
15937
16180
|
};
|
|
15938
16181
|
const buildCiAttributes = () => {
|
|
@@ -15940,9 +16183,8 @@ const buildCiAttributes = () => {
|
|
|
15940
16183
|
return {
|
|
15941
16184
|
actorAssociation: githubActorAssociation ?? null,
|
|
15942
16185
|
runnerOs: detectRunnerOs(),
|
|
15943
|
-
nonBlocking: readEnvBoolean(ACTION_INPUT_ENVIRONMENT_VARIABLES.nonBlocking),
|
|
15944
16186
|
comment: readEnvBoolean(ACTION_INPUT_ENVIRONMENT_VARIABLES.comment),
|
|
15945
|
-
|
|
16187
|
+
reviewComments: readEnvBoolean(ACTION_INPUT_ENVIRONMENT_VARIABLES.reviewComments),
|
|
15946
16188
|
versionPin: resolveVersionPin(process.env[ACTION_INPUT_ENVIRONMENT_VARIABLES.version])
|
|
15947
16189
|
};
|
|
15948
16190
|
};
|
|
@@ -15992,6 +16234,66 @@ const recordRunEvent = (rootSpan, input) => {
|
|
|
15992
16234
|
} catch {}
|
|
15993
16235
|
};
|
|
15994
16236
|
//#endregion
|
|
16237
|
+
//#region src/cli/utils/materialize-baseline-files.ts
|
|
16238
|
+
/**
|
|
16239
|
+
* Materializes the `ref` version of `files` into `tempDirectory` (via
|
|
16240
|
+
* `git show <ref>:<path>`), mirroring the project layout + head's config files
|
|
16241
|
+
* so the base lints under the same rules as head. Reuses the shared,
|
|
16242
|
+
* zip-slip-guarded `materializeSourceTree`. Per-file read misses (e.g. a file
|
|
16243
|
+
* the PR added, absent at base) are skipped, which is exactly what we want:
|
|
16244
|
+
* a brand-new file has no base counterpart, so all its findings are "new".
|
|
16245
|
+
*/
|
|
16246
|
+
const materializeBaselineFiles = (input) => Effect.runPromise(Effect.gen(function* () {
|
|
16247
|
+
const git = yield* Git;
|
|
16248
|
+
return yield* materializeSourceTree({
|
|
16249
|
+
directory: input.directory,
|
|
16250
|
+
files: input.files,
|
|
16251
|
+
tempDirectory: input.tempDirectory,
|
|
16252
|
+
readContent: (relativePath) => git.showRefContent({
|
|
16253
|
+
directory: input.directory,
|
|
16254
|
+
ref: input.ref,
|
|
16255
|
+
relativePath,
|
|
16256
|
+
options: { maxBufferBytes: GIT_SHOW_MAX_BUFFER_BYTES }
|
|
16257
|
+
})
|
|
16258
|
+
});
|
|
16259
|
+
}).pipe(Effect.provide(Git.layerNode)));
|
|
16260
|
+
/**
|
|
16261
|
+
* Resolves the commit a baseline scan should read base content from — the
|
|
16262
|
+
* merge-base of `ref` and HEAD, so "introduced" is measured against the branch
|
|
16263
|
+
* point. `null` when unresolvable (ref missing/unsafe, no merge-base).
|
|
16264
|
+
*/
|
|
16265
|
+
const resolveMergeBaseRef = async (directory, ref) => {
|
|
16266
|
+
try {
|
|
16267
|
+
return await Effect.runPromise(Effect.gen(function* () {
|
|
16268
|
+
return yield* (yield* Git).mergeBase({
|
|
16269
|
+
directory,
|
|
16270
|
+
ref
|
|
16271
|
+
});
|
|
16272
|
+
}).pipe(Effect.provide(Git.layerNode)));
|
|
16273
|
+
} catch {
|
|
16274
|
+
return null;
|
|
16275
|
+
}
|
|
16276
|
+
};
|
|
16277
|
+
//#endregion
|
|
16278
|
+
//#region src/cli/utils/read-source-line.ts
|
|
16279
|
+
/**
|
|
16280
|
+
* Builds a cached `(filePath, line) -> source text` reader rooted at
|
|
16281
|
+
* `rootDirectory`, used to fingerprint a diagnostic by the content of its
|
|
16282
|
+
* flagged line (see `computeDiagnosticDelta`). Wraps core's
|
|
16283
|
+
* `createNodeReadFileLinesSync` with per-file memoization + 1-indexed line
|
|
16284
|
+
* lookup; unreadable files / out-of-range lines return `null`.
|
|
16285
|
+
*/
|
|
16286
|
+
const createSourceLineReader = (rootDirectory) => {
|
|
16287
|
+
const readFileLines = createNodeReadFileLinesSync(rootDirectory);
|
|
16288
|
+
const fileLinesCache = /* @__PURE__ */ new Map();
|
|
16289
|
+
return (filePath, line) => {
|
|
16290
|
+
if (!fileLinesCache.has(filePath)) fileLinesCache.set(filePath, readFileLines(filePath));
|
|
16291
|
+
const lines = fileLinesCache.get(filePath) ?? null;
|
|
16292
|
+
if (lines === null || line < 1 || line > lines.length) return null;
|
|
16293
|
+
return lines[line - 1] ?? null;
|
|
16294
|
+
};
|
|
16295
|
+
};
|
|
16296
|
+
//#endregion
|
|
15995
16297
|
//#region src/cli/utils/build-no-score-message.ts
|
|
15996
16298
|
const ENTERPRISE_CONTACT_HINT = `Want something custom to your company? Contact us at ${ENTERPRISE_CONTACT_URL}.`;
|
|
15997
16299
|
const buildNoScoreMessage = (isScoreDisabled) => {
|
|
@@ -16735,41 +17037,6 @@ const printSummary = (input) => Effect.gen(function* () {
|
|
|
16735
17037
|
if (diagnosticsDirectory !== null && input.verbose) yield* Console.log(highlighter.gray(` Full diagnostics written to ${diagnosticsDirectory}`));
|
|
16736
17038
|
});
|
|
16737
17039
|
//#endregion
|
|
16738
|
-
//#region src/cli/utils/cli-logger.ts
|
|
16739
|
-
/**
|
|
16740
|
-
* Thin synchronous façade over Effect's `Console` module. Used by
|
|
16741
|
-
* the imperative CLI helper files (`select-projects`, `run-explain`,
|
|
16742
|
-
* `install-react-doctor`, the legacy paths in `cli/commands/inspect.ts`)
|
|
16743
|
-
* that aren't yet Effect-typed. Every call drains into a single
|
|
16744
|
-
* `Console.*` Effect via `Effect.runSync`, so the underlying logging
|
|
16745
|
-
* pipeline is identical to the canonical `yield* Console.log(...)`
|
|
16746
|
-
* call sites in the renderers. Convert callers to `Effect.gen` to
|
|
16747
|
-
* drop the bridge.
|
|
16748
|
-
*/
|
|
16749
|
-
const cliLogger = {
|
|
16750
|
-
log: (message) => {
|
|
16751
|
-
Effect.runSync(Console.log(message));
|
|
16752
|
-
},
|
|
16753
|
-
warn: (message) => {
|
|
16754
|
-
Effect.runSync(Console.warn(highlighter.warn(message)));
|
|
16755
|
-
},
|
|
16756
|
-
error: (message) => {
|
|
16757
|
-
Effect.runSync(Console.error(highlighter.error(message)));
|
|
16758
|
-
},
|
|
16759
|
-
info: (message) => {
|
|
16760
|
-
Effect.runSync(Console.info(highlighter.info(message)));
|
|
16761
|
-
},
|
|
16762
|
-
dim: (message) => {
|
|
16763
|
-
Effect.runSync(Console.log(highlighter.gray(message)));
|
|
16764
|
-
},
|
|
16765
|
-
success: (message) => {
|
|
16766
|
-
Effect.runSync(Console.log(highlighter.success(message)));
|
|
16767
|
-
},
|
|
16768
|
-
break: () => {
|
|
16769
|
-
Effect.runSync(Console.log(""));
|
|
16770
|
-
}
|
|
16771
|
-
};
|
|
16772
|
-
//#endregion
|
|
16773
17040
|
//#region src/cli/utils/should-auto-select-current-choice.ts
|
|
16774
17041
|
const shouldAutoSelectCurrentChoice = (choiceStates, cursor) => {
|
|
16775
17042
|
if (choiceStates.some((choiceState) => choiceState.selected)) return false;
|
|
@@ -16912,7 +17179,8 @@ const mergeInspectOptions = (inputOptions, userConfig) => ({
|
|
|
16912
17179
|
ignoredTags: buildIgnoredTags(userConfig),
|
|
16913
17180
|
outputSurface: inputOptions.outputSurface ?? "cli",
|
|
16914
17181
|
suppressRendering: inputOptions.suppressRendering ?? false,
|
|
16915
|
-
concurrency: inputOptions.concurrency
|
|
17182
|
+
concurrency: inputOptions.concurrency,
|
|
17183
|
+
baseline: inputOptions.baseline ?? null
|
|
16916
17184
|
});
|
|
16917
17185
|
const buildRunEventConfig = (options, userConfig, hasCustomConfig) => ({
|
|
16918
17186
|
parallel: options.concurrency !== void 0,
|
|
@@ -16966,6 +17234,75 @@ const inspect = async (directory, inputOptions = {}) => {
|
|
|
16966
17234
|
if (options.silent) setSpinnerSilent(wasSpinnerSilent);
|
|
16967
17235
|
}
|
|
16968
17236
|
};
|
|
17237
|
+
/**
|
|
17238
|
+
* Runs a second, lint-only scan over the changed files as they existed at the
|
|
17239
|
+
* baseline ref (materialized into a temp tree with head's config) and diffs it
|
|
17240
|
+
* against the head diagnostics, returning only the findings the change
|
|
17241
|
+
* introduced plus the fixed / base counts. No score, dead-code, progress, or
|
|
17242
|
+
* telemetry — it's a pure comparison pass. The temp tree is always cleaned up.
|
|
17243
|
+
*/
|
|
17244
|
+
const runBaselineComparison = async (params) => {
|
|
17245
|
+
const tempDirectory = mkdtempSync(path.join(tmpdir(), BASELINE_FILES_TEMP_DIR_PREFIX));
|
|
17246
|
+
const snapshot = await materializeBaselineFiles({
|
|
17247
|
+
directory: params.directory,
|
|
17248
|
+
ref: params.baselineRef,
|
|
17249
|
+
files: params.options.includePaths,
|
|
17250
|
+
tempDirectory
|
|
17251
|
+
}).catch((error) => {
|
|
17252
|
+
rmSync(tempDirectory, {
|
|
17253
|
+
recursive: true,
|
|
17254
|
+
force: true
|
|
17255
|
+
});
|
|
17256
|
+
throw error;
|
|
17257
|
+
});
|
|
17258
|
+
try {
|
|
17259
|
+
const baseLayers = buildRuntimeLayers({
|
|
17260
|
+
directory: snapshot.tempDirectory,
|
|
17261
|
+
hasConfigOverride: true,
|
|
17262
|
+
userConfig: params.userConfig,
|
|
17263
|
+
configSourceDirectory: null,
|
|
17264
|
+
shouldSkipLint: !params.options.lint || !params.resolvedNodeBinaryPath,
|
|
17265
|
+
shouldRunDeadCode: false,
|
|
17266
|
+
shouldComputeScore: false,
|
|
17267
|
+
shouldShowProgressSpinners: false,
|
|
17268
|
+
oxlintConcurrency: params.options.concurrency
|
|
17269
|
+
});
|
|
17270
|
+
const baseProgram = runInspect({
|
|
17271
|
+
directory: snapshot.tempDirectory,
|
|
17272
|
+
includePaths: params.options.includePaths,
|
|
17273
|
+
customRulesOnly: params.options.customRulesOnly,
|
|
17274
|
+
respectInlineDisables: params.options.respectInlineDisables,
|
|
17275
|
+
warnings: params.options.warnings,
|
|
17276
|
+
adoptExistingLintConfig: params.options.adoptExistingLintConfig,
|
|
17277
|
+
ignoredTags: params.options.ignoredTags,
|
|
17278
|
+
nodeBinaryPath: params.resolvedNodeBinaryPath ?? void 0,
|
|
17279
|
+
runDeadCode: false,
|
|
17280
|
+
isCi: params.options.isCi,
|
|
17281
|
+
doctorVersion: VERSION,
|
|
17282
|
+
runId: getRunId(),
|
|
17283
|
+
resolveLocalGithubViewerPermission: false,
|
|
17284
|
+
suppressScanSummary: true
|
|
17285
|
+
}, {});
|
|
17286
|
+
const baseOutput = await Effect.runPromise(restoreLegacyThrow(baseProgram.pipe(Effect.provide(baseLayers), Effect.provideService(Console.Console, silentConsole))));
|
|
17287
|
+
if (baseOutput.didLintFail) return null;
|
|
17288
|
+
const delta = computeDiagnosticDelta({
|
|
17289
|
+
headDiagnostics: params.headDiagnostics,
|
|
17290
|
+
baseDiagnostics: baseOutput.diagnostics,
|
|
17291
|
+
readHeadLine: createSourceLineReader(params.directory),
|
|
17292
|
+
readBaseLine: createSourceLineReader(snapshot.tempDirectory)
|
|
17293
|
+
});
|
|
17294
|
+
return {
|
|
17295
|
+
displayDiagnostics: delta.newDiagnostics,
|
|
17296
|
+
baselineDelta: {
|
|
17297
|
+
baseRef: params.baselineRef,
|
|
17298
|
+
fixedCount: delta.fixedCount,
|
|
17299
|
+
baseTotalCount: baseOutput.diagnostics.length
|
|
17300
|
+
}
|
|
17301
|
+
};
|
|
17302
|
+
} finally {
|
|
17303
|
+
snapshot.cleanup();
|
|
17304
|
+
}
|
|
17305
|
+
};
|
|
16969
17306
|
const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOverride, configSourceDirectory, startTime, rootSentrySpan) => {
|
|
16970
17307
|
const isDiffMode = options.includePaths.length > 0;
|
|
16971
17308
|
const resolvedNodeBinaryPath = await resolveOxlintNode(options.lint, options.scoreOnly || options.silent);
|
|
@@ -17016,7 +17353,23 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
17016
17353
|
const lintFailureReason = lintBindingMissing ? `oxlint native binding not found for Node ${process.version}; expected one matching ${OXLINT_NODE_REQUIREMENT}` : output.lintFailureReason;
|
|
17017
17354
|
if (!options.scoreOnly && !lintBindingMissing && output.didLintFail && lintFailureReason !== null) if (output.lintFailureReasonKind === "native-binding-missing") runConsole(Console.log(highlighter.gray(` Upgrade to Node ${OXLINT_NODE_REQUIREMENT} or run: npx -p oxlint@latest react-doctor@latest`)));
|
|
17018
17355
|
else runConsole(Console.error(highlighter.error(lintFailureReason)));
|
|
17019
|
-
|
|
17356
|
+
let inspectDiagnostics = output.diagnostics;
|
|
17357
|
+
let baselineDelta;
|
|
17358
|
+
if (options.baseline && isDiffMode && !didLintFail) {
|
|
17359
|
+
const comparison = await runBaselineComparison({
|
|
17360
|
+
directory,
|
|
17361
|
+
options,
|
|
17362
|
+
userConfig,
|
|
17363
|
+
headDiagnostics: output.diagnostics,
|
|
17364
|
+
resolvedNodeBinaryPath,
|
|
17365
|
+
baselineRef: options.baseline.ref
|
|
17366
|
+
});
|
|
17367
|
+
if (comparison) {
|
|
17368
|
+
inspectDiagnostics = comparison.displayDiagnostics;
|
|
17369
|
+
baselineDelta = comparison.baselineDelta;
|
|
17370
|
+
}
|
|
17371
|
+
}
|
|
17372
|
+
const baselineDegraded = Boolean(options.baseline) && isDiffMode && baselineDelta === void 0;
|
|
17020
17373
|
const score = didLintFail ? null : output.score;
|
|
17021
17374
|
const elapsedMilliseconds = performance.now() - startTime;
|
|
17022
17375
|
const forceOnboarding = isOnboardingForced();
|
|
@@ -17036,7 +17389,8 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
17036
17389
|
directory: output.resolvedDirectory,
|
|
17037
17390
|
scannedFileCount: output.scannedFileCount,
|
|
17038
17391
|
scannedFilePaths: output.scannedFilePaths,
|
|
17039
|
-
scanElapsedMilliseconds: output.scanElapsedMilliseconds
|
|
17392
|
+
scanElapsedMilliseconds: output.scanElapsedMilliseconds,
|
|
17393
|
+
baselineDelta
|
|
17040
17394
|
};
|
|
17041
17395
|
const result = await Effect.runPromise(finalizeAndRender(finalizeInput).pipe(options.silent ? Effect.provideService(Console.Console, silentConsole) : (program) => program));
|
|
17042
17396
|
if (shouldRecordOnboarding({
|
|
@@ -17045,9 +17399,11 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
17045
17399
|
verbose: options.verbose,
|
|
17046
17400
|
isNonInteractiveEnvironment: options.isNonInteractiveEnvironment
|
|
17047
17401
|
})) markOnboardingComplete();
|
|
17402
|
+
const scanMode = baselineDelta ? "baseline" : isDiffMode ? "diff" : "full";
|
|
17048
17403
|
recordScanMetrics({
|
|
17049
17404
|
result,
|
|
17050
|
-
mode:
|
|
17405
|
+
mode: scanMode,
|
|
17406
|
+
baselineDegraded,
|
|
17051
17407
|
parallel: options.concurrency !== void 0,
|
|
17052
17408
|
workerCount: options.concurrency,
|
|
17053
17409
|
lint: options.lint,
|
|
@@ -17061,7 +17417,8 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
17061
17417
|
recordRunEvent(rootSentrySpan, {
|
|
17062
17418
|
...buildRunEventConfig(options, userConfig, userConfig !== null),
|
|
17063
17419
|
result,
|
|
17064
|
-
mode:
|
|
17420
|
+
mode: scanMode,
|
|
17421
|
+
gateExempt: baselineDegraded,
|
|
17065
17422
|
didLintFail,
|
|
17066
17423
|
lintFailureReasonKind: lintBindingMissing ? "native-binding-missing" : output.lintFailureReasonKind,
|
|
17067
17424
|
lintPartialFailureCount: output.lintPartialFailures.length,
|
|
@@ -17070,7 +17427,7 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
17070
17427
|
return result;
|
|
17071
17428
|
};
|
|
17072
17429
|
const finalizeAndRender = (input) => Effect.gen(function* () {
|
|
17073
|
-
const { options, elapsedMilliseconds, diagnostics, score, project, userConfig, didLintFail, lintFailureReason, lintPartialFailures, didDeadCodeFail, deadCodeFailureReason, directory, scannedFileCount, scannedFilePaths, scanElapsedMilliseconds } = input;
|
|
17430
|
+
const { options, elapsedMilliseconds, diagnostics, score, project, userConfig, didLintFail, lintFailureReason, lintPartialFailures, didDeadCodeFail, deadCodeFailureReason, directory, scannedFileCount, scannedFilePaths, scanElapsedMilliseconds, baselineDelta } = input;
|
|
17074
17431
|
const { skippedChecks, skippedCheckReasons } = buildSkippedChecks({
|
|
17075
17432
|
didLintFail,
|
|
17076
17433
|
lintFailureReason,
|
|
@@ -17089,7 +17446,8 @@ const finalizeAndRender = (input) => Effect.gen(function* () {
|
|
|
17089
17446
|
elapsedMilliseconds,
|
|
17090
17447
|
scannedFileCount,
|
|
17091
17448
|
scannedFilePaths,
|
|
17092
|
-
scanElapsedMilliseconds
|
|
17449
|
+
scanElapsedMilliseconds,
|
|
17450
|
+
...baselineDelta ? { baselineDelta } : {}
|
|
17093
17451
|
});
|
|
17094
17452
|
if (options.suppressRendering) return buildResult();
|
|
17095
17453
|
if (options.scoreOnly) {
|
|
@@ -17409,7 +17767,7 @@ const VITE_PLUS_HOOKS_PATH = ".vite-hooks";
|
|
|
17409
17767
|
const LEFTHOOK_CONFIG_FILES = ["lefthook.yml", "lefthook.yaml"];
|
|
17410
17768
|
const PRE_COMMIT_CONFIG_FILE = ".pre-commit-config.yaml";
|
|
17411
17769
|
const OVERCOMMIT_CONFIG_FILE = ".overcommit.yml";
|
|
17412
|
-
const REACT_DOCTOR_COMMAND = "react-doctor --staged --
|
|
17770
|
+
const REACT_DOCTOR_COMMAND = "react-doctor --staged --blocking warning";
|
|
17413
17771
|
const NON_BLOCKING_REACT_DOCTOR_COMMAND = [
|
|
17414
17772
|
"react_doctor_output=$(mktemp \"${TMPDIR:-/tmp}/react-doctor-hook.XXXXXX\");",
|
|
17415
17773
|
`if ${REACT_DOCTOR_COMMAND} > "$react_doctor_output" 2>&1; then`,
|
|
@@ -17678,22 +18036,22 @@ const buildAgentHookScript = () => [
|
|
|
17678
18036
|
"",
|
|
17679
18037
|
"run_react_doctor() {",
|
|
17680
18038
|
" if [ -x ./node_modules/.bin/react-doctor ]; then",
|
|
17681
|
-
" ./node_modules/.bin/react-doctor --verbose --diff --
|
|
18039
|
+
" ./node_modules/.bin/react-doctor --verbose --diff --blocking warning --no-score",
|
|
17682
18040
|
" return",
|
|
17683
18041
|
" fi",
|
|
17684
18042
|
"",
|
|
17685
18043
|
" if command -v react-doctor >/dev/null 2>&1; then",
|
|
17686
|
-
" react-doctor --verbose --diff --
|
|
18044
|
+
" react-doctor --verbose --diff --blocking warning --no-score",
|
|
17687
18045
|
" return",
|
|
17688
18046
|
" fi",
|
|
17689
18047
|
"",
|
|
17690
18048
|
" if command -v pnpm >/dev/null 2>&1; then",
|
|
17691
|
-
" pnpm dlx react-doctor@latest --verbose --diff --
|
|
18049
|
+
" pnpm dlx react-doctor@latest --verbose --diff --blocking warning --no-score",
|
|
17692
18050
|
" return",
|
|
17693
18051
|
" fi",
|
|
17694
18052
|
"",
|
|
17695
18053
|
" if command -v npx >/dev/null 2>&1; then",
|
|
17696
|
-
" npx --yes react-doctor@latest --verbose --diff --
|
|
18054
|
+
" npx --yes react-doctor@latest --verbose --diff --blocking warning --no-score",
|
|
17697
18055
|
" return",
|
|
17698
18056
|
" fi",
|
|
17699
18057
|
"",
|
|
@@ -17855,8 +18213,8 @@ const REACT_DOCTOR_BLOCK_PATTERN = new RegExp(`(?:${REACT_DOCTOR_BLOCK_START}[\\
|
|
|
17855
18213
|
const SHEBANG = "#!/bin/sh";
|
|
17856
18214
|
const SHEBANG_PREFIX = "#!";
|
|
17857
18215
|
const LOCAL_REACT_DOCTOR_BIN = "./node_modules/.bin/react-doctor";
|
|
17858
|
-
const PNPM_REACT_DOCTOR_COMMAND = "pnpm dlx react-doctor@latest --staged --
|
|
17859
|
-
const NPX_REACT_DOCTOR_COMMAND = "npx --yes react-doctor@latest --staged --
|
|
18216
|
+
const PNPM_REACT_DOCTOR_COMMAND = "pnpm dlx react-doctor@latest --staged --blocking warning";
|
|
18217
|
+
const NPX_REACT_DOCTOR_COMMAND = "npx --yes react-doctor@latest --staged --blocking warning";
|
|
17860
18218
|
const buildReactDoctorHookBlock = () => [
|
|
17861
18219
|
REACT_DOCTOR_BLOCK_START,
|
|
17862
18220
|
"react_doctor_scan_staged_files() {",
|
|
@@ -17937,11 +18295,11 @@ const installDirectGitHook = (options) => {
|
|
|
17937
18295
|
//#region src/cli/utils/install-git-hook-config-managers.ts
|
|
17938
18296
|
const appendStringCommand = (existingCommand) => {
|
|
17939
18297
|
const existingCommandText = typeof existingCommand === "string" ? existingCommand : Array.isArray(existingCommand) ? existingCommand.filter((entry) => typeof entry === "string").join("\n") : "";
|
|
17940
|
-
return existingCommandText.includes("react-doctor --staged --
|
|
18298
|
+
return existingCommandText.includes("react-doctor --staged --blocking warning") ? existingCommandText : [existingCommandText, NON_BLOCKING_REACT_DOCTOR_COMMAND].filter(Boolean).join("\n");
|
|
17941
18299
|
};
|
|
17942
18300
|
const appendArrayCommand = (existingCommands) => {
|
|
17943
18301
|
const commands = Array.isArray(existingCommands) ? existingCommands.filter((entry) => typeof entry === "string") : typeof existingCommands === "string" ? [existingCommands] : [];
|
|
17944
|
-
return commands.some((command) => command.includes("react-doctor --staged --
|
|
18302
|
+
return commands.some((command) => command.includes("react-doctor --staged --blocking warning")) ? commands : [...commands, NON_BLOCKING_REACT_DOCTOR_COMMAND];
|
|
17945
18303
|
};
|
|
17946
18304
|
const installPackageJsonHook = (options, strategy) => {
|
|
17947
18305
|
const packageJsonPath = getPackageJsonPath(options.projectRoot);
|
|
@@ -18238,7 +18596,7 @@ const installReactDoctorGitHook = (options) => {
|
|
|
18238
18596
|
};
|
|
18239
18597
|
//#endregion
|
|
18240
18598
|
//#region src/cli/utils/should-skip-prompts.ts
|
|
18241
|
-
const shouldSkipPrompts = (input = {}) => Boolean(input.yes) || Boolean(input.
|
|
18599
|
+
const shouldSkipPrompts = (input = {}) => Boolean(input.yes) || Boolean(input.json) || isNonInteractiveEnvironment() || !process.stdin.isTTY;
|
|
18242
18600
|
//#endregion
|
|
18243
18601
|
//#region src/cli/utils/install-react-doctor.ts
|
|
18244
18602
|
const SETUP_OPTION_GIT_HOOK = "git-hook";
|
|
@@ -19139,20 +19497,6 @@ export default ${serializeTsObjectLiteral(config)} satisfies ReactDoctorConfig;
|
|
|
19139
19497
|
return targetPath;
|
|
19140
19498
|
};
|
|
19141
19499
|
//#endregion
|
|
19142
|
-
//#region src/cli/utils/annotation-encoding.ts
|
|
19143
|
-
const encodeAnnotationProperty = (value) => value.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A").replaceAll(":", "%3A").replaceAll(",", "%2C");
|
|
19144
|
-
const encodeAnnotationMessage = (value) => value.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A");
|
|
19145
|
-
//#endregion
|
|
19146
|
-
//#region src/cli/utils/print-annotations.ts
|
|
19147
|
-
const printAnnotations = (diagnostics, routeToStderr) => {
|
|
19148
|
-
const writeLine = routeToStderr ? (line) => process.stderr.write(`${line}\n`) : (line) => process.stdout.write(`${line}\n`);
|
|
19149
|
-
for (const diagnostic of diagnostics) {
|
|
19150
|
-
const level = diagnostic.severity === "error" ? "error" : "warning";
|
|
19151
|
-
const title = `${diagnostic.plugin}/${diagnostic.rule}`;
|
|
19152
|
-
writeLine(`::${level} ${`file=${encodeAnnotationProperty(diagnostic.filePath)}`}${diagnostic.line > 0 ? `,line=${diagnostic.line}` : ""}${`,title=${encodeAnnotationProperty(title)}`}::${encodeAnnotationMessage(diagnostic.message)}`);
|
|
19153
|
-
}
|
|
19154
|
-
};
|
|
19155
|
-
//#endregion
|
|
19156
19500
|
//#region src/cli/utils/print-branded-header.ts
|
|
19157
19501
|
/**
|
|
19158
19502
|
* Single branded line every command prints first when not in JSON
|
|
@@ -19418,28 +19762,26 @@ const resolveParallelFlag = (parallel) => parallel === false ? 1 : void 0;
|
|
|
19418
19762
|
/**
|
|
19419
19763
|
* Translates CLI flags into the `InspectOptions` contract `inspect()`
|
|
19420
19764
|
* accepts. Flag-specific computed fields (`scoreOnly`, `noScore`,
|
|
19421
|
-
* `silent`, `
|
|
19422
|
-
*
|
|
19423
|
-
*
|
|
19424
|
-
*
|
|
19425
|
-
*
|
|
19426
|
-
*
|
|
19427
|
-
* can apply the one flag-and-config rule that flags own
|
|
19765
|
+
* `silent`, `isCi`) live here — there's no `userConfig` knob for them,
|
|
19766
|
+
* only flag derivation. The plain boolean knobs (`lint`, `deadCode`,
|
|
19767
|
+
* `verbose`) pass through unchanged: `inspect()` owns the
|
|
19768
|
+
* userConfig-fallback layer so the merge logic isn't duplicated. The
|
|
19769
|
+
* shell still hands `userConfig` in via `configOverride` and `noScore`
|
|
19770
|
+
* so this resolver can apply the one flag-and-config rule that flags own
|
|
19428
19771
|
* (`--score false` wins, otherwise inherit `userConfig.noScore`).
|
|
19429
19772
|
*/
|
|
19430
19773
|
const resolveCliInspectOptions = (flags, userConfig) => {
|
|
19431
|
-
const wantsWarningGate = (flags
|
|
19774
|
+
const wantsWarningGate = pickBlockingLevel(flags, userConfig) === "warning";
|
|
19432
19775
|
return {
|
|
19433
19776
|
lint: flags.lint,
|
|
19434
19777
|
deadCode: flags.deadCode,
|
|
19435
19778
|
verbose: flags.verbose,
|
|
19436
|
-
respectInlineDisables: flags.respectInlineDisables,
|
|
19437
|
-
warnings:
|
|
19779
|
+
respectInlineDisables: flags.respectInlineDisables === false ? false : void 0,
|
|
19780
|
+
warnings: wantsWarningGate ? true : flags.warnings,
|
|
19438
19781
|
scoreOnly: flags.score === true,
|
|
19439
19782
|
noScore: flags.score === false || flags.telemetry === false || (userConfig?.noScore ?? false),
|
|
19440
19783
|
isCi: isCiEnvironment(),
|
|
19441
19784
|
silent: Boolean(flags.json),
|
|
19442
|
-
outputSurface: flags.prComment ? "prComment" : "cli",
|
|
19443
19785
|
concurrency: resolveParallelFlag(flags.parallel)
|
|
19444
19786
|
};
|
|
19445
19787
|
};
|
|
@@ -19492,25 +19834,7 @@ const coerceDiffValue = (value) => {
|
|
|
19492
19834
|
};
|
|
19493
19835
|
//#endregion
|
|
19494
19836
|
//#region src/cli/utils/resolve-effective-diff.ts
|
|
19495
|
-
const resolveEffectiveDiff = (flags, userConfig) =>
|
|
19496
|
-
if (flags.full) return false;
|
|
19497
|
-
return coerceDiffValue(flags.diff ?? userConfig?.diff);
|
|
19498
|
-
};
|
|
19499
|
-
//#endregion
|
|
19500
|
-
//#region src/cli/utils/resolve-fail-on-level.ts
|
|
19501
|
-
const VALID_FAIL_ON_LEVELS = new Set([
|
|
19502
|
-
"error",
|
|
19503
|
-
"warning",
|
|
19504
|
-
"none"
|
|
19505
|
-
]);
|
|
19506
|
-
const DEFAULT_FAIL_ON_LEVEL = "none";
|
|
19507
|
-
const isValidFailOnLevel = (level) => VALID_FAIL_ON_LEVELS.has(level);
|
|
19508
|
-
const resolveFailOnLevel = (flags, userConfig) => {
|
|
19509
|
-
const sourceValue = flags.failOn ?? userConfig?.failOn ?? DEFAULT_FAIL_ON_LEVEL;
|
|
19510
|
-
if (isValidFailOnLevel(sourceValue)) return sourceValue;
|
|
19511
|
-
cliLogger.warn(`Invalid failOn level "${sourceValue}". Expected one of: error, warning, none. Falling back to "${DEFAULT_FAIL_ON_LEVEL}".`);
|
|
19512
|
-
return DEFAULT_FAIL_ON_LEVEL;
|
|
19513
|
-
};
|
|
19837
|
+
const resolveEffectiveDiff = (flags, userConfig) => coerceDiffValue(flags.diff ?? userConfig?.diff);
|
|
19514
19838
|
//#endregion
|
|
19515
19839
|
//#region src/cli/utils/resolve-project-diff-include-paths.ts
|
|
19516
19840
|
const resolveProjectDiffIncludePaths = (rootDirectory, projectDirectory, diffInfo) => {
|
|
@@ -19614,8 +19938,11 @@ const selectProjects = async (rootDirectory, projectFlag, skipPrompts) => {
|
|
|
19614
19938
|
}
|
|
19615
19939
|
return promptProjectSelection(packages, rootDirectory);
|
|
19616
19940
|
};
|
|
19941
|
+
const ALL_PROJECTS_SENTINEL = "*";
|
|
19617
19942
|
const resolveProjectFlag = (projectFlag, workspacePackages) => {
|
|
19618
|
-
const requestedNames = projectFlag.split(",").map((name) => name.trim());
|
|
19943
|
+
const requestedNames = projectFlag.split(",").map((name) => name.trim()).filter((name) => name.length > 0);
|
|
19944
|
+
if (requestedNames.length === 0) throw new CliInputError(`--project "${projectFlag}" did not name any project. Pass a project name, a comma-separated list, or "*" for all.`);
|
|
19945
|
+
if (requestedNames.includes(ALL_PROJECTS_SENTINEL)) return workspacePackages.map((workspacePackage) => workspacePackage.directory);
|
|
19619
19946
|
const resolvedDirectories = [];
|
|
19620
19947
|
for (const requestedName of requestedNames) {
|
|
19621
19948
|
const matched = workspacePackages.find((workspacePackage) => workspacePackage.name === requestedName || path$1.basename(workspacePackage.directory) === requestedName);
|
|
@@ -19688,6 +20015,16 @@ const runExplain = async (fileLineArgument, context) => {
|
|
|
19688
20015
|
}
|
|
19689
20016
|
};
|
|
19690
20017
|
//#endregion
|
|
20018
|
+
//#region src/cli/utils/warn-deprecated-fail-on.ts
|
|
20019
|
+
const warnDeprecatedFailOn = (flags, userConfig) => {
|
|
20020
|
+
const usedFlag = flags.failOn !== void 0;
|
|
20021
|
+
const usedConfig = userConfig?.failOn !== void 0;
|
|
20022
|
+
if (!usedFlag && !usedConfig) return;
|
|
20023
|
+
const source = usedFlag ? "The `--fail-on` flag" : "The `failOn` config option";
|
|
20024
|
+
const replacement = usedFlag ? "`--blocking <level>`" : "`blocking`";
|
|
20025
|
+
cliLogger.warn(`${source} is deprecated; rename it to ${replacement}.`);
|
|
20026
|
+
};
|
|
20027
|
+
//#endregion
|
|
19691
20028
|
//#region src/cli/utils/validate-mode-flags.ts
|
|
19692
20029
|
const validateModeFlags = (flags) => {
|
|
19693
20030
|
const coercedDiff = coerceDiffValue(flags.diff);
|
|
@@ -19695,36 +20032,44 @@ const validateModeFlags = (flags) => {
|
|
|
19695
20032
|
if (exclusiveModes.length > 1) throw new CliInputError(`Cannot combine ${exclusiveModes.join(" and ")}; pick one mode.`);
|
|
19696
20033
|
if (flags.score && flags.json) throw new CliInputError("Cannot combine --score and --json; pick one output mode.");
|
|
19697
20034
|
if (flags.score && flags.telemetry === false) throw new CliInputError("Cannot combine --score with --no-telemetry; --score prints the score that --no-telemetry disables.");
|
|
19698
|
-
if (flags.prComment && (flags.json || flags.score)) throw new CliInputError("--pr-comment cannot be combined with --json or --score.");
|
|
19699
|
-
if (flags.annotations && flags.score) throw new CliInputError("--annotations cannot be combined with --score.");
|
|
19700
|
-
if (flags.explain !== void 0 && flags.why !== void 0) throw new CliInputError("Use --explain or --why, not both — they're aliases of the same flag.");
|
|
19701
|
-
if ((flags.explain ?? flags.why) !== void 0 && (flags.json || flags.score || flags.annotations || flags.staged)) throw new CliInputError("--explain cannot be combined with --json, --score, --annotations, or --staged.");
|
|
19702
20035
|
};
|
|
19703
20036
|
//#endregion
|
|
19704
20037
|
//#region src/cli/commands/inspect.ts
|
|
19705
20038
|
/**
|
|
19706
20039
|
* Post-scan finalization shared by the staged-arm and project-loop
|
|
19707
|
-
* paths of `inspectAction`: emit the JSON report (when in JSON mode)
|
|
19708
|
-
*
|
|
19709
|
-
* `
|
|
19710
|
-
*
|
|
20040
|
+
* paths of `inspectAction`: emit the JSON report (when in JSON mode)
|
|
20041
|
+
* and set `process.exitCode = 1` when a diagnostic at or above the
|
|
20042
|
+
* `--blocking` threshold (default `"error"`) reaches the `ciFailure`
|
|
20043
|
+
* surface. `--blocking none` keeps the scan advisory (always exits 0).
|
|
19711
20044
|
*/
|
|
19712
20045
|
const finalizeScans = (input) => {
|
|
19713
|
-
|
|
19714
|
-
|
|
19715
|
-
|
|
19716
|
-
|
|
19717
|
-
|
|
19718
|
-
|
|
19719
|
-
|
|
19720
|
-
|
|
19721
|
-
|
|
19722
|
-
|
|
19723
|
-
|
|
20046
|
+
const baselineDeltas = input.completedScans.flatMap((scan) => scan.result.baselineDelta ? [scan.result.baselineDelta] : []);
|
|
20047
|
+
const baselineComputed = input.completedScans.length > 0 && input.completedScans.every((scan) => scan.result.baselineDelta !== void 0);
|
|
20048
|
+
const baselineDegraded = input.baselineIntended && !baselineComputed;
|
|
20049
|
+
const mode = baselineDegraded ? "diff" : input.mode;
|
|
20050
|
+
if (input.isJsonMode) {
|
|
20051
|
+
const baseline = baselineComputed && baselineDeltas.length > 0 ? {
|
|
20052
|
+
baseRef: baselineDeltas[0].baseRef,
|
|
20053
|
+
fixedCount: baselineDeltas.reduce((total, delta) => total + delta.fixedCount, 0),
|
|
20054
|
+
baseTotalCount: baselineDeltas.reduce((total, delta) => total + delta.baseTotalCount, 0)
|
|
20055
|
+
} : void 0;
|
|
20056
|
+
writeJsonReport(buildJsonReport({
|
|
20057
|
+
version: VERSION,
|
|
20058
|
+
directory: input.resolvedDirectory,
|
|
20059
|
+
mode,
|
|
20060
|
+
diff: input.diff,
|
|
20061
|
+
scans: input.completedScans,
|
|
20062
|
+
totalElapsedMilliseconds: performance.now() - input.startTime,
|
|
20063
|
+
baseline
|
|
20064
|
+
}));
|
|
20065
|
+
}
|
|
20066
|
+
if (input.isScoreOnly || baselineDegraded) return;
|
|
20067
|
+
if (shouldBlockCi(filterDiagnosticsForSurface(input.diagnostics, "ciFailure", input.userConfig), resolveBlockingLevel(input.flags, input.userConfig))) process.exitCode = 1;
|
|
19724
20068
|
};
|
|
19725
20069
|
const buildChangedFilesDiffInfo = (changedFiles) => ({
|
|
19726
20070
|
currentBranch: process.env.GITHUB_HEAD_REF?.trim() || null,
|
|
19727
20071
|
baseBranch: process.env.GITHUB_BASE_REF?.trim() || "pull request target",
|
|
20072
|
+
baseSha: process.env.REACT_DOCTOR_BASE_SHA?.trim() || void 0,
|
|
19728
20073
|
changedFiles,
|
|
19729
20074
|
isCurrentChanges: false
|
|
19730
20075
|
});
|
|
@@ -19767,11 +20112,12 @@ const inspectAction = async (directory, flags) => {
|
|
|
19767
20112
|
const userConfig = scanTarget.userConfig;
|
|
19768
20113
|
const resolvedDirectory = scanTarget.resolvedDirectory;
|
|
19769
20114
|
setJsonReportDirectory(resolvedDirectory);
|
|
20115
|
+
warnDeprecatedFailOn(flags, userConfig);
|
|
19770
20116
|
if (scanTarget.didRedirectViaRootDir && !isQuiet) {
|
|
19771
20117
|
cliLogger.dim(`Redirected to ${highlighter.info(toRelativePath(resolvedDirectory, requestedDirectory))} via react-doctor config "rootDir".`);
|
|
19772
20118
|
cliLogger.break();
|
|
19773
20119
|
}
|
|
19774
|
-
const explainArgument = flags.explain
|
|
20120
|
+
const explainArgument = flags.explain;
|
|
19775
20121
|
if (explainArgument !== void 0) {
|
|
19776
20122
|
await runExplain(explainArgument, {
|
|
19777
20123
|
resolvedDirectory,
|
|
@@ -19788,7 +20134,6 @@ const inspectAction = async (directory, flags) => {
|
|
|
19788
20134
|
const scanOptions = resolveCliInspectOptions(flags, userConfig);
|
|
19789
20135
|
const skipPrompts = shouldSkipPrompts({
|
|
19790
20136
|
yes: flags.yes,
|
|
19791
|
-
full: flags.full,
|
|
19792
20137
|
json: flags.json
|
|
19793
20138
|
});
|
|
19794
20139
|
if (flags.staged) {
|
|
@@ -19843,6 +20188,7 @@ const inspectAction = async (directory, flags) => {
|
|
|
19843
20188
|
}],
|
|
19844
20189
|
mode: "staged",
|
|
19845
20190
|
diff: null,
|
|
20191
|
+
baselineIntended: false,
|
|
19846
20192
|
isJsonMode,
|
|
19847
20193
|
isScoreOnly,
|
|
19848
20194
|
flags,
|
|
@@ -19856,11 +20202,12 @@ const inspectAction = async (directory, flags) => {
|
|
|
19856
20202
|
return;
|
|
19857
20203
|
}
|
|
19858
20204
|
const projectDirectories = await selectProjects(resolvedDirectory, flags.project, skipPrompts);
|
|
19859
|
-
const changedFilesDiffInfo = flags.changedFilesFrom
|
|
20205
|
+
const changedFilesDiffInfo = flags.changedFilesFrom ? buildChangedFilesDiffInfo(readChangedFilesFrom(path$1.resolve(flags.changedFilesFrom))) : null;
|
|
19860
20206
|
const effectiveDiff = resolveEffectiveDiff(flags, userConfig);
|
|
19861
20207
|
const diffInfo = changedFilesDiffInfo ?? (changedFilesDiffInfo === null && (effectiveDiff !== void 0 && effectiveDiff !== false || !skipPrompts && !isQuiet) ? await getDiffInfo(resolvedDirectory, typeof effectiveDiff === "string" ? effectiveDiff : void 0) : null);
|
|
19862
20208
|
const isDiffMode = changedFilesDiffInfo !== null || await resolveDiffMode(diffInfo, effectiveDiff, skipPrompts, isQuiet);
|
|
19863
|
-
|
|
20209
|
+
const baselineRef = isDiffMode && diffInfo && !diffInfo.isCurrentChanges ? diffInfo.baseSha ? await resolveMergeBaseRef(resolvedDirectory, diffInfo.baseSha) : diffInfo.diffBaseRef ?? await resolveMergeBaseRef(resolvedDirectory, diffInfo.baseBranch) : null;
|
|
20210
|
+
setJsonReportMode(baselineRef ? "baseline" : isDiffMode ? "diff" : "full");
|
|
19864
20211
|
if (isDiffMode && diffInfo && !isQuiet) {
|
|
19865
20212
|
if (diffInfo.isCurrentChanges) cliLogger.log("Scanning uncommitted changes");
|
|
19866
20213
|
else {
|
|
@@ -19890,7 +20237,8 @@ const inspectAction = async (directory, flags) => {
|
|
|
19890
20237
|
...scanOptions,
|
|
19891
20238
|
includePaths,
|
|
19892
20239
|
configOverride: userConfig,
|
|
19893
|
-
suppressRendering: isMultiProject
|
|
20240
|
+
suppressRendering: isMultiProject,
|
|
20241
|
+
baseline: baselineRef ? { ref: baselineRef } : void 0
|
|
19894
20242
|
});
|
|
19895
20243
|
allDiagnostics.push(...scanResult.diagnostics);
|
|
19896
20244
|
completedScans.push({
|
|
@@ -19912,8 +20260,9 @@ const inspectAction = async (directory, flags) => {
|
|
|
19912
20260
|
finalizeScans({
|
|
19913
20261
|
diagnostics: allDiagnostics,
|
|
19914
20262
|
completedScans,
|
|
19915
|
-
mode: isDiffMode ? "diff" : "full",
|
|
20263
|
+
mode: baselineRef ? "baseline" : isDiffMode ? "diff" : "full",
|
|
19916
20264
|
diff: isDiffMode ? diffInfo : null,
|
|
20265
|
+
baselineIntended: isDiffMode && diffInfo !== null && !diffInfo.isCurrentChanges,
|
|
19917
20266
|
isJsonMode,
|
|
19918
20267
|
isScoreOnly,
|
|
19919
20268
|
flags,
|
|
@@ -19951,7 +20300,7 @@ const inspectAction = async (directory, flags) => {
|
|
|
19951
20300
|
const isUserError = isExpectedUserError(error);
|
|
19952
20301
|
const sentryEventId = isUserError ? void 0 : await reportErrorToSentry(error);
|
|
19953
20302
|
if (isJsonMode) {
|
|
19954
|
-
writeJsonErrorReport(error);
|
|
20303
|
+
writeJsonErrorReport(error, sentryEventId);
|
|
19955
20304
|
process.exitCode = 1;
|
|
19956
20305
|
return;
|
|
19957
20306
|
}
|
|
@@ -20540,6 +20889,20 @@ const versionAction = () => {
|
|
|
20540
20889
|
process.stdout.write(`${buildVersionString()}\n`);
|
|
20541
20890
|
};
|
|
20542
20891
|
//#endregion
|
|
20892
|
+
//#region src/cli/commands/why.ts
|
|
20893
|
+
/**
|
|
20894
|
+
* `why <file:line>` — explains why a rule fired (or why a suppression didn't
|
|
20895
|
+
* apply) at a specific location. A thin wrapper over the inspect flow's
|
|
20896
|
+
* single-location explain path so it reuses the same scan, config resolution,
|
|
20897
|
+
* and clean error handling. (Replaces the former `--explain` / `--why` flags.)
|
|
20898
|
+
*/
|
|
20899
|
+
const whyAction = async (location, options) => {
|
|
20900
|
+
await inspectAction(options.cwd ?? process.cwd(), {
|
|
20901
|
+
explain: location,
|
|
20902
|
+
project: options.project
|
|
20903
|
+
});
|
|
20904
|
+
};
|
|
20905
|
+
//#endregion
|
|
20543
20906
|
//#region src/cli/utils/apply-color-preference.ts
|
|
20544
20907
|
/**
|
|
20545
20908
|
* Resolve an explicit color preference from `--color` / `--no-color` or the
|
|
@@ -20641,13 +21004,32 @@ const normalizeHelpInvocation = (argv, knownCommands) => {
|
|
|
20641
21004
|
return [...nodeArguments, "--help"];
|
|
20642
21005
|
};
|
|
20643
21006
|
//#endregion
|
|
21007
|
+
//#region src/cli/utils/removed-cli-flags.ts
|
|
21008
|
+
const REMOVED_FLAGS = new Map([
|
|
21009
|
+
["--full", "use `--diff false` to force a full scan"],
|
|
21010
|
+
["--explain", "use the `why <file>:<line>` command"],
|
|
21011
|
+
["--why", "use the `why <file>:<line>` command"],
|
|
21012
|
+
["--pr-comment", "the GitHub Action posts the PR comment for you; remove this flag"]
|
|
21013
|
+
]);
|
|
21014
|
+
/**
|
|
21015
|
+
* Throws a clean {@link CliInputError} when a removed flag appears in argv,
|
|
21016
|
+
* pointing to its replacement. Run before flag stripping so a removed flag is a
|
|
21017
|
+
* loud, actionable error rather than a silent no-op.
|
|
21018
|
+
*/
|
|
21019
|
+
const assertNoRemovedFlags = (argv) => {
|
|
21020
|
+
for (const argument of argv.slice(2)) {
|
|
21021
|
+
if (argument === "--") return;
|
|
21022
|
+
const optionName = argument.includes("=") ? argument.slice(0, argument.indexOf("=")) : argument;
|
|
21023
|
+
const guidance = REMOVED_FLAGS.get(optionName);
|
|
21024
|
+
if (guidance !== void 0) throw new CliInputError(`\`${optionName}\` was removed — ${guidance}.`);
|
|
21025
|
+
}
|
|
21026
|
+
};
|
|
21027
|
+
//#endregion
|
|
20644
21028
|
//#region src/cli/utils/strip-unknown-cli-flags.ts
|
|
20645
21029
|
const ROOT_FLAG_SPEC = {
|
|
20646
21030
|
longOptionsWithoutValues: new Set([
|
|
20647
|
-
"--annotations",
|
|
20648
21031
|
"--color",
|
|
20649
21032
|
"--dead-code",
|
|
20650
|
-
"--full",
|
|
20651
21033
|
"--help",
|
|
20652
21034
|
"--json",
|
|
20653
21035
|
"--json-compact",
|
|
@@ -20660,8 +21042,6 @@ const ROOT_FLAG_SPEC = {
|
|
|
20660
21042
|
"--no-score",
|
|
20661
21043
|
"--no-telemetry",
|
|
20662
21044
|
"--no-warnings",
|
|
20663
|
-
"--pr-comment",
|
|
20664
|
-
"--respect-inline-disables",
|
|
20665
21045
|
"--score",
|
|
20666
21046
|
"--staged",
|
|
20667
21047
|
"--verbose",
|
|
@@ -20671,10 +21051,9 @@ const ROOT_FLAG_SPEC = {
|
|
|
20671
21051
|
]),
|
|
20672
21052
|
longOptionsWithRequiredValues: new Set([
|
|
20673
21053
|
"--changed-files-from",
|
|
20674
|
-
"--
|
|
21054
|
+
"--blocking",
|
|
20675
21055
|
"--fail-on",
|
|
20676
|
-
"--project"
|
|
20677
|
-
"--why"
|
|
21056
|
+
"--project"
|
|
20678
21057
|
]),
|
|
20679
21058
|
longOptionsWithOptionalValues: new Set(["--diff"]),
|
|
20680
21059
|
shortOptionsWithoutValues: new Set([
|
|
@@ -20730,6 +21109,17 @@ const COMMAND_FLAG_SPECS = new Map([
|
|
|
20730
21109
|
longOptionsWithOptionalValues: /* @__PURE__ */ new Set(),
|
|
20731
21110
|
shortOptionsWithoutValues: new Set(["-h"]),
|
|
20732
21111
|
shortOptionsWithRequiredValues: new Set(["-c"])
|
|
21112
|
+
}],
|
|
21113
|
+
["why", {
|
|
21114
|
+
longOptionsWithoutValues: new Set([
|
|
21115
|
+
"--color",
|
|
21116
|
+
"--help",
|
|
21117
|
+
"--no-color"
|
|
21118
|
+
]),
|
|
21119
|
+
longOptionsWithRequiredValues: new Set(["--cwd", "--project"]),
|
|
21120
|
+
longOptionsWithOptionalValues: /* @__PURE__ */ new Set(),
|
|
21121
|
+
shortOptionsWithoutValues: new Set(["-h"]),
|
|
21122
|
+
shortOptionsWithRequiredValues: new Set(["-c"])
|
|
20733
21123
|
}]
|
|
20734
21124
|
]);
|
|
20735
21125
|
const isFlagLike = (argument) => argument.startsWith("-") && argument !== "-";
|
|
@@ -20816,9 +21206,9 @@ ${formatExampleLines([
|
|
|
20816
21206
|
["react-doctor ./apps/web", "scan a specific directory"],
|
|
20817
21207
|
["react-doctor --diff main", "scan only files changed vs. main"],
|
|
20818
21208
|
["react-doctor --staged", "scan staged files (pre-commit hook)"],
|
|
20819
|
-
["react-doctor --
|
|
21209
|
+
["react-doctor --blocking warning", "fail CI on warnings too (default: error)"],
|
|
20820
21210
|
["react-doctor --json > report.json", "write a machine-readable report"],
|
|
20821
|
-
["react-doctor
|
|
21211
|
+
["react-doctor why src/App.tsx:42", "explain why a rule fired there"],
|
|
20822
21212
|
["react-doctor install", "set up the agent skill and git hook"]
|
|
20823
21213
|
])}
|
|
20824
21214
|
|
|
@@ -20844,8 +21234,9 @@ ${formatExampleLines([
|
|
|
20844
21234
|
${highlighter.dim("Learn more:")}
|
|
20845
21235
|
${highlighter.info(CANONICAL_GITHUB_URL)}
|
|
20846
21236
|
`;
|
|
20847
|
-
const program = new Command().name("react-doctor").description("Diagnose React codebase health").version(VERSION, "-v, --version", "display the version number").argument("[directory]", "project directory to scan", ".").option("--lint", "enable linting").option("--no-lint", "skip linting").option("--dead-code", "enable dead-code analysis (default)").option("--no-dead-code", "skip dead-code analysis (unused files / exports / dependencies, circular imports)").option("--verbose", "show every rule and per-file details (default shows top 3 rules)").option("--score", "output only the score").option("--json", "output a single structured JSON report (suppresses other output)").option("--json-compact", "with --json, emit compact JSON (no indentation)").option("-y, --yes", "skip prompts, scan all workspace projects").option("--
|
|
21237
|
+
const program = new Command().name("react-doctor").description("Diagnose React codebase health").version(VERSION, "-v, --version", "display the version number").argument("[directory]", "project directory to scan", ".").option("--lint", "enable linting").option("--no-lint", "skip linting").option("--dead-code", "enable dead-code analysis (default)").option("--no-dead-code", "skip dead-code analysis (unused files / exports / dependencies, circular imports)").option("--verbose", "show every rule and per-file details (default shows top 3 rules)").option("--score", "output only the score").option("--json", "output a single structured JSON report (suppresses other output)").option("--json-compact", "with --json, emit compact JSON (no indentation)").option("-y, --yes", "skip prompts, scan all workspace projects").option("--no-parallel", "lint serially with one worker (default: parallel across CPU cores; set the worker count with REACT_DOCTOR_PARALLEL)").option("--project <name>", "select workspace project (comma-separated for multiple)").option("--diff [base]", "scan only files changed vs base branch (pass `false` to force a full scan, overriding config)").addOption(new Option$1("--changed-files-from <file>", "scan source files listed in a newline-delimited changed-files file").hideHelp()).option("--no-score", "skip the score API, the share URL, and crash reporting").option("--no-telemetry", "alias for --no-score (skip the score API, share URL, and crash reporting)").option("--staged", "scan only staged (git index) files for pre-commit hooks").option("--blocking <level>", "severity that fails CI: error (default), warning, or none (advisory)").addOption(new Option$1("--fail-on <level>", "[deprecated] alias for --blocking <level>").hideHelp()).option("--no-respect-inline-disables", "audit mode: neutralize inline lint suppressions before scanning").option("--warnings", "show warning-severity diagnostics (default)").option("--no-warnings", "hide warning-severity diagnostics (errors only)").option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").addHelpText("after", renderRootHelpEpilog);
|
|
20848
21238
|
program.action(inspectAction);
|
|
21239
|
+
program.command("why <location>").description("Explain why a rule fired (or why a suppression didn't apply) at a file:line").option("--project <name>", "select workspace project (comma-separated for multiple)").option("-c, --cwd <cwd>", "working directory", process.cwd()).option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").action((location, options) => whyAction(location, options));
|
|
20849
21240
|
program.command("install").alias("setup").description("Install the react-doctor skill into your coding agents and optional git hook").option("-y, --yes", "skip prompts, install for all detected agents").option("--dry-run", "show what would be installed without writing files").option("--agent-hooks", "install native non-blocking agent hooks for Claude Code and Cursor").option("-c, --cwd <cwd>", "working directory", process.cwd()).option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").addHelpText("after", renderInstallHelpEpilog).action(installAction);
|
|
20850
21241
|
program.command("version").description("show the version with Node and platform info").option("--color", "force colored output").option("--no-color", "disable colored output (also honors NO_COLOR)").action(versionAction);
|
|
20851
21242
|
const rules = program.command("rules").description("List, explain, and configure which React Doctor rules run");
|
|
@@ -20857,6 +21248,7 @@ rules.command("disable <rule>").description("Disable a rule so it never runs").o
|
|
|
20857
21248
|
rules.command("category <category> <severity>").description("Set the severity for a whole category (off, warn, error)").option("-c, --cwd <cwd>", "working directory", process.cwd()).action((category, severity, _options, command) => rulesCategoryAction(category, severity, command.optsWithGlobals()));
|
|
20858
21249
|
rules.command("ignore-tag <tag>").description("Skip a whole rule family by tag before linting (e.g. design)").option("-c, --cwd <cwd>", "working directory", process.cwd()).action((tag, _options, command) => rulesIgnoreTagAction(tag, command.optsWithGlobals()));
|
|
20859
21250
|
rules.command("unignore-tag <tag>").description("Stop ignoring a tag previously skipped via ignore-tag").option("-c, --cwd <cwd>", "working directory", process.cwd()).action((tag, _options, command) => rulesUnignoreTagAction(tag, command.optsWithGlobals()));
|
|
21251
|
+
program.command("experimental-lsp", { hidden: false }).description("[experimental] run the React Doctor language server over stdio (for editors)").allowUnknownOption().action(() => {});
|
|
20860
21252
|
process.stdout.on("error", (error) => {
|
|
20861
21253
|
if (error.code === "EPIPE") process.exit(0);
|
|
20862
21254
|
});
|
|
@@ -20868,11 +21260,11 @@ if (process.argv.includes("-V") && !strippedArgv.includes("-V")) {
|
|
|
20868
21260
|
}
|
|
20869
21261
|
applyColorPreference(strippedArgv);
|
|
20870
21262
|
const argv = normalizeHelpInvocation(strippedArgv, knownCommands);
|
|
20871
|
-
program.parseAsync(argv).then(() => flushSentry()).catch(async (error) => {
|
|
21263
|
+
Promise.resolve().then(() => assertNoRemovedFlags(process.argv)).then(() => program.parseAsync(argv)).then(() => flushSentry()).catch(async (error) => {
|
|
20872
21264
|
const isUserError = isExpectedUserError(error);
|
|
20873
21265
|
const sentryEventId = isUserError ? void 0 : await reportErrorToSentry(error);
|
|
20874
21266
|
if (isJsonModeActive()) {
|
|
20875
|
-
writeJsonErrorReport(error);
|
|
21267
|
+
writeJsonErrorReport(error, sentryEventId);
|
|
20876
21268
|
process.exit(1);
|
|
20877
21269
|
}
|
|
20878
21270
|
if (isUserError) {
|
|
@@ -20885,4 +21277,4 @@ program.parseAsync(argv).then(() => flushSentry()).catch(async (error) => {
|
|
|
20885
21277
|
export {};
|
|
20886
21278
|
|
|
20887
21279
|
//# sourceMappingURL=cli.js.map
|
|
20888
|
-
//# debugId=
|
|
21280
|
+
//# debugId=3c457dc9-865a-5459-b923-a0fb762b158f
|