react-doctor 0.2.15 → 0.2.16
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 +8 -5
- package/dist/cli.js +672 -313
- package/dist/index.d.ts +7 -6
- package/dist/index.js +266 -144
- package/package.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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]="7cd8f7c3-d243-5c1a-9ebb-98a50f4157a1")}catch(e){}}();
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
5
5
|
import * as Path from "node:path";
|
|
@@ -7338,27 +7338,30 @@ var OxlintSpawnTimeoutMs = class extends Context.Reference("react-doctor/OxlintS
|
|
|
7338
7338
|
var OxlintOutputMaxBytes = class extends Context.Reference("react-doctor/OxlintOutputMaxBytes", { defaultValue: () => OXLINT_OUTPUT_MAX_BYTES }) {};
|
|
7339
7339
|
/**
|
|
7340
7340
|
* Number of oxlint subprocesses the lint pass runs in parallel. Defaults
|
|
7341
|
-
* to
|
|
7342
|
-
*
|
|
7343
|
-
*
|
|
7344
|
-
*
|
|
7341
|
+
* to auto-detected CPU cores (parallel) so large repos scan fast out of
|
|
7342
|
+
* the box; `spawnLintBatches` transparently falls back to a single worker
|
|
7343
|
+
* if a parallel run exhausts system resources. The CLI's `--no-parallel`
|
|
7344
|
+
* flag forces serial via `Layer.succeed`; the `REACT_DOCTOR_PARALLEL` env
|
|
7345
|
+
* var seeds the default for programmatic / CI callers that never touch the
|
|
7346
|
+
* flag — parallelism is opt-OUT, so only the explicit serial values pin
|
|
7347
|
+
* one worker:
|
|
7345
7348
|
*
|
|
7346
|
-
* - unset / `
|
|
7347
|
-
* - `
|
|
7348
|
-
* - a positive integer
|
|
7349
|
+
* - unset / `auto` / `true` / `on` → available CPU cores (clamped)
|
|
7350
|
+
* - `0` / `false` / `off` → `1` (serial)
|
|
7351
|
+
* - a positive integer → that many workers (clamped)
|
|
7352
|
+
* - any other value → available CPU cores (clamped)
|
|
7349
7353
|
*
|
|
7350
7354
|
* The resolved value is always within
|
|
7351
7355
|
* `[MIN_SCAN_CONCURRENCY, MAX_SCAN_CONCURRENCY]`.
|
|
7352
7356
|
*/
|
|
7353
7357
|
var OxlintConcurrency = class extends Context.Reference("react-doctor/OxlintConcurrency", { defaultValue: () => {
|
|
7354
7358
|
const raw = process.env["REACT_DOCTOR_PARALLEL"];
|
|
7355
|
-
if (raw === void 0) return
|
|
7359
|
+
if (raw === void 0) return resolveScanConcurrency("auto");
|
|
7356
7360
|
const normalized = raw.trim().toLowerCase();
|
|
7357
|
-
if (normalized === "
|
|
7358
|
-
if (normalized === "auto" || normalized === "true" || normalized === "on") return resolveScanConcurrency("auto");
|
|
7361
|
+
if (normalized === "0" || normalized === "false" || normalized === "off") return 1;
|
|
7359
7362
|
const parsed = Number.parseInt(normalized, 10);
|
|
7360
|
-
if (
|
|
7361
|
-
return resolveScanConcurrency(
|
|
7363
|
+
if (Number.isInteger(parsed) && parsed > 0) return resolveScanConcurrency(parsed);
|
|
7364
|
+
return resolveScanConcurrency("auto");
|
|
7362
7365
|
} }) {};
|
|
7363
7366
|
const DIAGNOSTIC_SURFACES = [
|
|
7364
7367
|
"cli",
|
|
@@ -8359,6 +8362,100 @@ const checkReducedMotion = (rootDirectory) => {
|
|
|
8359
8362
|
if (result.status === 0) return [];
|
|
8360
8363
|
return [MISSING_REDUCED_MOTION_DIAGNOSTIC];
|
|
8361
8364
|
};
|
|
8365
|
+
var import_picocolors = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
8366
|
+
let p = process || {}, argv = p.argv || [], env = p.env || {};
|
|
8367
|
+
let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
8368
|
+
let formatter = (open, close, replace = open) => (input) => {
|
|
8369
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
8370
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
8371
|
+
};
|
|
8372
|
+
let replaceClose = (string, close, replace, index) => {
|
|
8373
|
+
let result = "", cursor = 0;
|
|
8374
|
+
do {
|
|
8375
|
+
result += string.substring(cursor, index) + replace;
|
|
8376
|
+
cursor = index + close.length;
|
|
8377
|
+
index = string.indexOf(close, cursor);
|
|
8378
|
+
} while (~index);
|
|
8379
|
+
return result + string.substring(cursor);
|
|
8380
|
+
};
|
|
8381
|
+
let createColors = (enabled = isColorSupported) => {
|
|
8382
|
+
let f = enabled ? formatter : () => String;
|
|
8383
|
+
return {
|
|
8384
|
+
isColorSupported: enabled,
|
|
8385
|
+
reset: f("\x1B[0m", "\x1B[0m"),
|
|
8386
|
+
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
8387
|
+
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
8388
|
+
italic: f("\x1B[3m", "\x1B[23m"),
|
|
8389
|
+
underline: f("\x1B[4m", "\x1B[24m"),
|
|
8390
|
+
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
8391
|
+
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
8392
|
+
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
8393
|
+
black: f("\x1B[30m", "\x1B[39m"),
|
|
8394
|
+
red: f("\x1B[31m", "\x1B[39m"),
|
|
8395
|
+
green: f("\x1B[32m", "\x1B[39m"),
|
|
8396
|
+
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
8397
|
+
blue: f("\x1B[34m", "\x1B[39m"),
|
|
8398
|
+
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
8399
|
+
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
8400
|
+
white: f("\x1B[37m", "\x1B[39m"),
|
|
8401
|
+
gray: f("\x1B[90m", "\x1B[39m"),
|
|
8402
|
+
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
8403
|
+
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
8404
|
+
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
8405
|
+
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
8406
|
+
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
8407
|
+
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
8408
|
+
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
8409
|
+
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
8410
|
+
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
8411
|
+
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
8412
|
+
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
8413
|
+
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
8414
|
+
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
8415
|
+
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
8416
|
+
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
8417
|
+
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
8418
|
+
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
8419
|
+
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
8420
|
+
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
8421
|
+
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
8422
|
+
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
8423
|
+
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
8424
|
+
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
8425
|
+
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
8426
|
+
};
|
|
8427
|
+
};
|
|
8428
|
+
module.exports = createColors();
|
|
8429
|
+
module.exports.createColors = createColors;
|
|
8430
|
+
})))(), 1);
|
|
8431
|
+
const highlighter = {
|
|
8432
|
+
error: import_picocolors.default.red,
|
|
8433
|
+
warn: import_picocolors.default.yellow,
|
|
8434
|
+
info: import_picocolors.default.cyan,
|
|
8435
|
+
success: import_picocolors.default.green,
|
|
8436
|
+
dim: import_picocolors.default.dim,
|
|
8437
|
+
gray: import_picocolors.default.gray,
|
|
8438
|
+
bold: import_picocolors.default.bold
|
|
8439
|
+
};
|
|
8440
|
+
/**
|
|
8441
|
+
* Override picocolors' automatic color detection. picocolors decides
|
|
8442
|
+
* once, at import time, from `NO_COLOR` / `FORCE_COLOR` / `TERM` / TTY.
|
|
8443
|
+
* This lets the CLI honor an explicit `--color` / `--no-color` flag
|
|
8444
|
+
* (clig.dev, Output: "Disable color … if the user requested it") by
|
|
8445
|
+
* swapping in a fresh set of formatters. Call it before any colored
|
|
8446
|
+
* output is produced. Every call site reads `highlighter.<method>` at
|
|
8447
|
+
* call time, so reassigning the properties propagates everywhere.
|
|
8448
|
+
*/
|
|
8449
|
+
const setColorEnabled = (enabled) => {
|
|
8450
|
+
const colors = import_picocolors.default.createColors(enabled);
|
|
8451
|
+
highlighter.error = colors.red;
|
|
8452
|
+
highlighter.warn = colors.yellow;
|
|
8453
|
+
highlighter.info = colors.cyan;
|
|
8454
|
+
highlighter.success = colors.green;
|
|
8455
|
+
highlighter.dim = colors.dim;
|
|
8456
|
+
highlighter.gray = colors.gray;
|
|
8457
|
+
highlighter.bold = colors.bold;
|
|
8458
|
+
};
|
|
8362
8459
|
const computeJsxIncludePaths = (includePaths) => includePaths.length > 0 ? includePaths.filter((filePath) => JSX_FILE_PATTERN.test(filePath)) : void 0;
|
|
8363
8460
|
const LINGUIST_ATTRIBUTE_PATTERN = /^linguist-(?:vendored|generated)(?:=([a-zA-Z0-9]+))?$/i;
|
|
8364
8461
|
const FALSY_VALUES = new Set([
|
|
@@ -8975,6 +9072,11 @@ const trimOrNull = (value) => {
|
|
|
8975
9072
|
* `@{` reflog suffix, or any character outside `[A-Za-z0-9_./-]`.
|
|
8976
9073
|
*/
|
|
8977
9074
|
const SAFE_GIT_REVISION_PATTERN = /^[A-Za-z0-9_./-]+$/;
|
|
9075
|
+
/** Human-readable summary of the `isSafeGitRevision` contract, reused across error details. */
|
|
9076
|
+
const GIT_REF_NAME_RULE = "must match [A-Za-z0-9_./-] without leading '-', '..', or '@{'";
|
|
9077
|
+
/** git's two range operators: two-dot (direct) and three-dot (merge-base). */
|
|
9078
|
+
const DIFF_RANGE_OPERATOR = "..";
|
|
9079
|
+
const SYMMETRIC_DIFF_RANGE_OPERATOR = "...";
|
|
8978
9080
|
const isSafeGitRevision = (candidate) => {
|
|
8979
9081
|
if (candidate.length === 0) return false;
|
|
8980
9082
|
if (candidate.startsWith("-")) return false;
|
|
@@ -8982,6 +9084,31 @@ const isSafeGitRevision = (candidate) => {
|
|
|
8982
9084
|
if (candidate.includes("..") || candidate.includes("@{")) return false;
|
|
8983
9085
|
return SAFE_GIT_REVISION_PATTERN.test(candidate);
|
|
8984
9086
|
};
|
|
9087
|
+
/**
|
|
9088
|
+
* Splits a git revision range into its endpoints: three-dot `A...B`
|
|
9089
|
+
* (symmetric, merge-base) or two-dot `A..B` (direct). Returns `null`
|
|
9090
|
+
* when `value` carries no range operator so the caller falls back to
|
|
9091
|
+
* single-base resolution.
|
|
9092
|
+
*
|
|
9093
|
+
* Only the first operator is split on; any leftover `..` stays inside an
|
|
9094
|
+
* endpoint so `isSafeGitRevision` rejects malformed input like
|
|
9095
|
+
* `A..B..C` instead of silently guessing which pair the user meant.
|
|
9096
|
+
*/
|
|
9097
|
+
const parseGitDiffRange = (value) => {
|
|
9098
|
+
const symmetricIndex = value.indexOf(SYMMETRIC_DIFF_RANGE_OPERATOR);
|
|
9099
|
+
if (symmetricIndex !== -1) return {
|
|
9100
|
+
base: value.slice(0, symmetricIndex),
|
|
9101
|
+
head: value.slice(symmetricIndex + 3),
|
|
9102
|
+
symmetric: true
|
|
9103
|
+
};
|
|
9104
|
+
const rangeIndex = value.indexOf(DIFF_RANGE_OPERATOR);
|
|
9105
|
+
if (rangeIndex !== -1) return {
|
|
9106
|
+
base: value.slice(0, rangeIndex),
|
|
9107
|
+
head: value.slice(rangeIndex + 2),
|
|
9108
|
+
symmetric: false
|
|
9109
|
+
};
|
|
9110
|
+
return null;
|
|
9111
|
+
};
|
|
8985
9112
|
const parseGithubRepoFromRemoteUrl = (remoteUrl) => {
|
|
8986
9113
|
const withoutGitSuffix = remoteUrl.trim().replace(/\.git$/, "");
|
|
8987
9114
|
const sshMatch = /^git@github\.com:([^/\s]+)\/([^/\s]+)$/.exec(withoutGitSuffix);
|
|
@@ -9133,6 +9260,49 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9133
9260
|
if (result.status !== 0) return null;
|
|
9134
9261
|
return parseGithubViewerPermission(result.stdout);
|
|
9135
9262
|
}).pipe(Effect.catch(() => Effect.succeed(null)));
|
|
9263
|
+
/**
|
|
9264
|
+
* Resolves a `--diff A..B` / `A...B` commit range into a changed-file
|
|
9265
|
+
* selection. Each endpoint is validated with `isSafeGitRevision`
|
|
9266
|
+
* BEFORE it reaches `git` (so the range syntax can't smuggle a
|
|
9267
|
+
* `--upload-pack=…`-style option past the CVE-2018-17456 guard) and
|
|
9268
|
+
* verified to exist, then the diff runs between the two commits with
|
|
9269
|
+
* the same `--diff-filter=ACMR` shape the single-base path uses.
|
|
9270
|
+
*/
|
|
9271
|
+
const resolveDiffRange = (input) => Effect.gen(function* () {
|
|
9272
|
+
if (input.range.base.length === 0 && input.range.head.length === 0) return yield* Effect.fail(new ReactDoctorError({ reason: new GitBaseBranchInvalid({ detail: `Diff range "${input.raw}" must name at least one commit (e.g. "main..feature").` }) }));
|
|
9273
|
+
const baseRef = input.range.base.length === 0 ? "HEAD" : input.range.base;
|
|
9274
|
+
const headRef = input.range.head.length === 0 ? "HEAD" : input.range.head;
|
|
9275
|
+
for (const endpoint of [baseRef, headRef]) if (!isSafeGitRevision(endpoint)) return yield* Effect.fail(new ReactDoctorError({ reason: new GitBaseBranchInvalid({ detail: `Diff range "${input.raw}" has an invalid endpoint "${endpoint}" (${GIT_REF_NAME_RULE}).` }) }));
|
|
9276
|
+
for (const endpoint of [baseRef, headRef]) if (!(yield* branchExists(input.directory, endpoint))) return yield* Effect.fail(new ReactDoctorError({ reason: new GitBaseBranchMissing({ branch: endpoint }) }));
|
|
9277
|
+
let diffBaseRef = baseRef;
|
|
9278
|
+
if (input.range.symmetric) {
|
|
9279
|
+
const mergeBase = yield* runGit(input.directory, [
|
|
9280
|
+
"merge-base",
|
|
9281
|
+
baseRef,
|
|
9282
|
+
headRef
|
|
9283
|
+
]);
|
|
9284
|
+
if (mergeBase.status !== 0) return null;
|
|
9285
|
+
const mergeBaseRef = trimOrNull(mergeBase.stdout);
|
|
9286
|
+
if (mergeBaseRef === null) return null;
|
|
9287
|
+
diffBaseRef = mergeBaseRef;
|
|
9288
|
+
}
|
|
9289
|
+
const diff = yield* runGit(input.directory, [
|
|
9290
|
+
"diff",
|
|
9291
|
+
"-z",
|
|
9292
|
+
"--name-only",
|
|
9293
|
+
"--diff-filter=ACMR",
|
|
9294
|
+
"--relative",
|
|
9295
|
+
diffBaseRef,
|
|
9296
|
+
headRef
|
|
9297
|
+
]);
|
|
9298
|
+
if (diff.status !== 0) return null;
|
|
9299
|
+
return {
|
|
9300
|
+
currentBranch: yield* currentBranch(input.directory),
|
|
9301
|
+
baseBranch: baseRef,
|
|
9302
|
+
changedFiles: splitNullSeparated(diff.stdout),
|
|
9303
|
+
isCurrentChanges: false
|
|
9304
|
+
};
|
|
9305
|
+
});
|
|
9136
9306
|
return Git.of({
|
|
9137
9307
|
currentBranch,
|
|
9138
9308
|
defaultBranch,
|
|
@@ -9142,7 +9312,15 @@ var Git = class Git extends Context.Service()("react-doctor/Git") {
|
|
|
9142
9312
|
branchExists,
|
|
9143
9313
|
diffSelection: ({ directory, explicitBaseBranch }) => Effect.gen(function* () {
|
|
9144
9314
|
if (explicitBaseBranch !== void 0 && explicitBaseBranch.trim().length === 0) return yield* Effect.fail(new ReactDoctorError({ reason: new GitBaseBranchInvalid({ detail: "Diff base branch cannot be empty." }) }));
|
|
9145
|
-
if (explicitBaseBranch !== void 0
|
|
9315
|
+
if (explicitBaseBranch !== void 0) {
|
|
9316
|
+
const range = parseGitDiffRange(explicitBaseBranch);
|
|
9317
|
+
if (range !== null) return yield* resolveDiffRange({
|
|
9318
|
+
directory,
|
|
9319
|
+
range,
|
|
9320
|
+
raw: explicitBaseBranch
|
|
9321
|
+
});
|
|
9322
|
+
if (!isSafeGitRevision(explicitBaseBranch)) return yield* Effect.fail(new ReactDoctorError({ reason: new GitBaseBranchInvalid({ detail: `Diff base branch "${explicitBaseBranch}" is not a valid git ref name (${GIT_REF_NAME_RULE}).` }) }));
|
|
9323
|
+
}
|
|
9146
9324
|
const resolvedCurrentBranch = yield* currentBranch(directory);
|
|
9147
9325
|
if (resolvedCurrentBranch === null && explicitBaseBranch === void 0) return null;
|
|
9148
9326
|
const baseBranch = explicitBaseBranch ?? (yield* defaultBranch(directory));
|
|
@@ -10451,6 +10629,21 @@ const spawnOxlint = (args, rootDirectory, nodeBinaryPath, spawnTimeoutMs = OXLIN
|
|
|
10451
10629
|
resolve(output);
|
|
10452
10630
|
});
|
|
10453
10631
|
});
|
|
10632
|
+
const PARALLELISM_EXHAUSTION_ERROR_CODES = new Set([
|
|
10633
|
+
"EAGAIN",
|
|
10634
|
+
"EMFILE",
|
|
10635
|
+
"ENFILE",
|
|
10636
|
+
"ENOMEM"
|
|
10637
|
+
]);
|
|
10638
|
+
const isParallelismRelatedSpawnError = (error) => {
|
|
10639
|
+
if (!(error instanceof ReactDoctorError)) return false;
|
|
10640
|
+
const { reason } = error;
|
|
10641
|
+
if (reason._tag !== "OxlintSpawnFailed") return false;
|
|
10642
|
+
const { cause } = reason;
|
|
10643
|
+
if (typeof cause !== "object" || cause === null || !("code" in cause)) return false;
|
|
10644
|
+
const { code } = cause;
|
|
10645
|
+
return typeof code === "string" && PARALLELISM_EXHAUSTION_ERROR_CODES.has(code);
|
|
10646
|
+
};
|
|
10454
10647
|
/**
|
|
10455
10648
|
* Runs every prebuilt file batch through oxlint, with binary-split
|
|
10456
10649
|
* retry on the splittable error classes (timeout / output-too-large /
|
|
@@ -10459,66 +10652,83 @@ const spawnOxlint = (args, rootDirectory, nodeBinaryPath, spawnTimeoutMs = OXLIN
|
|
|
10459
10652
|
* (surfaced via `onPartialFailure`) so JSON-mode consumers see WHICH
|
|
10460
10653
|
* files were skipped instead of silently losing them.
|
|
10461
10654
|
*
|
|
10462
|
-
*
|
|
10463
|
-
*
|
|
10464
|
-
*
|
|
10465
|
-
*
|
|
10655
|
+
* Parallel runs (concurrency > 1) get one extra safety net: if the pass
|
|
10656
|
+
* fails with a resource-exhaustion error that's exclusive to running
|
|
10657
|
+
* many oxlint subprocesses at once (EAGAIN / EMFILE / ENFILE / ENOMEM —
|
|
10658
|
+
* see `isParallelismRelatedSpawnError`), the whole pass replays once
|
|
10659
|
+
* with a single worker. That's the only failure a serial replay can
|
|
10660
|
+
* clear, so every other error class is left to propagate.
|
|
10661
|
+
*
|
|
10662
|
+
* Errors that aren't splittable and aren't parallelism-related (oxlint
|
|
10663
|
+
* config crash, JS plugin resolution failure, etc.) propagate to the
|
|
10664
|
+
* caller — the `runOxlint` retry-without-extends fallback re-spawns this
|
|
10665
|
+
* loop with a slimmer config in that case.
|
|
10466
10666
|
*/
|
|
10467
10667
|
const spawnLintBatches = async (input) => {
|
|
10468
10668
|
const { baseArgs, fileBatches, rootDirectory, nodeBinaryPath, project, onPartialFailure, onFileProgress, spawnTimeoutMs, outputMaxBytes } = input;
|
|
10469
|
-
const
|
|
10669
|
+
const requestedConcurrency = resolveScanConcurrency(input.concurrency ?? 1);
|
|
10470
10670
|
const totalFileCount = fileBatches.reduce((sum, batch) => sum + batch.length, 0);
|
|
10471
|
-
const
|
|
10472
|
-
|
|
10473
|
-
|
|
10474
|
-
|
|
10475
|
-
const
|
|
10476
|
-
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
|
|
10481
|
-
|
|
10482
|
-
|
|
10483
|
-
|
|
10671
|
+
const runBatchPass = async (concurrency) => {
|
|
10672
|
+
const allDiagnostics = [];
|
|
10673
|
+
const droppedFiles = [];
|
|
10674
|
+
let firstDropReason = null;
|
|
10675
|
+
const spawnLintBatch = async (batch) => {
|
|
10676
|
+
const batchArgs = [...baseArgs, ...batch];
|
|
10677
|
+
try {
|
|
10678
|
+
return parseOxlintOutput(await spawnOxlint(batchArgs, rootDirectory, nodeBinaryPath, spawnTimeoutMs, outputMaxBytes), project, rootDirectory);
|
|
10679
|
+
} catch (error) {
|
|
10680
|
+
if (!isSplittableReactDoctorError(error)) throw error;
|
|
10681
|
+
if (batch.length <= 1) {
|
|
10682
|
+
droppedFiles.push(...batch);
|
|
10683
|
+
if (firstDropReason === null) firstDropReason = error.message;
|
|
10684
|
+
return [];
|
|
10685
|
+
}
|
|
10686
|
+
const splitIndex = Math.ceil(batch.length / 2);
|
|
10687
|
+
return [...await spawnLintBatch(batch.slice(0, splitIndex)), ...await spawnLintBatch(batch.slice(splitIndex))];
|
|
10484
10688
|
}
|
|
10485
|
-
|
|
10486
|
-
|
|
10689
|
+
};
|
|
10690
|
+
let startedFileCount = 0;
|
|
10691
|
+
let scannedFileCount = 0;
|
|
10692
|
+
let displayedFileCount = 0;
|
|
10693
|
+
const progressTimer = onFileProgress && totalFileCount > 1 ? setInterval(() => {
|
|
10694
|
+
const ceiling = Math.min(startedFileCount, totalFileCount - 1);
|
|
10695
|
+
if (displayedFileCount < ceiling) {
|
|
10696
|
+
displayedFileCount += 1;
|
|
10697
|
+
onFileProgress(displayedFileCount, totalFileCount);
|
|
10698
|
+
}
|
|
10699
|
+
}, 50) : null;
|
|
10700
|
+
progressTimer?.unref?.();
|
|
10701
|
+
try {
|
|
10702
|
+
const batchResults = await mapWithConcurrency(fileBatches, concurrency, async (batch) => {
|
|
10703
|
+
startedFileCount += batch.length;
|
|
10704
|
+
const batchDiagnostics = await spawnLintBatch(batch);
|
|
10705
|
+
scannedFileCount += batch.length;
|
|
10706
|
+
if (onFileProgress) {
|
|
10707
|
+
displayedFileCount = Math.min(Math.max(displayedFileCount, scannedFileCount), totalFileCount);
|
|
10708
|
+
onFileProgress(displayedFileCount, totalFileCount);
|
|
10709
|
+
}
|
|
10710
|
+
return batchDiagnostics;
|
|
10711
|
+
});
|
|
10712
|
+
for (const batchDiagnostics of batchResults) allDiagnostics.push(...batchDiagnostics);
|
|
10713
|
+
} finally {
|
|
10714
|
+
if (progressTimer !== null) clearInterval(progressTimer);
|
|
10487
10715
|
}
|
|
10716
|
+
if (droppedFiles.length > 0 && onPartialFailure) {
|
|
10717
|
+
const previewFiles = droppedFiles.slice(0, 3).join(", ");
|
|
10718
|
+
const remainderHint = droppedFiles.length > 3 ? `, +${droppedFiles.length - 3} more` : "";
|
|
10719
|
+
const reasonHint = firstDropReason ? ` — first failure: ${firstDropReason}` : "";
|
|
10720
|
+
onPartialFailure(`${droppedFiles.length} file(s) failed to lint and were skipped (${previewFiles}${remainderHint})${reasonHint}`);
|
|
10721
|
+
}
|
|
10722
|
+
return allDiagnostics;
|
|
10488
10723
|
};
|
|
10489
|
-
let
|
|
10490
|
-
let scannedFileCount = 0;
|
|
10491
|
-
let displayedFileCount = 0;
|
|
10492
|
-
const progressTimer = onFileProgress && totalFileCount > 1 ? setInterval(() => {
|
|
10493
|
-
const ceiling = Math.min(startedFileCount, totalFileCount - 1);
|
|
10494
|
-
if (displayedFileCount < ceiling) {
|
|
10495
|
-
displayedFileCount += 1;
|
|
10496
|
-
onFileProgress(displayedFileCount, totalFileCount);
|
|
10497
|
-
}
|
|
10498
|
-
}, 50) : null;
|
|
10499
|
-
progressTimer?.unref?.();
|
|
10724
|
+
let diagnostics;
|
|
10500
10725
|
try {
|
|
10501
|
-
|
|
10502
|
-
|
|
10503
|
-
|
|
10504
|
-
|
|
10505
|
-
if (onFileProgress) {
|
|
10506
|
-
displayedFileCount = Math.min(Math.max(displayedFileCount, scannedFileCount), totalFileCount);
|
|
10507
|
-
onFileProgress(displayedFileCount, totalFileCount);
|
|
10508
|
-
}
|
|
10509
|
-
return batchDiagnostics;
|
|
10510
|
-
});
|
|
10511
|
-
for (const batchDiagnostics of batchResults) allDiagnostics.push(...batchDiagnostics);
|
|
10512
|
-
} finally {
|
|
10513
|
-
if (progressTimer !== null) clearInterval(progressTimer);
|
|
10514
|
-
}
|
|
10515
|
-
if (droppedFiles.length > 0 && onPartialFailure) {
|
|
10516
|
-
const previewFiles = droppedFiles.slice(0, 3).join(", ");
|
|
10517
|
-
const remainderHint = droppedFiles.length > 3 ? `, +${droppedFiles.length - 3} more` : "";
|
|
10518
|
-
const reasonHint = firstDropReason ? ` — first failure: ${firstDropReason}` : "";
|
|
10519
|
-
onPartialFailure(`${droppedFiles.length} file(s) failed to lint and were skipped (${previewFiles}${remainderHint})${reasonHint}`);
|
|
10726
|
+
diagnostics = await runBatchPass(requestedConcurrency);
|
|
10727
|
+
} catch (error) {
|
|
10728
|
+
if (requestedConcurrency <= 1 || !isParallelismRelatedSpawnError(error)) throw error;
|
|
10729
|
+
diagnostics = await runBatchPass(1);
|
|
10520
10730
|
}
|
|
10521
|
-
return dedupeDiagnostics(
|
|
10731
|
+
return dedupeDiagnostics(diagnostics);
|
|
10522
10732
|
};
|
|
10523
10733
|
let didValidate = false;
|
|
10524
10734
|
/**
|
|
@@ -11077,7 +11287,7 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
11077
11287
|
reason: null
|
|
11078
11288
|
});
|
|
11079
11289
|
const scanConcurrency = yield* OxlintConcurrency;
|
|
11080
|
-
const workerCountSuffix = scanConcurrency > 1 ? `
|
|
11290
|
+
const workerCountSuffix = scanConcurrency > 1 ? ` ${highlighter.dim(`[~${scanConcurrency} workers]`)}` : "";
|
|
11081
11291
|
const scanProgress = yield* progressService.start("Scanning...");
|
|
11082
11292
|
const scanStartTime = Date.now();
|
|
11083
11293
|
let lastReportedTotalFileCount = 0;
|
|
@@ -11524,12 +11734,13 @@ const buildSkippedChecks = (input) => {
|
|
|
11524
11734
|
* Git service runs through Effect's `ChildProcess` (true subprocess
|
|
11525
11735
|
* spawn, not `spawnSync`).
|
|
11526
11736
|
*
|
|
11527
|
-
*
|
|
11528
|
-
*
|
|
11529
|
-
*
|
|
11530
|
-
*
|
|
11531
|
-
*
|
|
11532
|
-
*
|
|
11737
|
+
* Failures propagate as the tagged `ReactDoctorError` (rejected by
|
|
11738
|
+
* `Effect.runPromise`) rather than being flattened into a plain
|
|
11739
|
+
* `Error`. The message is unchanged — `ReactDoctorError.message`
|
|
11740
|
+
* defers to `reason.message` — so message-matching callers keep
|
|
11741
|
+
* working, while the CLI can now dispatch on `error.reason._tag` to
|
|
11742
|
+
* render diff-base mistakes (`GitBaseBranchInvalid` /
|
|
11743
|
+
* `GitBaseBranchMissing`) as clean user errors instead of crashes.
|
|
11533
11744
|
*/
|
|
11534
11745
|
const getDiffInfo = (directory, explicitBaseBranch) => Effect.runPromise(Effect.gen(function* () {
|
|
11535
11746
|
const selection = yield* (yield* Git).diffSelection({
|
|
@@ -11543,105 +11754,8 @@ const getDiffInfo = (directory, explicitBaseBranch) => Effect.runPromise(Effect.
|
|
|
11543
11754
|
changedFiles: [...selection.changedFiles],
|
|
11544
11755
|
...selection.isCurrentChanges ? { isCurrentChanges: true } : {}
|
|
11545
11756
|
};
|
|
11546
|
-
}).pipe(Effect.provide(Git.layerNode)
|
|
11547
|
-
GitBaseBranchInvalid: (reason) => Effect.die(new Error(reason.detail)),
|
|
11548
|
-
GitBaseBranchMissing: (reason) => Effect.die(new Error(reason.message))
|
|
11549
|
-
})));
|
|
11757
|
+
}).pipe(Effect.provide(Git.layerNode)));
|
|
11550
11758
|
const filterSourceFiles = (filePaths) => filePaths.filter(isLintableSourceFile);
|
|
11551
|
-
var import_picocolors = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
11552
|
-
let p = process || {}, argv = p.argv || [], env = p.env || {};
|
|
11553
|
-
let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
11554
|
-
let formatter = (open, close, replace = open) => (input) => {
|
|
11555
|
-
let string = "" + input, index = string.indexOf(close, open.length);
|
|
11556
|
-
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
11557
|
-
};
|
|
11558
|
-
let replaceClose = (string, close, replace, index) => {
|
|
11559
|
-
let result = "", cursor = 0;
|
|
11560
|
-
do {
|
|
11561
|
-
result += string.substring(cursor, index) + replace;
|
|
11562
|
-
cursor = index + close.length;
|
|
11563
|
-
index = string.indexOf(close, cursor);
|
|
11564
|
-
} while (~index);
|
|
11565
|
-
return result + string.substring(cursor);
|
|
11566
|
-
};
|
|
11567
|
-
let createColors = (enabled = isColorSupported) => {
|
|
11568
|
-
let f = enabled ? formatter : () => String;
|
|
11569
|
-
return {
|
|
11570
|
-
isColorSupported: enabled,
|
|
11571
|
-
reset: f("\x1B[0m", "\x1B[0m"),
|
|
11572
|
-
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
11573
|
-
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
11574
|
-
italic: f("\x1B[3m", "\x1B[23m"),
|
|
11575
|
-
underline: f("\x1B[4m", "\x1B[24m"),
|
|
11576
|
-
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
11577
|
-
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
11578
|
-
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
11579
|
-
black: f("\x1B[30m", "\x1B[39m"),
|
|
11580
|
-
red: f("\x1B[31m", "\x1B[39m"),
|
|
11581
|
-
green: f("\x1B[32m", "\x1B[39m"),
|
|
11582
|
-
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
11583
|
-
blue: f("\x1B[34m", "\x1B[39m"),
|
|
11584
|
-
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
11585
|
-
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
11586
|
-
white: f("\x1B[37m", "\x1B[39m"),
|
|
11587
|
-
gray: f("\x1B[90m", "\x1B[39m"),
|
|
11588
|
-
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
11589
|
-
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
11590
|
-
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
11591
|
-
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
11592
|
-
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
11593
|
-
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
11594
|
-
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
11595
|
-
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
11596
|
-
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
11597
|
-
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
11598
|
-
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
11599
|
-
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
11600
|
-
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
11601
|
-
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
11602
|
-
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
11603
|
-
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
11604
|
-
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
11605
|
-
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
11606
|
-
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
11607
|
-
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
11608
|
-
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
11609
|
-
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
11610
|
-
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
11611
|
-
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
11612
|
-
};
|
|
11613
|
-
};
|
|
11614
|
-
module.exports = createColors();
|
|
11615
|
-
module.exports.createColors = createColors;
|
|
11616
|
-
})))(), 1);
|
|
11617
|
-
const highlighter = {
|
|
11618
|
-
error: import_picocolors.default.red,
|
|
11619
|
-
warn: import_picocolors.default.yellow,
|
|
11620
|
-
info: import_picocolors.default.cyan,
|
|
11621
|
-
success: import_picocolors.default.green,
|
|
11622
|
-
dim: import_picocolors.default.dim,
|
|
11623
|
-
gray: import_picocolors.default.gray,
|
|
11624
|
-
bold: import_picocolors.default.bold
|
|
11625
|
-
};
|
|
11626
|
-
/**
|
|
11627
|
-
* Override picocolors' automatic color detection. picocolors decides
|
|
11628
|
-
* once, at import time, from `NO_COLOR` / `FORCE_COLOR` / `TERM` / TTY.
|
|
11629
|
-
* This lets the CLI honor an explicit `--color` / `--no-color` flag
|
|
11630
|
-
* (clig.dev, Output: "Disable color … if the user requested it") by
|
|
11631
|
-
* swapping in a fresh set of formatters. Call it before any colored
|
|
11632
|
-
* output is produced. Every call site reads `highlighter.<method>` at
|
|
11633
|
-
* call time, so reassigning the properties propagates everywhere.
|
|
11634
|
-
*/
|
|
11635
|
-
const setColorEnabled = (enabled) => {
|
|
11636
|
-
const colors = import_picocolors.default.createColors(enabled);
|
|
11637
|
-
highlighter.error = colors.red;
|
|
11638
|
-
highlighter.warn = colors.yellow;
|
|
11639
|
-
highlighter.info = colors.cyan;
|
|
11640
|
-
highlighter.success = colors.green;
|
|
11641
|
-
highlighter.dim = colors.dim;
|
|
11642
|
-
highlighter.gray = colors.gray;
|
|
11643
|
-
highlighter.bold = colors.bold;
|
|
11644
|
-
};
|
|
11645
11759
|
/**
|
|
11646
11760
|
* Canonical URL for a rule's documentation page — its reviewer-tested fix
|
|
11647
11761
|
* recipe rendered for humans — served at
|
|
@@ -11760,6 +11874,33 @@ const STAGED_FILES_TEMP_DIR_PREFIX = "react-doctor-staged-";
|
|
|
11760
11874
|
const INTERNAL_ERROR_JSON_FALLBACK = "{\"schemaVersion\":1,\"ok\":false,\"error\":{\"message\":\"Internal error\",\"name\":\"Error\",\"chain\":[]}}\n";
|
|
11761
11875
|
const SENTRY_FLUSH_TIMEOUT_MS = 2e3;
|
|
11762
11876
|
const NANOSECONDS_PER_SECOND = 1000000000n;
|
|
11877
|
+
const METRIC = {
|
|
11878
|
+
cliInvoked: "cli.invoked",
|
|
11879
|
+
cliError: "cli.error",
|
|
11880
|
+
projectDetected: "project.detected",
|
|
11881
|
+
scanCompleted: "scan.completed",
|
|
11882
|
+
scanDuration: "scan.duration",
|
|
11883
|
+
scanPhaseDuration: "scan.phase_duration",
|
|
11884
|
+
scanFiles: "scan.files",
|
|
11885
|
+
scanScore: "scan.score",
|
|
11886
|
+
scanClean: "scan.clean",
|
|
11887
|
+
scanCheckSkipped: "scan.check_skipped",
|
|
11888
|
+
ruleFired: "rule.fired",
|
|
11889
|
+
lintFailed: "lint.failed",
|
|
11890
|
+
deadCodeFailed: "deadcode.failed",
|
|
11891
|
+
scoreUnavailable: "score.unavailable",
|
|
11892
|
+
oxlintWorkers: "oxlint.workers",
|
|
11893
|
+
agentHandoff: "agent.handoff",
|
|
11894
|
+
agentInstallHintShown: "agent.install_hint_shown",
|
|
11895
|
+
installCompleted: "install.completed",
|
|
11896
|
+
installAgent: "install.agent",
|
|
11897
|
+
installGitHook: "install.git_hook",
|
|
11898
|
+
installWorkflow: "install.workflow",
|
|
11899
|
+
installAgentHooks: "install.agent_hooks",
|
|
11900
|
+
installDependency: "install.dependency",
|
|
11901
|
+
rulesChanged: "rules.changed",
|
|
11902
|
+
rulesQueried: "rules.queried"
|
|
11903
|
+
};
|
|
11763
11904
|
//#endregion
|
|
11764
11905
|
//#region src/cli/utils/noop-console.ts
|
|
11765
11906
|
/**
|
|
@@ -11801,7 +11942,7 @@ const makeNoopConsole = () => ({
|
|
|
11801
11942
|
});
|
|
11802
11943
|
//#endregion
|
|
11803
11944
|
//#region src/cli/utils/version.ts
|
|
11804
|
-
const VERSION = "0.2.
|
|
11945
|
+
const VERSION = "0.2.16";
|
|
11805
11946
|
//#endregion
|
|
11806
11947
|
//#region src/cli/utils/json-mode.ts
|
|
11807
11948
|
let context = null;
|
|
@@ -12025,13 +12166,20 @@ const buildSentryScope = (runContext = buildRunContext()) => {
|
|
|
12025
12166
|
};
|
|
12026
12167
|
};
|
|
12027
12168
|
//#endregion
|
|
12028
|
-
//#region src/cli/utils/
|
|
12169
|
+
//#region src/cli/utils/anonymize-text.ts
|
|
12170
|
+
/**
|
|
12171
|
+
* Free-text fields can carry both a home-directory path (the OS username) and a
|
|
12172
|
+
* secret/email echoed from user code, so run both scrubbers: strip the username
|
|
12173
|
+
* from paths, then mask any known credential/PII shape. Shared by the Sentry
|
|
12174
|
+
* event scrubber ({@link scrubSentryEvent}) and metric scrubber
|
|
12175
|
+
* ({@link scrubSentryMetric}).
|
|
12176
|
+
*/
|
|
12029
12177
|
const anonymizeText = (text) => redactSensitiveText(scrubSensitivePaths(text));
|
|
12030
12178
|
/**
|
|
12031
12179
|
* Recursively rewrites every string within an arbitrary value (object / array /
|
|
12032
12180
|
* primitive) through {@link anonymizeText}, mutating in place. Used to sweep the
|
|
12033
|
-
* unstructured corners of
|
|
12034
|
-
* span attributes) where a path or secret could hide.
|
|
12181
|
+
* unstructured corners of a Sentry payload (event contexts/extra/tags, breadcrumb
|
|
12182
|
+
* data, span attributes, metric attributes) where a path or secret could hide.
|
|
12035
12183
|
*/
|
|
12036
12184
|
const anonymizeInPlace = (value) => {
|
|
12037
12185
|
if (Array.isArray(value)) {
|
|
@@ -12049,6 +12197,8 @@ const anonymizeInPlace = (value) => {
|
|
|
12049
12197
|
else anonymizeInPlace(inner);
|
|
12050
12198
|
}
|
|
12051
12199
|
};
|
|
12200
|
+
//#endregion
|
|
12201
|
+
//#region src/cli/utils/scrub-sentry-event.ts
|
|
12052
12202
|
/**
|
|
12053
12203
|
* Anonymizes a Sentry event (error or transaction) before it leaves the
|
|
12054
12204
|
* machine. Strips identity the SDK attaches automatically — the IP-bearing
|
|
@@ -12096,6 +12246,27 @@ const scrubSentryEvent = (event) => {
|
|
|
12096
12246
|
}
|
|
12097
12247
|
};
|
|
12098
12248
|
//#endregion
|
|
12249
|
+
//#region src/cli/utils/scrub-sentry-metric.ts
|
|
12250
|
+
/**
|
|
12251
|
+
* Anonymizes a Sentry metric before it leaves the machine, mirroring
|
|
12252
|
+
* {@link scrubSentryEvent}. Drops the `server.address` default attribute (the
|
|
12253
|
+
* hostname) and scrubs home-directory paths + known secrets/emails from every
|
|
12254
|
+
* remaining attribute value (metric names are our own constants, so they're
|
|
12255
|
+
* left intact to avoid splitting a series). Returns `null` on any failure so an
|
|
12256
|
+
* un-anonymized metric is never sent. Wired into `beforeSendMetric`.
|
|
12257
|
+
*/
|
|
12258
|
+
const scrubSentryMetric = (metric) => {
|
|
12259
|
+
try {
|
|
12260
|
+
if (metric.attributes) {
|
|
12261
|
+
delete metric.attributes["server.address"];
|
|
12262
|
+
anonymizeInPlace(metric.attributes);
|
|
12263
|
+
}
|
|
12264
|
+
return metric;
|
|
12265
|
+
} catch {
|
|
12266
|
+
return null;
|
|
12267
|
+
}
|
|
12268
|
+
};
|
|
12269
|
+
//#endregion
|
|
12099
12270
|
//#region src/instrument.ts
|
|
12100
12271
|
let isInitialized = false;
|
|
12101
12272
|
let resolvedTracesSampleRate = 0;
|
|
@@ -12117,13 +12288,13 @@ const isDevVersion = (version) => version === "0.0.0" || version.includes("-");
|
|
|
12117
12288
|
* uploads source-map artifacts under, so stack frames symbolicate. Honors the
|
|
12118
12289
|
* standard `SENTRY_RELEASE` override.
|
|
12119
12290
|
*/
|
|
12120
|
-
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.2.
|
|
12291
|
+
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.2.16`;
|
|
12121
12292
|
/**
|
|
12122
12293
|
* Deployment environment shown in Sentry's environment filter. Defaults to
|
|
12123
12294
|
* `production` for tagged releases and `development` for dev/unbuilt versions,
|
|
12124
12295
|
* overridable via the standard `SENTRY_ENVIRONMENT` env var.
|
|
12125
12296
|
*/
|
|
12126
|
-
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.2.
|
|
12297
|
+
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.2.16") ? "development" : "production");
|
|
12127
12298
|
/**
|
|
12128
12299
|
* Performance-tracing sample rate in `[0, 1]`. Reads `SENTRY_TRACES_SAMPLE_RATE`
|
|
12129
12300
|
* (set to `0` to disable tracing) and falls back to
|
|
@@ -12191,7 +12362,8 @@ const initializeSentry = () => {
|
|
|
12191
12362
|
contexts
|
|
12192
12363
|
},
|
|
12193
12364
|
beforeSend: (event) => scrubSentryEvent(event),
|
|
12194
|
-
beforeSendTransaction: (event) => scrubSentryEvent(event)
|
|
12365
|
+
beforeSendTransaction: (event) => scrubSentryEvent(event),
|
|
12366
|
+
beforeSendMetric: (metric) => scrubSentryMetric(metric)
|
|
12195
12367
|
});
|
|
12196
12368
|
};
|
|
12197
12369
|
//#endregion
|
|
@@ -15463,6 +15635,122 @@ const recordSentryProjectContext = (projectInfo, rootSpan) => {
|
|
|
15463
15635
|
rootSpan?.setAttributes(toSpanAttributes(buildSentryProjectContext(projectInfo).tags));
|
|
15464
15636
|
};
|
|
15465
15637
|
//#endregion
|
|
15638
|
+
//#region src/cli/utils/record-metric.ts
|
|
15639
|
+
const cleanAttributes = (attributes) => {
|
|
15640
|
+
const cleaned = {};
|
|
15641
|
+
if (!attributes) return cleaned;
|
|
15642
|
+
for (const [key, value] of Object.entries(attributes)) if (value !== null && value !== void 0) cleaned[key] = value;
|
|
15643
|
+
return cleaned;
|
|
15644
|
+
};
|
|
15645
|
+
const withRunAttributes = (attributes) => ({
|
|
15646
|
+
...toSpanAttributes(buildSentryScope().tags),
|
|
15647
|
+
...cleanAttributes(attributes)
|
|
15648
|
+
});
|
|
15649
|
+
/**
|
|
15650
|
+
* Emits a Sentry counter. A guarded, swallow-on-throw no-op unless the CLI's
|
|
15651
|
+
* Sentry SDK is live, so it's inert under `--no-score`, tests, and the
|
|
15652
|
+
* programmatic `@react-doctor/api` library (none of which initialize Sentry).
|
|
15653
|
+
* Metrics flow independently of performance tracing, so counters are still
|
|
15654
|
+
* recorded when `SENTRY_TRACES_SAMPLE_RATE=0`.
|
|
15655
|
+
*/
|
|
15656
|
+
const recordCount = (name, value = 1, attributes) => {
|
|
15657
|
+
if (!Sentry.isInitialized()) return;
|
|
15658
|
+
try {
|
|
15659
|
+
Sentry.metrics.count(name, value, { attributes: withRunAttributes(attributes) });
|
|
15660
|
+
} catch {}
|
|
15661
|
+
};
|
|
15662
|
+
/**
|
|
15663
|
+
* Emits a Sentry distribution (value ranges — durations, sizes, scores). Same
|
|
15664
|
+
* gating and run-attribute handling as {@link recordCount}.
|
|
15665
|
+
*/
|
|
15666
|
+
const recordDistribution = (name, value, options = {}) => {
|
|
15667
|
+
if (!Sentry.isInitialized()) return;
|
|
15668
|
+
try {
|
|
15669
|
+
Sentry.metrics.distribution(name, value, {
|
|
15670
|
+
unit: options.unit,
|
|
15671
|
+
attributes: withRunAttributes(options.attributes)
|
|
15672
|
+
});
|
|
15673
|
+
} catch {}
|
|
15674
|
+
};
|
|
15675
|
+
//#endregion
|
|
15676
|
+
//#region src/cli/utils/record-scan-metrics.ts
|
|
15677
|
+
/**
|
|
15678
|
+
* Aggregates diagnostics into per-`(rule, severity)` firing counts, reusing the
|
|
15679
|
+
* canonical `getDiagnosticRuleIdentity` so the `<plugin>/<rule>` key and
|
|
15680
|
+
* category match every other rule-keyed surface. Pure and exported so the
|
|
15681
|
+
* bucketing is unit-testable without an active Sentry client (the emit helpers
|
|
15682
|
+
* no-op under tests). Grouping the emitted `rule.fired` counter by `category`
|
|
15683
|
+
* or `severity` in Sentry reproduces a coarser breakdown.
|
|
15684
|
+
*/
|
|
15685
|
+
const summarizeRuleFirings = (diagnostics) => {
|
|
15686
|
+
const firings = /* @__PURE__ */ new Map();
|
|
15687
|
+
for (const diagnostic of diagnostics) {
|
|
15688
|
+
const { ruleKey, category } = getDiagnosticRuleIdentity(diagnostic);
|
|
15689
|
+
const firingKey = `${ruleKey}\u0000${diagnostic.severity}`;
|
|
15690
|
+
const existing = firings.get(firingKey);
|
|
15691
|
+
firings.set(firingKey, existing ? {
|
|
15692
|
+
...existing,
|
|
15693
|
+
count: existing.count + 1
|
|
15694
|
+
} : {
|
|
15695
|
+
rule: ruleKey,
|
|
15696
|
+
plugin: diagnostic.plugin,
|
|
15697
|
+
category,
|
|
15698
|
+
severity: diagnostic.severity,
|
|
15699
|
+
count: 1
|
|
15700
|
+
});
|
|
15701
|
+
}
|
|
15702
|
+
return [...firings.values()];
|
|
15703
|
+
};
|
|
15704
|
+
/**
|
|
15705
|
+
* Emits the per-scan engineering + product counters/distributions for one
|
|
15706
|
+
* `inspect()` run (fires once per project in a workspace scan). Every emission
|
|
15707
|
+
* is a no-op unless Sentry is live, and the shared run/project attributes ride
|
|
15708
|
+
* along from the global scope, so call sites only pass scan-specific dimensions.
|
|
15709
|
+
*/
|
|
15710
|
+
const recordScanMetrics = (input) => {
|
|
15711
|
+
const { result } = input;
|
|
15712
|
+
const hasSkippedChecks = result.skippedChecks.length > 0;
|
|
15713
|
+
recordCount(METRIC.scanCompleted, 1, {
|
|
15714
|
+
mode: input.mode,
|
|
15715
|
+
lint: input.lint,
|
|
15716
|
+
deadCode: input.deadCode,
|
|
15717
|
+
parallel: input.parallel,
|
|
15718
|
+
scoreOnly: input.scoreOnly,
|
|
15719
|
+
didLintFail: input.didLintFail,
|
|
15720
|
+
didDeadCodeFail: input.didDeadCodeFail,
|
|
15721
|
+
hasSkippedChecks
|
|
15722
|
+
});
|
|
15723
|
+
recordDistribution(METRIC.scanDuration, result.elapsedMilliseconds, {
|
|
15724
|
+
unit: "millisecond",
|
|
15725
|
+
attributes: {
|
|
15726
|
+
mode: input.mode,
|
|
15727
|
+
parallel: input.parallel,
|
|
15728
|
+
scoreOnly: input.scoreOnly
|
|
15729
|
+
}
|
|
15730
|
+
});
|
|
15731
|
+
if (result.scanElapsedMilliseconds !== void 0) recordDistribution(METRIC.scanPhaseDuration, result.scanElapsedMilliseconds, {
|
|
15732
|
+
unit: "millisecond",
|
|
15733
|
+
attributes: { mode: input.mode }
|
|
15734
|
+
});
|
|
15735
|
+
if (result.scannedFileCount !== void 0) recordDistribution(METRIC.scanFiles, result.scannedFileCount, { attributes: { mode: input.mode } });
|
|
15736
|
+
if (input.workerCount !== void 0) recordDistribution(METRIC.oxlintWorkers, input.workerCount, { attributes: { mode: input.mode } });
|
|
15737
|
+
for (const firing of summarizeRuleFirings(result.diagnostics)) recordCount(METRIC.ruleFired, firing.count, {
|
|
15738
|
+
rule: firing.rule,
|
|
15739
|
+
plugin: firing.plugin,
|
|
15740
|
+
category: firing.category,
|
|
15741
|
+
severity: firing.severity
|
|
15742
|
+
});
|
|
15743
|
+
if (result.diagnostics.length === 0 && !hasSkippedChecks) recordCount(METRIC.scanClean, 1, { mode: input.mode });
|
|
15744
|
+
if (result.score) recordDistribution(METRIC.scanScore, result.score.score, { attributes: { mode: input.mode } });
|
|
15745
|
+
else if (!input.noScore && !input.didLintFail) recordCount(METRIC.scoreUnavailable, 1, { mode: input.mode });
|
|
15746
|
+
if (input.didLintFail) recordCount(METRIC.lintFailed, 1, { reasonKind: input.lintFailureReasonKind });
|
|
15747
|
+
if (input.didDeadCodeFail) recordCount(METRIC.deadCodeFailed, 1);
|
|
15748
|
+
for (const check of result.skippedChecks) recordCount(METRIC.scanCheckSkipped, 1, {
|
|
15749
|
+
check,
|
|
15750
|
+
reason: result.skippedCheckReasons?.[check] ?? null
|
|
15751
|
+
});
|
|
15752
|
+
};
|
|
15753
|
+
//#endregion
|
|
15466
15754
|
//#region src/cli/utils/build-no-score-message.ts
|
|
15467
15755
|
const ENTERPRISE_CONTACT_HINT = `Want something custom to your company? Contact us at ${ENTERPRISE_CONTACT_URL}.`;
|
|
15468
15756
|
const buildNoScoreMessage = (isScoreDisabled) => {
|
|
@@ -15586,6 +15874,9 @@ const buildCodeFrame = (input) => {
|
|
|
15586
15874
|
});
|
|
15587
15875
|
};
|
|
15588
15876
|
//#endregion
|
|
15877
|
+
//#region src/cli/utils/build-section-divider.ts
|
|
15878
|
+
const buildSectionDivider = () => highlighter.dim(` ${"─".repeat(60)}`);
|
|
15879
|
+
//#endregion
|
|
15589
15880
|
//#region src/cli/utils/indent-multiline-text.ts
|
|
15590
15881
|
const indentMultilineText = (text, linePrefix) => text.split("\n").map((lineText) => `${linePrefix}${lineText}`).join("\n");
|
|
15591
15882
|
//#endregion
|
|
@@ -15668,7 +15959,6 @@ const buildCompactCategoryLine = (categoryGroup) => {
|
|
|
15668
15959
|
};
|
|
15669
15960
|
const TOP_ERROR_DETAIL_INDENT = " ";
|
|
15670
15961
|
const pickRepresentativeDiagnostic = (ruleDiagnostics) => ruleDiagnostics.find((diagnostic) => diagnostic.line > 0) ?? ruleDiagnostics[0];
|
|
15671
|
-
const isErrorRuleGroup = (ruleDiagnostics) => pickRepresentativeDiagnostic(ruleDiagnostics).severity === "error";
|
|
15672
15962
|
const FRAME_CONTEXT_REACH_LINES = 3;
|
|
15673
15963
|
const clusterNearbyDiagnostics = (diagnostics) => {
|
|
15674
15964
|
const byFile = groupBy(diagnostics, (diagnostic) => diagnostic.filePath);
|
|
@@ -15719,89 +16009,60 @@ const buildDiagnosticClusterLines = (cluster, resolveSourceRoot, renderCodeFrame
|
|
|
15719
16009
|
}
|
|
15720
16010
|
return lines;
|
|
15721
16011
|
};
|
|
15722
|
-
const buildRuleDetailBlock = (ruleKey, ruleDiagnostics, resolveSourceRoot, renderEverySite) => {
|
|
16012
|
+
const buildRuleDetailBlock = (ruleKey, ruleDiagnostics, resolveSourceRoot, renderEverySite, isAgentEnvironment) => {
|
|
15723
16013
|
const representative = pickRepresentativeDiagnostic(ruleDiagnostics);
|
|
15724
16014
|
const { severity } = representative;
|
|
15725
16015
|
const trailingBadge = formatTrailingSiteBadge(ruleDiagnostics.length);
|
|
15726
16016
|
const headline = colorizeBySeverity(`${representative.category}: ${representative.title ?? ruleKey}`, severity);
|
|
15727
16017
|
const lines = [` ${colorizeBySeverity(severity === "error" ? "✗" : "⚠", severity)} ${headline}${trailingBadge}`];
|
|
15728
|
-
if (
|
|
15729
|
-
if (representative.help) for (const fixLine of wrapTextToWidth(`→ ${representative.help}`, 60, { breakLongWords: false })) lines.push(highlighter.dim(`${TOP_ERROR_DETAIL_INDENT}${fixLine}`));
|
|
15730
|
-
const renderCodeFrame = severity === "error";
|
|
15731
|
-
const sites = renderEverySite ? ruleDiagnostics : [representative];
|
|
15732
|
-
for (const cluster of clusterNearbyDiagnostics(sites)) lines.push(...buildDiagnosticClusterLines(cluster, resolveSourceRoot, renderCodeFrame));
|
|
15733
|
-
return lines;
|
|
15734
|
-
};
|
|
15735
|
-
const WARNING_DETAIL_INDENT = " ";
|
|
15736
|
-
const computeRuleNameColumnWidth = (ruleKeys) => ruleKeys.reduce((widest, ruleKey) => Math.max(widest, ruleKey.length), 36);
|
|
15737
|
-
const padRuleNameToColumn = (ruleName, columnWidth) => ruleName.length >= columnWidth ? ruleName : ruleName + " ".repeat(columnWidth - ruleName.length);
|
|
15738
|
-
const buildWarningHeaderLine = (ruleKey, siteCount, ruleNameColumnWidth) => {
|
|
15739
|
-
const ruleName = formatSiteCountBadge(siteCount).length > 0 ? padRuleNameToColumn(ruleKey, ruleNameColumnWidth) : ruleKey;
|
|
15740
|
-
return ` ${highlighter.warn("⚠")} ${ruleName}${formatTrailingSiteBadge(siteCount)}`;
|
|
15741
|
-
};
|
|
15742
|
-
const buildWarningRuleBlock = (ruleKey, ruleDiagnostics, ruleNameColumnWidth, isAgentEnvironment) => {
|
|
15743
|
-
const representative = pickRepresentativeDiagnostic(ruleDiagnostics);
|
|
15744
|
-
const lines = [buildWarningHeaderLine(ruleKey, ruleDiagnostics.length, ruleNameColumnWidth)];
|
|
15745
|
-
if (!isAgentEnvironment) {
|
|
16018
|
+
if (renderEverySite && !isAgentEnvironment) {
|
|
15746
16019
|
const learnMoreLine = formatLearnMoreLine(representative);
|
|
15747
|
-
if (learnMoreLine) lines.push(`${
|
|
16020
|
+
if (learnMoreLine) lines.push(`${TOP_ERROR_DETAIL_INDENT}${highlighter.info(learnMoreLine)}`);
|
|
15748
16021
|
}
|
|
15749
|
-
|
|
15750
|
-
if (representative.help)
|
|
15751
|
-
if (isAgentEnvironment) {
|
|
16022
|
+
if (!renderEverySite) for (const explanationLine of wrapTextToWidth(representative.message, 60, { breakLongWords: false })) lines.push(`${TOP_ERROR_DETAIL_INDENT}${explanationLine}`);
|
|
16023
|
+
if (representative.help) for (const fixLine of wrapTextToWidth(`→ ${representative.help}`, 60, { breakLongWords: false })) lines.push(highlighter.dim(`${TOP_ERROR_DETAIL_INDENT}${fixLine}`));
|
|
16024
|
+
if (renderEverySite && isAgentEnvironment) {
|
|
15752
16025
|
const fixRecipeLine = formatFixRecipeLine(representative);
|
|
15753
|
-
if (fixRecipeLine) lines.push(highlighter.gray(`${
|
|
15754
|
-
}
|
|
15755
|
-
for (const [filePath, sites] of buildVerboseSiteMap(ruleDiagnostics)) {
|
|
15756
|
-
if (sites.length === 0) {
|
|
15757
|
-
lines.push(highlighter.gray(`${WARNING_DETAIL_INDENT}${filePath}`));
|
|
15758
|
-
continue;
|
|
15759
|
-
}
|
|
15760
|
-
for (const site of sites) {
|
|
15761
|
-
lines.push(highlighter.gray(`${WARNING_DETAIL_INDENT}${filePath}:${site.line}`));
|
|
15762
|
-
if (site.suppressionHint) lines.push(highlighter.gray(`${WARNING_DETAIL_INDENT} ↳ ${site.suppressionHint}`));
|
|
15763
|
-
}
|
|
16026
|
+
if (fixRecipeLine) lines.push(highlighter.gray(`${TOP_ERROR_DETAIL_INDENT}${fixRecipeLine}`));
|
|
15764
16027
|
}
|
|
16028
|
+
const renderCodeFrame = severity === "error" || renderEverySite;
|
|
16029
|
+
const sites = renderEverySite ? ruleDiagnostics : [representative];
|
|
16030
|
+
for (const cluster of clusterNearbyDiagnostics(sites)) lines.push(...buildDiagnosticClusterLines(cluster, resolveSourceRoot, renderCodeFrame));
|
|
15765
16031
|
return lines;
|
|
15766
16032
|
};
|
|
15767
16033
|
const selectErrorRuleGroups = (diagnostics, rulePriority) => buildSortedRuleGroups(diagnostics.filter((diagnostic) => diagnostic.severity === "error"), rulePriority);
|
|
15768
16034
|
const selectTopErrorRuleGroups = (diagnostics, limit, rulePriority) => selectErrorRuleGroups(diagnostics, rulePriority).slice(0, limit);
|
|
15769
|
-
const
|
|
15770
|
-
const
|
|
15771
|
-
|
|
16035
|
+
const buildOverflowSummaryLine = (diagnostics, rulePriority) => {
|
|
16036
|
+
const errorRuleGroups = selectErrorRuleGroups(diagnostics, rulePriority);
|
|
16037
|
+
const shownErrorRuleCount = Math.min(3, errorRuleGroups.length);
|
|
16038
|
+
if (diagnostics.length <= shownErrorRuleCount) return void 0;
|
|
16039
|
+
const hiddenErrorRuleCount = errorRuleGroups.length - shownErrorRuleCount;
|
|
16040
|
+
const warningCount = diagnostics.filter((diagnostic) => diagnostic.severity === "warning").length;
|
|
16041
|
+
const parts = [];
|
|
16042
|
+
if (hiddenErrorRuleCount > 0) {
|
|
16043
|
+
const ruleNoun = hiddenErrorRuleCount === 1 ? "rule" : "rules";
|
|
16044
|
+
parts.push(highlighter.bold(highlighter.error(`+${hiddenErrorRuleCount} more ${ruleNoun}`)));
|
|
16045
|
+
}
|
|
16046
|
+
if (warningCount > 0) {
|
|
16047
|
+
const warningNoun = warningCount === 1 ? "warning" : "warnings";
|
|
16048
|
+
parts.push(highlighter.bold(highlighter.warn(`+${warningCount} optional ${warningNoun}`)));
|
|
16049
|
+
}
|
|
16050
|
+
const command = highlighter.bold(highlighter.info("npx react-doctor@latest --verbose"));
|
|
16051
|
+
return ` ${parts.length > 0 ? `${parts.join(highlighter.dim(" and "))} ${highlighter.dim("— run")}` : highlighter.dim("Run")} ${command} ${highlighter.dim("for details")}`;
|
|
15772
16052
|
};
|
|
15773
16053
|
const getTopErrorRuleKeys = (diagnostics, limit, rulePriority) => new Set(selectTopErrorRuleGroups(diagnostics, limit, rulePriority).map(([ruleKey]) => ruleKey));
|
|
15774
16054
|
const buildTopErrorsLines = (diagnostics, resolveSourceRoot, rulePriority) => {
|
|
15775
|
-
const
|
|
15776
|
-
const topRuleGroups = errorRuleGroups.slice(0, 3);
|
|
16055
|
+
const topRuleGroups = selectErrorRuleGroups(diagnostics, rulePriority).slice(0, 3);
|
|
15777
16056
|
if (topRuleGroups.length === 0) return [];
|
|
15778
|
-
const hiddenRuleCount = errorRuleGroups.length - topRuleGroups.length;
|
|
15779
16057
|
const lines = [
|
|
15780
|
-
|
|
16058
|
+
buildSectionDivider(),
|
|
15781
16059
|
` ${highlighter.bold(`Top ${topRuleGroups.length} ${topRuleGroups.length === 1 ? "error" : "errors"} you should fix`)}`,
|
|
15782
16060
|
""
|
|
15783
16061
|
];
|
|
15784
16062
|
for (const [ruleKey, ruleDiagnostics] of topRuleGroups) {
|
|
15785
|
-
lines.push(...buildRuleDetailBlock(ruleKey, ruleDiagnostics, resolveSourceRoot, false));
|
|
16063
|
+
lines.push(...buildRuleDetailBlock(ruleKey, ruleDiagnostics, resolveSourceRoot, false, false));
|
|
15786
16064
|
lines.push("");
|
|
15787
16065
|
}
|
|
15788
|
-
if (hiddenRuleCount > 0) lines.push(buildMoreRulesLine(hiddenRuleCount, "errors", highlighter.error));
|
|
15789
|
-
return lines;
|
|
15790
|
-
};
|
|
15791
|
-
const buildWarningsListLines = (diagnostics, rulePriority) => {
|
|
15792
|
-
const warningDiagnostics = diagnostics.filter((diagnostic) => diagnostic.severity === "warning");
|
|
15793
|
-
if (warningDiagnostics.length === 0) return [];
|
|
15794
|
-
const sortedRuleGroups = buildSortedRuleGroups(warningDiagnostics, rulePriority);
|
|
15795
|
-
const shownRuleGroups = sortedRuleGroups.slice(0, 10);
|
|
15796
|
-
const hiddenRuleCount = sortedRuleGroups.length - shownRuleGroups.length;
|
|
15797
|
-
const ruleNameColumnWidth = computeRuleNameColumnWidth(shownRuleGroups.map(([ruleKey]) => ruleKey));
|
|
15798
|
-
const lines = [
|
|
15799
|
-
highlighter.dim(` ${"─".repeat(60)}`),
|
|
15800
|
-
` ${highlighter.bold(`${warningDiagnostics.length} ${warningDiagnostics.length === 1 ? "warning" : "warnings"}`)}`,
|
|
15801
|
-
""
|
|
15802
|
-
];
|
|
15803
|
-
for (const [ruleKey, ruleDiagnostics] of shownRuleGroups) lines.push(buildWarningHeaderLine(ruleKey, ruleDiagnostics.length, ruleNameColumnWidth));
|
|
15804
|
-
if (hiddenRuleCount > 0) lines.push(buildMoreRulesLine(hiddenRuleCount, "warnings", highlighter.warn));
|
|
15805
16066
|
return lines;
|
|
15806
16067
|
};
|
|
15807
16068
|
const buildCategoryBreakdownLines = (diagnostics, rulePriority) => buildCategoryDiagnosticGroups(diagnostics, rulePriority).map(buildCompactCategoryLine);
|
|
@@ -15832,14 +16093,11 @@ const printDiagnostics = (diagnostics, isVerbose, sourceRoot, rulePriority, isAg
|
|
|
15832
16093
|
const resolveSourceRoot = typeof sourceRoot === "function" ? sourceRoot : () => sourceRoot;
|
|
15833
16094
|
let detailLines;
|
|
15834
16095
|
if (!isVerbose) detailLines = buildTopErrorsLines(diagnostics, resolveSourceRoot, rulePriority);
|
|
15835
|
-
else {
|
|
15836
|
-
|
|
15837
|
-
|
|
15838
|
-
|
|
15839
|
-
|
|
15840
|
-
});
|
|
15841
|
-
}
|
|
15842
|
-
const lines = joinSections(buildCategoryBreakdownLines(diagnostics, rulePriority), buildCountsSummaryLines(diagnostics), detailLines, isVerbose ? [] : buildWarningsListLines(diagnostics, rulePriority));
|
|
16096
|
+
else detailLines = buildSortedRuleGroups(diagnostics, rulePriority).flatMap(([ruleKey, ruleDiagnostics]) => {
|
|
16097
|
+
return [...buildRuleDetailBlock(ruleKey, ruleDiagnostics, resolveSourceRoot, true, isAgentEnvironment), ""];
|
|
16098
|
+
});
|
|
16099
|
+
const overflowLine = isVerbose ? void 0 : buildOverflowSummaryLine(diagnostics, rulePriority);
|
|
16100
|
+
const lines = joinSections(buildCategoryBreakdownLines(diagnostics, rulePriority), buildCountsSummaryLines(diagnostics), detailLines, overflowLine ? [overflowLine] : []);
|
|
15843
16101
|
for (const line of lines) yield* Console.log(line);
|
|
15844
16102
|
});
|
|
15845
16103
|
const formatElapsedTime = (elapsedMilliseconds) => {
|
|
@@ -16099,16 +16357,21 @@ const buildShareUrl = (diagnostics, scoreResult, projectName) => {
|
|
|
16099
16357
|
if (affectedFileCount > 0) params.set("f", String(affectedFileCount));
|
|
16100
16358
|
return `${SHARE_BASE_URL}?${params.toString()}`;
|
|
16101
16359
|
};
|
|
16102
|
-
const
|
|
16103
|
-
|
|
16104
|
-
|
|
16105
|
-
const message = diagnostics.some((diagnostic) => diagnostic.severity === "warning") ? `Run ${command} to see each warning explained with its fix` : `Run ${command} to see each issue explained with its fix`;
|
|
16106
|
-
yield* Console.log(highlighter.dim(` Tip: ${message}`));
|
|
16107
|
-
});
|
|
16108
|
-
const printDocsNote = () => Effect.gen(function* () {
|
|
16360
|
+
const printFooter = (input) => Effect.gen(function* () {
|
|
16361
|
+
yield* Console.log("");
|
|
16362
|
+
yield* Console.log(buildSectionDivider());
|
|
16109
16363
|
yield* Console.log("");
|
|
16364
|
+
if (!input.isOffline) {
|
|
16365
|
+
const shareUrl = buildShareUrl(input.diagnostics, input.scoreResult, input.projectName);
|
|
16366
|
+
yield* Console.log(` ${highlighter.bold("Share:")} ${highlighter.info(shareUrl)}`);
|
|
16367
|
+
yield* Console.log(highlighter.dim(" Tell others how you did on socials"));
|
|
16368
|
+
yield* Console.log("");
|
|
16369
|
+
}
|
|
16110
16370
|
yield* Console.log(` ${highlighter.bold("Docs:")} ${highlighter.info(DOCS_URL)}`);
|
|
16111
|
-
yield* Console.log(highlighter.dim("
|
|
16371
|
+
yield* Console.log(highlighter.dim(" Learn more about fixing issues, setting up CI/CD, and configuring rules with a config file"));
|
|
16372
|
+
yield* Console.log("");
|
|
16373
|
+
yield* Console.log(` ${highlighter.bold("GitHub:")} ${highlighter.info(CANONICAL_GITHUB_URL)}`);
|
|
16374
|
+
yield* Console.log(highlighter.dim(" Report issues and star the repository!"));
|
|
16112
16375
|
});
|
|
16113
16376
|
const printSummary = (input) => Effect.gen(function* () {
|
|
16114
16377
|
if (input.scoreResult) {
|
|
@@ -16123,12 +16386,6 @@ const printSummary = (input) => Effect.gen(function* () {
|
|
|
16123
16386
|
catch: (cause) => cause
|
|
16124
16387
|
}).pipe(Effect.orElseSucceed(() => null));
|
|
16125
16388
|
if (diagnosticsDirectory !== null && input.verbose) yield* Console.log(highlighter.gray(` Full diagnostics written to ${diagnosticsDirectory}`));
|
|
16126
|
-
if (!input.isOffline) {
|
|
16127
|
-
yield* Console.log("");
|
|
16128
|
-
const shareUrl = buildShareUrl(input.diagnostics, input.scoreResult, input.projectName);
|
|
16129
|
-
yield* Console.log(` ${highlighter.bold("Share:")} ${highlighter.info(shareUrl)}`);
|
|
16130
|
-
yield* Console.log("");
|
|
16131
|
-
}
|
|
16132
16389
|
});
|
|
16133
16390
|
//#endregion
|
|
16134
16391
|
//#region src/cli/utils/cli-logger.ts
|
|
@@ -16370,6 +16627,7 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
16370
16627
|
suppressScanSummary: options.suppressRendering
|
|
16371
16628
|
}, { beforeLint: (projectInfo, lintIncludePaths) => Effect.gen(function* () {
|
|
16372
16629
|
recordSentryProjectContext(projectInfo, rootSentrySpan);
|
|
16630
|
+
recordCount(METRIC.projectDetected, 1);
|
|
16373
16631
|
if (options.scoreOnly || options.suppressRendering) return;
|
|
16374
16632
|
const lintSourceFileCount = lintIncludePaths?.length ?? projectInfo.sourceFileCount;
|
|
16375
16633
|
yield* printProjectDetection({
|
|
@@ -16405,7 +16663,21 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
16405
16663
|
scannedFilePaths: output.scannedFilePaths,
|
|
16406
16664
|
scanElapsedMilliseconds: output.scanElapsedMilliseconds
|
|
16407
16665
|
};
|
|
16408
|
-
|
|
16666
|
+
const result = await Effect.runPromise(finalizeAndRender(finalizeInput).pipe(options.silent ? Effect.provideService(Console.Console, silentConsole) : (program) => program));
|
|
16667
|
+
recordScanMetrics({
|
|
16668
|
+
result,
|
|
16669
|
+
mode: isDiffMode ? "diff" : "full",
|
|
16670
|
+
parallel: options.concurrency !== void 0,
|
|
16671
|
+
workerCount: options.concurrency,
|
|
16672
|
+
lint: options.lint,
|
|
16673
|
+
deadCode: options.deadCode,
|
|
16674
|
+
scoreOnly: options.scoreOnly,
|
|
16675
|
+
noScore: options.noScore,
|
|
16676
|
+
didLintFail,
|
|
16677
|
+
lintFailureReasonKind: lintBindingMissing ? "native-binding-missing" : output.lintFailureReasonKind,
|
|
16678
|
+
didDeadCodeFail: output.didDeadCodeFail
|
|
16679
|
+
});
|
|
16680
|
+
return result;
|
|
16409
16681
|
};
|
|
16410
16682
|
const finalizeAndRender = (input) => Effect.gen(function* () {
|
|
16411
16683
|
const { options, elapsedMilliseconds, diagnostics, score, project, userConfig, didLintFail, lintFailureReason, lintPartialFailures, didDeadCodeFail, deadCodeFailureReason, directory, scannedFileCount, scannedFilePaths, scanElapsedMilliseconds } = input;
|
|
@@ -16466,10 +16738,8 @@ const finalizeAndRender = (input) => Effect.gen(function* () {
|
|
|
16466
16738
|
elapsedMilliseconds,
|
|
16467
16739
|
scoreResult: score,
|
|
16468
16740
|
potentialScore,
|
|
16469
|
-
projectName: project.projectName,
|
|
16470
16741
|
totalSourceFileCount: lintSourceFileCount,
|
|
16471
16742
|
noScoreMessage,
|
|
16472
|
-
isOffline: !shouldShowShareLink,
|
|
16473
16743
|
verbose: options.verbose
|
|
16474
16744
|
});
|
|
16475
16745
|
if (hasSkippedChecks) {
|
|
@@ -16477,8 +16747,12 @@ const finalizeAndRender = (input) => Effect.gen(function* () {
|
|
|
16477
16747
|
yield* Console.log("");
|
|
16478
16748
|
yield* Console.warn(highlighter.warn(` Note: ${skippedLabel} checks failed — score may be incomplete.`));
|
|
16479
16749
|
}
|
|
16480
|
-
yield*
|
|
16481
|
-
|
|
16750
|
+
yield* printFooter({
|
|
16751
|
+
diagnostics: [...surfaceDiagnostics],
|
|
16752
|
+
scoreResult: score,
|
|
16753
|
+
projectName: project.projectName,
|
|
16754
|
+
isOffline: !shouldShowShareLink
|
|
16755
|
+
});
|
|
16482
16756
|
return buildResult();
|
|
16483
16757
|
});
|
|
16484
16758
|
//#endregion
|
|
@@ -16589,6 +16863,21 @@ const handleError = (error, options = {}) => {
|
|
|
16589
16863
|
if (options.shouldExit !== false) process.exit(1);
|
|
16590
16864
|
process.exitCode = 1;
|
|
16591
16865
|
};
|
|
16866
|
+
/**
|
|
16867
|
+
* Renderer for expected, user-actionable failures — a bad `--diff` value or
|
|
16868
|
+
* a base branch that isn't fetched. Prints just the (already human-readable)
|
|
16869
|
+
* message — no "Something went wrong", prefilled issue, Discord link, or
|
|
16870
|
+
* Sentry reference — because there is no bug to report.
|
|
16871
|
+
*/
|
|
16872
|
+
const handleUserError = (error, options = {}) => {
|
|
16873
|
+
Effect.runSync(Effect.gen(function* () {
|
|
16874
|
+
yield* Console.error("");
|
|
16875
|
+
yield* Console.error(highlighter.error(formatErrorForReport(error)));
|
|
16876
|
+
yield* Console.error("");
|
|
16877
|
+
}));
|
|
16878
|
+
if (options.shouldExit !== false) process.exit(1);
|
|
16879
|
+
process.exitCode = 1;
|
|
16880
|
+
};
|
|
16592
16881
|
//#endregion
|
|
16593
16882
|
//#region src/cli/utils/build-handoff-payload.ts
|
|
16594
16883
|
const buildHandoffPayload = (input) => {
|
|
@@ -17597,11 +17886,17 @@ const installReactDoctorPackageSetup = async (projectRoot, dependencyRunner) =>
|
|
|
17597
17886
|
projectRoot,
|
|
17598
17887
|
runner: dependencyRunner
|
|
17599
17888
|
});
|
|
17889
|
+
recordCount(METRIC.installDependency, 1, {
|
|
17890
|
+
status: dependencyResult.dependencyStatus,
|
|
17891
|
+
reason: dependencyResult.dependencyReason ?? null,
|
|
17892
|
+
packageManager: detectPackageManager(projectRoot)
|
|
17893
|
+
});
|
|
17600
17894
|
if (dependencyResult.dependencyStatus === "skipped") {
|
|
17601
17895
|
dependencySpinner.fail(formatDependencyInstallMessage(dependencyResult));
|
|
17602
|
-
return;
|
|
17896
|
+
return dependencyResult;
|
|
17603
17897
|
}
|
|
17604
17898
|
dependencySpinner.succeed(formatDependencyInstallMessage(dependencyResult));
|
|
17899
|
+
return dependencyResult;
|
|
17605
17900
|
} catch (error) {
|
|
17606
17901
|
dependencySpinner.fail("Failed to install React Doctor package.");
|
|
17607
17902
|
throw error;
|
|
@@ -17769,7 +18064,7 @@ const runInstallReactDoctor = async (options = {}) => {
|
|
|
17769
18064
|
} catch {
|
|
17770
18065
|
cliLogger.dim(" Skipped bundled sibling skills (install error).");
|
|
17771
18066
|
}
|
|
17772
|
-
await installReactDoctorPackageSetup(projectRoot, options.installDependencyRunner);
|
|
18067
|
+
const dependencyResult = await installReactDoctorPackageSetup(projectRoot, options.installDependencyRunner);
|
|
17773
18068
|
if (shouldInstallGitHook && gitHookTarget !== null && gitHookTarget !== void 0) {
|
|
17774
18069
|
const hookSpinner = spinner("Installing React Doctor pre-commit hook...").start();
|
|
17775
18070
|
try {
|
|
@@ -17780,6 +18075,7 @@ const runInstallReactDoctor = async (options = {}) => {
|
|
|
17780
18075
|
hooksPathConfig: gitHookTarget.hooksPathConfig
|
|
17781
18076
|
});
|
|
17782
18077
|
hookSpinner.succeed(formatGitHookInstallMessage(hookResult));
|
|
18078
|
+
recordCount(METRIC.installGitHook, 1, { kind: hookResult.kind });
|
|
17783
18079
|
} catch (error) {
|
|
17784
18080
|
hookSpinner.fail("Failed to install React Doctor pre-commit hook.");
|
|
17785
18081
|
throw error;
|
|
@@ -17793,7 +18089,10 @@ const runInstallReactDoctor = async (options = {}) => {
|
|
|
17793
18089
|
agents: selectedAgents
|
|
17794
18090
|
});
|
|
17795
18091
|
if (hookResult.installedAgents.length === 0) hookSpinner.succeed("No supported native agent hook targets selected.");
|
|
17796
|
-
else
|
|
18092
|
+
else {
|
|
18093
|
+
hookSpinner.succeed(`React Doctor agent hooks installed for ${hookResult.installedAgents.map((agent) => getSkillAgentConfig(agent).displayName).join(", ")}.`);
|
|
18094
|
+
recordCount(METRIC.installAgentHooks, 1, { agentsCount: hookResult.installedAgents.length });
|
|
18095
|
+
}
|
|
17797
18096
|
} catch (error) {
|
|
17798
18097
|
hookSpinner.fail("Failed to install React Doctor agent hooks.");
|
|
17799
18098
|
throw error;
|
|
@@ -17805,11 +18104,21 @@ const runInstallReactDoctor = async (options = {}) => {
|
|
|
17805
18104
|
try {
|
|
17806
18105
|
writeFileSync(workflowTargetPath, buildWorkflowContent());
|
|
17807
18106
|
workflowSpinner.succeed(`GitHub Actions workflow added at ${path.relative(projectRoot, workflowTargetPath)}.`);
|
|
18107
|
+
recordCount(METRIC.installWorkflow, 1);
|
|
17808
18108
|
} catch (error) {
|
|
17809
18109
|
workflowSpinner.fail("Failed to add GitHub Actions workflow.");
|
|
17810
18110
|
throw error;
|
|
17811
18111
|
}
|
|
17812
18112
|
}
|
|
18113
|
+
recordCount(METRIC.installCompleted, 1, {
|
|
18114
|
+
agentsCount: selectedAgents.length,
|
|
18115
|
+
gitHook: shouldInstallGitHook,
|
|
18116
|
+
agentHooks: shouldInstallAgentHooks,
|
|
18117
|
+
workflow: shouldInstallWorkflow,
|
|
18118
|
+
dependencyStatus: dependencyResult.dependencyStatus,
|
|
18119
|
+
packageManager: detectPackageManager(projectRoot)
|
|
18120
|
+
});
|
|
18121
|
+
for (const agent of selectedAgents) recordCount(METRIC.installAgent, 1, { agent });
|
|
17813
18122
|
};
|
|
17814
18123
|
//#endregion
|
|
17815
18124
|
//#region src/cli/utils/install-skill-for-agent.ts
|
|
@@ -17894,6 +18203,7 @@ const detectLaunchableAgents = async () => {
|
|
|
17894
18203
|
};
|
|
17895
18204
|
const handoffToAgent = async (input) => {
|
|
17896
18205
|
if (!input.interactive || input.diagnostics.length === 0) return;
|
|
18206
|
+
cliLogger.break();
|
|
17897
18207
|
const { handoffTarget } = await prompts({
|
|
17898
18208
|
type: "select",
|
|
17899
18209
|
name: "handoffTarget",
|
|
@@ -17922,6 +18232,16 @@ const handoffToAgent = async (input) => {
|
|
|
17922
18232
|
],
|
|
17923
18233
|
initial: 0
|
|
17924
18234
|
}, { onCancel: () => true });
|
|
18235
|
+
let handoffOutcome = "launch";
|
|
18236
|
+
if (handoffTarget === void 0) handoffOutcome = "cancel";
|
|
18237
|
+
else if (handoffTarget === SKIP_CHOICE) handoffOutcome = "skip";
|
|
18238
|
+
else if (handoffTarget === PRINT_CHOICE) handoffOutcome = "print";
|
|
18239
|
+
else if (handoffTarget === CLIPBOARD_CHOICE) handoffOutcome = "clipboard";
|
|
18240
|
+
recordCount(METRIC.agentHandoff, 1, {
|
|
18241
|
+
outcome: handoffOutcome,
|
|
18242
|
+
agent: handoffOutcome === "launch" ? handoffTarget : void 0,
|
|
18243
|
+
diagnosticsCount: input.diagnostics.length
|
|
18244
|
+
});
|
|
17925
18245
|
if (handoffTarget === void 0 || handoffTarget === SKIP_CHOICE) return;
|
|
17926
18246
|
const payload = buildHandoffPayload({
|
|
17927
18247
|
diagnostics: input.diagnostics,
|
|
@@ -18067,6 +18387,13 @@ const reportErrorToSentry = async (error) => {
|
|
|
18067
18387
|
if (!Sentry.isInitialized()) return void 0;
|
|
18068
18388
|
try {
|
|
18069
18389
|
const { tags, contexts } = buildSentryScope();
|
|
18390
|
+
let reason = "unknown";
|
|
18391
|
+
if (isReactDoctorError(error)) reason = error.reason._tag;
|
|
18392
|
+
else if (error instanceof Error) reason = error.name;
|
|
18393
|
+
recordCount(METRIC.cliError, 1, {
|
|
18394
|
+
command: typeof tags.command === "string" ? tags.command : void 0,
|
|
18395
|
+
reason
|
|
18396
|
+
});
|
|
18070
18397
|
const runTrace = getActiveRunTrace();
|
|
18071
18398
|
const eventId = Sentry.withScope((scope) => {
|
|
18072
18399
|
for (const [name, context] of Object.entries(contexts)) scope.setContext(name, context);
|
|
@@ -18136,7 +18463,7 @@ const findLowestScoredScan = (completedScans) => {
|
|
|
18136
18463
|
return scoredScans.reduce((worst, scan) => scan.result.score.score < worst.result.score.score ? scan : worst);
|
|
18137
18464
|
};
|
|
18138
18465
|
const printMultiProjectSummary = (input) => Effect.gen(function* () {
|
|
18139
|
-
const { completedScans, userConfig, verbose } = input;
|
|
18466
|
+
const { completedScans, userConfig, verbose, isOffline, projectName } = input;
|
|
18140
18467
|
const surfaceDiagnostics = filterDiagnosticsForSurface(completedScans.flatMap((scan) => scan.result.diagnostics), "cli", userConfig);
|
|
18141
18468
|
const projectRootByDiagnostic = /* @__PURE__ */ new WeakMap();
|
|
18142
18469
|
for (const scan of completedScans) for (const diagnostic of scan.result.diagnostics) projectRootByDiagnostic.set(diagnostic, scan.result.project.rootDirectory);
|
|
@@ -18163,10 +18490,8 @@ const printMultiProjectSummary = (input) => Effect.gen(function* () {
|
|
|
18163
18490
|
elapsedMilliseconds: completedScans.reduce((sum, scan) => sum + scan.result.elapsedMilliseconds, 0),
|
|
18164
18491
|
scoreResult: aggregateScore,
|
|
18165
18492
|
potentialScore: lowestScoredScan ? yield* Effect.promise(() => computeProjectedScore(surfaceDiagnostics, lowestScoredScan.result.diagnostics, lowestScoredScan.result.score)) : null,
|
|
18166
|
-
projectName: completedScans.map((scan) => scan.result.project.projectName).join(", "),
|
|
18167
18493
|
totalSourceFileCount,
|
|
18168
18494
|
noScoreMessage: "Score unavailable.",
|
|
18169
|
-
isOffline: true,
|
|
18170
18495
|
verbose
|
|
18171
18496
|
});
|
|
18172
18497
|
const entries = completedScans.map((scan) => {
|
|
@@ -18181,9 +18506,12 @@ const printMultiProjectSummary = (input) => Effect.gen(function* () {
|
|
|
18181
18506
|
const longestProjectNameLength = Math.max(...entries.map((entry) => entry.projectName.length));
|
|
18182
18507
|
yield* Console.log("");
|
|
18183
18508
|
for (const entry of entries) yield* Console.log(buildSummaryLine(entry, longestProjectNameLength));
|
|
18184
|
-
yield*
|
|
18185
|
-
|
|
18186
|
-
|
|
18509
|
+
yield* printFooter({
|
|
18510
|
+
diagnostics: surfaceDiagnostics,
|
|
18511
|
+
scoreResult: aggregateScore,
|
|
18512
|
+
projectName,
|
|
18513
|
+
isOffline
|
|
18514
|
+
});
|
|
18187
18515
|
});
|
|
18188
18516
|
//#endregion
|
|
18189
18517
|
//#region src/cli/utils/prompt-install-setup.ts
|
|
@@ -18233,31 +18561,13 @@ const printAgentInstallHint = (writeLine = defaultWriteLine) => {
|
|
|
18233
18561
|
//#endregion
|
|
18234
18562
|
//#region src/cli/utils/resolve-parallel-flag.ts
|
|
18235
18563
|
/**
|
|
18236
|
-
*
|
|
18237
|
-
*
|
|
18238
|
-
*
|
|
18239
|
-
*
|
|
18240
|
-
*
|
|
18241
|
-
* - bare flag / `auto` → auto-detect CPU cores
|
|
18242
|
-
* - `--experimental-parallel <n>` → `n` workers (clamped)
|
|
18243
|
-
* - `false` / `off` / `0` → serial (an explicit opt-out, so
|
|
18244
|
-
* it overrides an env-enabled default rather than deferring to it)
|
|
18245
|
-
* - an unparseable value → auto-detect cores
|
|
18246
|
-
*
|
|
18247
|
-
* Commander yields `true` for a bare flag, the raw string for an explicit
|
|
18248
|
-
* value, and `undefined` when the flag is omitted.
|
|
18564
|
+
* Maps the `--no-parallel` flag to an `InspectOptions.concurrency` value.
|
|
18565
|
+
* `--no-parallel` (`parallel === false`) pins serial, overriding any
|
|
18566
|
+
* env-enabled default; otherwise `undefined` defers to the ambient
|
|
18567
|
+
* `OxlintConcurrency` default (parallel, unless `REACT_DOCTOR_PARALLEL`
|
|
18568
|
+
* sets a worker count — the flag itself no longer takes one).
|
|
18249
18569
|
*/
|
|
18250
|
-
const resolveParallelFlag = (parallel) =>
|
|
18251
|
-
if (parallel === void 0) return void 0;
|
|
18252
|
-
if (parallel === true) return resolveScanConcurrency("auto");
|
|
18253
|
-
if (parallel === false) return 1;
|
|
18254
|
-
const normalized = parallel.trim().toLowerCase();
|
|
18255
|
-
if (normalized === "" || normalized === "auto" || normalized === "true") return resolveScanConcurrency("auto");
|
|
18256
|
-
if (normalized === "false" || normalized === "off" || normalized === "0") return 1;
|
|
18257
|
-
const parsed = Number.parseInt(normalized, 10);
|
|
18258
|
-
if (!Number.isInteger(parsed) || parsed <= 0) return resolveScanConcurrency("auto");
|
|
18259
|
-
return resolveScanConcurrency(parsed);
|
|
18260
|
-
};
|
|
18570
|
+
const resolveParallelFlag = (parallel) => parallel === false ? 1 : void 0;
|
|
18261
18571
|
//#endregion
|
|
18262
18572
|
//#region src/cli/utils/resolve-cli-inspect-options.ts
|
|
18263
18573
|
/**
|
|
@@ -18285,7 +18595,7 @@ const resolveCliInspectOptions = (flags, userConfig) => {
|
|
|
18285
18595
|
isCi: isCiEnvironment(),
|
|
18286
18596
|
silent: Boolean(flags.json),
|
|
18287
18597
|
outputSurface: flags.prComment ? "prComment" : "cli",
|
|
18288
|
-
concurrency: resolveParallelFlag(flags.
|
|
18598
|
+
concurrency: resolveParallelFlag(flags.parallel)
|
|
18289
18599
|
};
|
|
18290
18600
|
};
|
|
18291
18601
|
//#endregion
|
|
@@ -18612,6 +18922,7 @@ const inspectAction = async (directory, flags) => {
|
|
|
18612
18922
|
compact: Boolean(flags.jsonCompact),
|
|
18613
18923
|
directory: requestedDirectory
|
|
18614
18924
|
});
|
|
18925
|
+
recordCount(METRIC.cliInvoked, 1, { command: "inspect" });
|
|
18615
18926
|
try {
|
|
18616
18927
|
validateModeFlags(flags);
|
|
18617
18928
|
maybeMigrateLegacyConfig(requestedDirectory, {
|
|
@@ -18751,11 +19062,16 @@ const inspectAction = async (directory, flags) => {
|
|
|
18751
19062
|
});
|
|
18752
19063
|
if (!isQuiet && !isMultiProject) cliLogger.break();
|
|
18753
19064
|
}
|
|
18754
|
-
if (!isQuiet && isMultiProject && completedScans.length > 0)
|
|
18755
|
-
|
|
18756
|
-
|
|
18757
|
-
|
|
18758
|
-
|
|
19065
|
+
if (!isQuiet && isMultiProject && completedScans.length > 0) {
|
|
19066
|
+
const shouldShowShareLink = !scanOptions.noScore && (userConfig?.share ?? true) && !scanOptions.isCi;
|
|
19067
|
+
await Effect.runPromise(printMultiProjectSummary({
|
|
19068
|
+
completedScans,
|
|
19069
|
+
userConfig,
|
|
19070
|
+
verbose: Boolean(flags.verbose),
|
|
19071
|
+
isOffline: !shouldShowShareLink,
|
|
19072
|
+
projectName: path.basename(resolvedDirectory)
|
|
19073
|
+
}));
|
|
19074
|
+
}
|
|
18759
19075
|
finalizeScans({
|
|
18760
19076
|
diagnostics: allDiagnostics,
|
|
18761
19077
|
completedScans,
|
|
@@ -18789,21 +19105,30 @@ const inspectAction = async (directory, flags) => {
|
|
|
18789
19105
|
isJsonMode,
|
|
18790
19106
|
isScoreOnly,
|
|
18791
19107
|
isStaged: Boolean(flags.staged)
|
|
18792
|
-
}))
|
|
19108
|
+
})) {
|
|
19109
|
+
printAgentInstallHint();
|
|
19110
|
+
recordCount(METRIC.agentInstallHintShown, 1);
|
|
19111
|
+
}
|
|
18793
19112
|
}
|
|
18794
19113
|
} catch (error) {
|
|
18795
|
-
const
|
|
19114
|
+
const isUserError = isReactDoctorError(error) && (error.reason._tag === "GitBaseBranchInvalid" || error.reason._tag === "GitBaseBranchMissing");
|
|
19115
|
+
const sentryEventId = isUserError ? void 0 : await reportErrorToSentry(error);
|
|
18796
19116
|
if (isJsonMode) {
|
|
18797
19117
|
writeJsonErrorReport(error);
|
|
18798
19118
|
process.exitCode = 1;
|
|
18799
19119
|
return;
|
|
18800
19120
|
}
|
|
19121
|
+
if (isUserError) {
|
|
19122
|
+
handleUserError(error);
|
|
19123
|
+
return;
|
|
19124
|
+
}
|
|
18801
19125
|
handleError(error, { sentryEventId });
|
|
18802
19126
|
}
|
|
18803
19127
|
};
|
|
18804
19128
|
//#endregion
|
|
18805
19129
|
//#region src/cli/commands/install.ts
|
|
18806
19130
|
const installAction = async (options, command) => {
|
|
19131
|
+
recordCount(METRIC.cliInvoked, 1, { command: "install" });
|
|
18807
19132
|
Effect.runSync(printBrandedHeader);
|
|
18808
19133
|
try {
|
|
18809
19134
|
const parentOptions = command?.parent?.opts?.();
|
|
@@ -19124,6 +19449,7 @@ const SEVERITY_VALUES = [
|
|
|
19124
19449
|
"warn",
|
|
19125
19450
|
"error"
|
|
19126
19451
|
];
|
|
19452
|
+
const recordRulesInvocation = () => recordCount(METRIC.cliInvoked, 1, { command: "rules" });
|
|
19127
19453
|
const resolveProjectRoot = (options) => {
|
|
19128
19454
|
const requestedDirectory = path.resolve(options.cwd ?? process.cwd());
|
|
19129
19455
|
return findNearestPackageDirectory(requestedDirectory) ?? requestedDirectory;
|
|
@@ -19166,6 +19492,11 @@ const reportManualEdit = (target, nextConfig) => {
|
|
|
19166
19492
|
process.exitCode = 1;
|
|
19167
19493
|
};
|
|
19168
19494
|
const rulesListAction = async (options) => {
|
|
19495
|
+
recordRulesInvocation();
|
|
19496
|
+
recordCount(METRIC.rulesQueried, 1, {
|
|
19497
|
+
subcommand: "list",
|
|
19498
|
+
hadFilter: Boolean(options.category || options.tag || options.framework || options.configured)
|
|
19499
|
+
});
|
|
19169
19500
|
const catalog = buildRuleCatalog();
|
|
19170
19501
|
const config = validateConfigTypes((await resolveRuleConfigTarget(resolveProjectRoot(options))).config);
|
|
19171
19502
|
const categoryFilter = options.category?.toLowerCase();
|
|
@@ -19197,6 +19528,8 @@ const rulesListAction = async (options) => {
|
|
|
19197
19528
|
cliLogger.log(renderRuleCatalog(rows));
|
|
19198
19529
|
};
|
|
19199
19530
|
const rulesExplainAction = async (ruleQuery, options) => {
|
|
19531
|
+
recordRulesInvocation();
|
|
19532
|
+
recordCount(METRIC.rulesQueried, 1, { subcommand: "explain" });
|
|
19200
19533
|
const entry = findRuleInCatalog(buildRuleCatalog(), ruleQuery);
|
|
19201
19534
|
if (!entry) {
|
|
19202
19535
|
reportRuleNotFound(ruleQuery);
|
|
@@ -19224,7 +19557,7 @@ const rulesExplainAction = async (ruleQuery, options) => {
|
|
|
19224
19557
|
effective
|
|
19225
19558
|
}));
|
|
19226
19559
|
};
|
|
19227
|
-
const setRuleSeverityAndReport = async (entry, severity, options) => {
|
|
19560
|
+
const setRuleSeverityAndReport = async (entry, severity, options, action) => {
|
|
19228
19561
|
const { target, nextConfig, written } = await applyConfigChange(options, (config) => setRuleSeverity(config, entry.key, severity));
|
|
19229
19562
|
if (!written) {
|
|
19230
19563
|
reportManualEdit(target, nextConfig);
|
|
@@ -19232,8 +19565,14 @@ const setRuleSeverityAndReport = async (entry, severity, options) => {
|
|
|
19232
19565
|
}
|
|
19233
19566
|
cliLogger.success(`Set ${entry.key} → ${severity}`);
|
|
19234
19567
|
cliLogger.dim(` Updated ${describeTargetPath(target)}`);
|
|
19568
|
+
recordCount(METRIC.rulesChanged, 1, {
|
|
19569
|
+
action,
|
|
19570
|
+
severity,
|
|
19571
|
+
target: entry.key
|
|
19572
|
+
});
|
|
19235
19573
|
};
|
|
19236
19574
|
const rulesSetAction = async (ruleQuery, severityValue, options) => {
|
|
19575
|
+
recordRulesInvocation();
|
|
19237
19576
|
const severity = parseSeverity(severityValue);
|
|
19238
19577
|
if (!severity) {
|
|
19239
19578
|
reportInvalidSeverity(severityValue);
|
|
@@ -19244,16 +19583,17 @@ const rulesSetAction = async (ruleQuery, severityValue, options) => {
|
|
|
19244
19583
|
reportRuleNotFound(ruleQuery);
|
|
19245
19584
|
return;
|
|
19246
19585
|
}
|
|
19247
|
-
await setRuleSeverityAndReport(entry, severity, options);
|
|
19586
|
+
await setRuleSeverityAndReport(entry, severity, options, "set");
|
|
19248
19587
|
};
|
|
19249
19588
|
const rulesEnableAction = async (ruleQuery, options) => {
|
|
19589
|
+
recordRulesInvocation();
|
|
19250
19590
|
const entry = findRuleInCatalog(buildRuleCatalog(), ruleQuery);
|
|
19251
19591
|
if (!entry) {
|
|
19252
19592
|
reportRuleNotFound(ruleQuery);
|
|
19253
19593
|
return;
|
|
19254
19594
|
}
|
|
19255
19595
|
if (options.severity === void 0) {
|
|
19256
|
-
await setRuleSeverityAndReport(entry, entry.defaultSeverity, options);
|
|
19596
|
+
await setRuleSeverityAndReport(entry, entry.defaultSeverity, options, "enable");
|
|
19257
19597
|
return;
|
|
19258
19598
|
}
|
|
19259
19599
|
const severity = parseSeverity(options.severity);
|
|
@@ -19266,17 +19606,19 @@ const rulesEnableAction = async (ruleQuery, options) => {
|
|
|
19266
19606
|
process.exitCode = 1;
|
|
19267
19607
|
return;
|
|
19268
19608
|
}
|
|
19269
|
-
await setRuleSeverityAndReport(entry, severity, options);
|
|
19609
|
+
await setRuleSeverityAndReport(entry, severity, options, "enable");
|
|
19270
19610
|
};
|
|
19271
19611
|
const rulesDisableAction = async (ruleQuery, options) => {
|
|
19612
|
+
recordRulesInvocation();
|
|
19272
19613
|
const entry = findRuleInCatalog(buildRuleCatalog(), ruleQuery);
|
|
19273
19614
|
if (!entry) {
|
|
19274
19615
|
reportRuleNotFound(ruleQuery);
|
|
19275
19616
|
return;
|
|
19276
19617
|
}
|
|
19277
|
-
await setRuleSeverityAndReport(entry, "off", options);
|
|
19618
|
+
await setRuleSeverityAndReport(entry, "off", options, "disable");
|
|
19278
19619
|
};
|
|
19279
19620
|
const rulesCategoryAction = async (categoryQuery, severityValue, options) => {
|
|
19621
|
+
recordRulesInvocation();
|
|
19280
19622
|
const severity = parseSeverity(severityValue);
|
|
19281
19623
|
if (!severity) {
|
|
19282
19624
|
reportInvalidSeverity(severityValue);
|
|
@@ -19297,8 +19639,14 @@ const rulesCategoryAction = async (categoryQuery, severityValue, options) => {
|
|
|
19297
19639
|
}
|
|
19298
19640
|
cliLogger.success(`Set category "${matchedCategory}" → ${severity}`);
|
|
19299
19641
|
cliLogger.dim(` Updated ${describeTargetPath(target)}`);
|
|
19642
|
+
recordCount(METRIC.rulesChanged, 1, {
|
|
19643
|
+
action: "category",
|
|
19644
|
+
severity,
|
|
19645
|
+
target: matchedCategory
|
|
19646
|
+
});
|
|
19300
19647
|
};
|
|
19301
19648
|
const rulesIgnoreTagAction = async (tag, options) => {
|
|
19649
|
+
recordRulesInvocation();
|
|
19302
19650
|
const knownTags = listRuleTags(buildRuleCatalog());
|
|
19303
19651
|
if (!knownTags.includes(tag)) {
|
|
19304
19652
|
cliLogger.error(`Unknown tag "${tag}".`);
|
|
@@ -19313,8 +19661,13 @@ const rulesIgnoreTagAction = async (tag, options) => {
|
|
|
19313
19661
|
}
|
|
19314
19662
|
cliLogger.success(`Ignoring tag "${tag}" (rules with this tag are skipped before linting)`);
|
|
19315
19663
|
cliLogger.dim(` Updated ${describeTargetPath(target)}`);
|
|
19664
|
+
recordCount(METRIC.rulesChanged, 1, {
|
|
19665
|
+
action: "ignoreTag",
|
|
19666
|
+
target: tag
|
|
19667
|
+
});
|
|
19316
19668
|
};
|
|
19317
19669
|
const rulesUnignoreTagAction = async (tag, options) => {
|
|
19670
|
+
recordRulesInvocation();
|
|
19318
19671
|
const target = await resolveRuleConfigTarget(resolveProjectRoot(options));
|
|
19319
19672
|
if (!(target.config.ignore?.tags ?? []).includes(tag)) {
|
|
19320
19673
|
cliLogger.dim(`Tag "${tag}" was not being ignored; nothing to change.`);
|
|
@@ -19328,6 +19681,10 @@ const rulesUnignoreTagAction = async (tag, options) => {
|
|
|
19328
19681
|
}
|
|
19329
19682
|
cliLogger.success(`Tag "${tag}" is no longer ignored`);
|
|
19330
19683
|
cliLogger.dim(` Updated ${describeTargetPath(target)}`);
|
|
19684
|
+
recordCount(METRIC.rulesChanged, 1, {
|
|
19685
|
+
action: "unignoreTag",
|
|
19686
|
+
target: tag
|
|
19687
|
+
});
|
|
19331
19688
|
};
|
|
19332
19689
|
//#endregion
|
|
19333
19690
|
//#region src/cli/commands/version.ts
|
|
@@ -19340,6 +19697,7 @@ const rulesUnignoreTagAction = async (tag, options) => {
|
|
|
19340
19697
|
*/
|
|
19341
19698
|
const buildVersionString = () => `react-doctor/${VERSION} ${process.platform}-${process.arch} node-${process.version}`;
|
|
19342
19699
|
const versionAction = () => {
|
|
19700
|
+
recordCount(METRIC.cliInvoked, 1, { command: "version" });
|
|
19343
19701
|
process.stdout.write(`${buildVersionString()}\n`);
|
|
19344
19702
|
};
|
|
19345
19703
|
//#endregion
|
|
@@ -19434,6 +19792,7 @@ const ROOT_FLAG_SPEC = {
|
|
|
19434
19792
|
"--no-color",
|
|
19435
19793
|
"--no-dead-code",
|
|
19436
19794
|
"--no-lint",
|
|
19795
|
+
"--no-parallel",
|
|
19437
19796
|
"--no-respect-inline-disables",
|
|
19438
19797
|
"--no-score",
|
|
19439
19798
|
"--no-telemetry",
|
|
@@ -19454,7 +19813,7 @@ const ROOT_FLAG_SPEC = {
|
|
|
19454
19813
|
"--project",
|
|
19455
19814
|
"--why"
|
|
19456
19815
|
]),
|
|
19457
|
-
longOptionsWithOptionalValues: new Set(["--diff"
|
|
19816
|
+
longOptionsWithOptionalValues: new Set(["--diff"]),
|
|
19458
19817
|
shortOptionsWithoutValues: new Set([
|
|
19459
19818
|
"-h",
|
|
19460
19819
|
"-v",
|
|
@@ -19621,7 +19980,7 @@ ${formatExampleLines([
|
|
|
19621
19980
|
${highlighter.dim("Learn more:")}
|
|
19622
19981
|
${highlighter.info(CANONICAL_GITHUB_URL)}
|
|
19623
19982
|
`;
|
|
19624
|
-
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("--full", "force a full scan (overrides any `diff` value in config or `--diff`)").option("--
|
|
19983
|
+
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("--full", "force a full scan (overrides any `diff` value in config or `--diff`)").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 disable; overridden by --full)").option("--changed-files-from <file>", "internal: scan source files listed in a newline-delimited changed-files file").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("--fail-on <level>", "exit with error code on diagnostics: error, warning, none (default: none)").option("--annotations", "output diagnostics as GitHub Actions annotations").option("--pr-comment", "tune CLI output for sticky PR comments (drops weak-signal rule families like `design` from the printed list and the fail-on gate; configure via config.surfaces)").option("--explain <file:line>", "diagnose why a rule fired or why a suppression didn't apply at a specific location").option("--why <file:line>", "alias for --explain").option("--respect-inline-disables", "respect inline `// eslint-disable*` / `// oxlint-disable*` comments (default)").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);
|
|
19625
19984
|
program.action(inspectAction);
|
|
19626
19985
|
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);
|
|
19627
19986
|
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);
|
|
@@ -19657,4 +20016,4 @@ program.parseAsync(argv).then(() => flushSentry()).catch(async (error) => {
|
|
|
19657
20016
|
export {};
|
|
19658
20017
|
|
|
19659
20018
|
//# sourceMappingURL=cli.js.map
|
|
19660
|
-
//# debugId=
|
|
20019
|
+
//# debugId=7cd8f7c3-d243-5c1a-9ebb-98a50f4157a1
|