react-doctor 0.4.2-dev.829655c → 0.4.2-dev.93d4eec
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +737 -179
- package/dist/index.d.ts +11 -0
- package/dist/index.js +264 -82
- package/dist/lsp.js +308 -130
- package/package.json +2 -2
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]="299ab690-e278-5f22-b581-ff28a76a28b8")}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";
|
|
@@ -8,6 +8,7 @@ import * as fs$1 from "node:fs";
|
|
|
8
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
|
+
import * as ts from "typescript";
|
|
11
12
|
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";
|
|
12
13
|
import * as Cause from "effect/Cause";
|
|
13
14
|
import * as Effect from "effect/Effect";
|
|
@@ -32,9 +33,8 @@ import * as NodeFileSystem from "@effect/platform-node-shared/NodeFileSystem";
|
|
|
32
33
|
import * as NodePath from "@effect/platform-node-shared/NodePath";
|
|
33
34
|
import * as ChildProcess from "effect/unstable/process/ChildProcess";
|
|
34
35
|
import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner";
|
|
35
|
-
import * as ts from "typescript";
|
|
36
36
|
import { gzipSync } from "node:zlib";
|
|
37
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
37
|
+
import crypto, { createHash, randomUUID } from "node:crypto";
|
|
38
38
|
import * as Exit from "effect/Exit";
|
|
39
39
|
import * as Sentry from "@sentry/node";
|
|
40
40
|
import { performance } from "node:perf_hooks";
|
|
@@ -5151,8 +5151,8 @@ const isFile = (filePath) => {
|
|
|
5151
5151
|
return false;
|
|
5152
5152
|
}
|
|
5153
5153
|
};
|
|
5154
|
-
const SOURCE_FILE_PATTERN = /\.(tsx?|jsx
|
|
5155
|
-
const GENERATED_BUNDLE_FILE_PATTERN = /\.(iife|umd|global|min)\.js$/i;
|
|
5154
|
+
const SOURCE_FILE_PATTERN = /\.(tsx?|jsx?|mts|mjs)$/;
|
|
5155
|
+
const GENERATED_BUNDLE_FILE_PATTERN = /\.(iife|umd|global|min)\.m?js$/i;
|
|
5156
5156
|
const MINIFIED_SNIFF_BYTES = 65536;
|
|
5157
5157
|
const GIT_LS_FILES_MAX_BUFFER_BYTES = 50 * 1024 * 1024;
|
|
5158
5158
|
const IGNORED_DIRECTORIES = new Set([
|
|
@@ -6064,6 +6064,204 @@ const resolveEffectiveReactMajor = (reactVersion, packageJson) => {
|
|
|
6064
6064
|
if (peerFloor === null) return hasUpperBoundOnlyPeerRange(peerReactRange) ? null : installedReactMajor;
|
|
6065
6065
|
return installedReactMajor !== null ? Math.min(installedReactMajor, peerFloor) : peerFloor;
|
|
6066
6066
|
};
|
|
6067
|
+
const JSX_FILE_PATTERN = /\.(tsx|jsx)$/;
|
|
6068
|
+
const MILLISECONDS_PER_SECOND = 1e3;
|
|
6069
|
+
const SCORE_API_URL = "https://www.react.doctor/api/score";
|
|
6070
|
+
const ENTERPRISE_CONTACT_URL = "https://react.doctor/enterprise";
|
|
6071
|
+
const SHARE_BASE_URL = "https://react.doctor/share";
|
|
6072
|
+
const CI_URL = "https://react.doctor/ci";
|
|
6073
|
+
const GITHUB_ACTIONS_SETUP_URL = "https://www.react.doctor/docs/ci-and-prs/github-actions-setup";
|
|
6074
|
+
const DOCS_URL = "https://react.doctor/docs";
|
|
6075
|
+
const DOCS_RULES_BASE_URL = `${DOCS_URL}/rules`;
|
|
6076
|
+
const FETCH_TIMEOUT_MS = 1e4;
|
|
6077
|
+
const GITHUB_VIEWER_PERMISSION_TIMEOUT_MS = 2e3;
|
|
6078
|
+
const DEFAULT_BRANCH_CANDIDATES = ["main", "master"];
|
|
6079
|
+
const ADOPTABLE_LINT_CONFIG_FILENAMES = [".oxlintrc.json", ".eslintrc.json"];
|
|
6080
|
+
const OXLINT_NODE_REQUIREMENT = "^20.19.0 || >=22.12.0";
|
|
6081
|
+
const GIT_SHOW_MAX_BUFFER_BYTES = 10 * 1024 * 1024;
|
|
6082
|
+
const ES_TARGET_YEAR_BY_NAME = {
|
|
6083
|
+
es3: 1999,
|
|
6084
|
+
es5: 2009,
|
|
6085
|
+
es6: 2015,
|
|
6086
|
+
es2015: 2015,
|
|
6087
|
+
es2016: 2016,
|
|
6088
|
+
es2017: 2017,
|
|
6089
|
+
es2018: 2018,
|
|
6090
|
+
es2019: 2019,
|
|
6091
|
+
es2020: 2020,
|
|
6092
|
+
es2021: 2021,
|
|
6093
|
+
es2022: 2022,
|
|
6094
|
+
es2023: 2023,
|
|
6095
|
+
es2024: 2024,
|
|
6096
|
+
es2025: 2025,
|
|
6097
|
+
esnext: 9999
|
|
6098
|
+
};
|
|
6099
|
+
/**
|
|
6100
|
+
* Project-config files that `StagedFiles.materialize` copies into
|
|
6101
|
+
* the temp directory alongside staged sources so oxlint resolves
|
|
6102
|
+
* `tsconfig` / `package.json` / lint configs the same way it would
|
|
6103
|
+
* in the working tree. Hoisted out of the staged-files helper so
|
|
6104
|
+
* the constant lives next to the rest of the IO budget knobs.
|
|
6105
|
+
*/
|
|
6106
|
+
const STAGED_FILES_PROJECT_CONFIG_FILENAMES = [
|
|
6107
|
+
"tsconfig.json",
|
|
6108
|
+
"tsconfig.base.json",
|
|
6109
|
+
"package.json",
|
|
6110
|
+
"doctor.config.ts",
|
|
6111
|
+
"doctor.config.mts",
|
|
6112
|
+
"doctor.config.cts",
|
|
6113
|
+
"doctor.config.js",
|
|
6114
|
+
"doctor.config.mjs",
|
|
6115
|
+
"doctor.config.cjs",
|
|
6116
|
+
"doctor.config.json",
|
|
6117
|
+
"doctor.config.jsonc",
|
|
6118
|
+
"oxlint.json",
|
|
6119
|
+
".oxlintrc.json"
|
|
6120
|
+
];
|
|
6121
|
+
const CONFIG_FINGERPRINT_FILENAMES = [
|
|
6122
|
+
"doctor.config.ts",
|
|
6123
|
+
"doctor.config.mts",
|
|
6124
|
+
"doctor.config.cts",
|
|
6125
|
+
"doctor.config.js",
|
|
6126
|
+
"doctor.config.mjs",
|
|
6127
|
+
"doctor.config.cjs",
|
|
6128
|
+
"doctor.config.json",
|
|
6129
|
+
"doctor.config.jsonc",
|
|
6130
|
+
"react-doctor.config.json",
|
|
6131
|
+
"package.json",
|
|
6132
|
+
"pnpm-workspace.yaml",
|
|
6133
|
+
"tsconfig.json",
|
|
6134
|
+
"tsconfig.base.json",
|
|
6135
|
+
".oxlintrc.json",
|
|
6136
|
+
".eslintrc.json",
|
|
6137
|
+
"pnpm-lock.yaml",
|
|
6138
|
+
"package-lock.json",
|
|
6139
|
+
"yarn.lock",
|
|
6140
|
+
"bun.lock",
|
|
6141
|
+
"bun.lockb",
|
|
6142
|
+
".gitignore"
|
|
6143
|
+
];
|
|
6144
|
+
const CANONICAL_GITHUB_URL = "https://github.com/millionco/react-doctor";
|
|
6145
|
+
const CANONICAL_DISCORD_URL = "https://react.doctor/discord";
|
|
6146
|
+
const SKILL_NAME = "react-doctor";
|
|
6147
|
+
const OXLINT_OUTPUT_MAX_BYTES = 50 * 1024 * 1024;
|
|
6148
|
+
const OXLINT_SPAWN_TIMEOUT_MS = 6e4;
|
|
6149
|
+
const DEAD_CODE_WORKER_MAX_OLD_SPACE_MB = 8192;
|
|
6150
|
+
const RECOMMENDED_PNPM_MINIMUM_RELEASE_AGE_MINUTES = 10080;
|
|
6151
|
+
const DIAGNOSTIC_CATEGORY_BUCKETS = [
|
|
6152
|
+
"Security",
|
|
6153
|
+
"Bugs",
|
|
6154
|
+
"Performance",
|
|
6155
|
+
"Accessibility",
|
|
6156
|
+
"Maintainability"
|
|
6157
|
+
];
|
|
6158
|
+
const APP_ONLY_RULE_KEYS = new Set([
|
|
6159
|
+
"react-hooks-js/static-components",
|
|
6160
|
+
"react-doctor/no-render-prop-children",
|
|
6161
|
+
"react-doctor/prefer-explicit-variants"
|
|
6162
|
+
]);
|
|
6163
|
+
const COMPILER_CLEANUP_BUCKET = "compiler-cleanup";
|
|
6164
|
+
const COMPILER_CLEANUP_RULE_KEYS = new Set(["react-doctor/react-compiler-no-manual-memoization"]);
|
|
6165
|
+
const MAX_GLOB_PATTERN_LENGTH_CHARS = 1024;
|
|
6166
|
+
const CONFIG_CACHE_TTL_MS = 300 * 1e3;
|
|
6167
|
+
const TSCONFIG_FILENAME = "tsconfig.json";
|
|
6168
|
+
const isRelativeExtendsValue = (extendsValue) => extendsValue.startsWith("./") || extendsValue.startsWith("../") || path$1.isAbsolute(extendsValue);
|
|
6169
|
+
const ensureJsonExtension = (filePath) => path$1.extname(filePath) === "" ? `${filePath}.json` : filePath;
|
|
6170
|
+
const resolvePackageExtendsPath = (extendsValue, fromConfigDirectory) => {
|
|
6171
|
+
const requireFromConfig = createRequire(path$1.join(fromConfigDirectory, "tsconfig.json"));
|
|
6172
|
+
const candidates = [
|
|
6173
|
+
extendsValue,
|
|
6174
|
+
ensureJsonExtension(extendsValue),
|
|
6175
|
+
`${extendsValue.replace(/\/$/, "")}/tsconfig.json`
|
|
6176
|
+
];
|
|
6177
|
+
for (const candidate of candidates) try {
|
|
6178
|
+
return requireFromConfig.resolve(candidate);
|
|
6179
|
+
} catch {
|
|
6180
|
+
continue;
|
|
6181
|
+
}
|
|
6182
|
+
return null;
|
|
6183
|
+
};
|
|
6184
|
+
const resolveExtendsPath = (extendsValue, fromConfigDirectory) => {
|
|
6185
|
+
if (isRelativeExtendsValue(extendsValue)) return ensureJsonExtension(path$1.resolve(fromConfigDirectory, extendsValue));
|
|
6186
|
+
return resolvePackageExtendsPath(extendsValue, fromConfigDirectory);
|
|
6187
|
+
};
|
|
6188
|
+
const normalizeCompilerOptions = (compilerOptions) => {
|
|
6189
|
+
if (!isPlainObject(compilerOptions)) return { hasExplicitLib: false };
|
|
6190
|
+
const target = typeof compilerOptions.target === "string" ? compilerOptions.target : void 0;
|
|
6191
|
+
const hasExplicitLib = Object.hasOwn(compilerOptions, "lib");
|
|
6192
|
+
return {
|
|
6193
|
+
target,
|
|
6194
|
+
lib: Array.isArray(compilerOptions.lib) ? compilerOptions.lib.filter((entry) => typeof entry === "string") : void 0,
|
|
6195
|
+
hasExplicitLib
|
|
6196
|
+
};
|
|
6197
|
+
};
|
|
6198
|
+
const readTsConfig = (filePath) => {
|
|
6199
|
+
let content;
|
|
6200
|
+
try {
|
|
6201
|
+
content = fs$1.readFileSync(filePath, "utf-8");
|
|
6202
|
+
} catch {
|
|
6203
|
+
return null;
|
|
6204
|
+
}
|
|
6205
|
+
const parsed = ts.parseConfigFileTextToJson(filePath, content);
|
|
6206
|
+
if (!isPlainObject(parsed.config)) return null;
|
|
6207
|
+
return {
|
|
6208
|
+
extends: typeof parsed.config.extends === "string" ? parsed.config.extends : void 0,
|
|
6209
|
+
compilerOptions: normalizeCompilerOptions(parsed.config.compilerOptions)
|
|
6210
|
+
};
|
|
6211
|
+
};
|
|
6212
|
+
const mergeCompilerOptions = (inherited, current) => {
|
|
6213
|
+
const target = current.target ?? inherited?.target;
|
|
6214
|
+
const hasExplicitLib = current.hasExplicitLib || Boolean(inherited?.hasExplicitLib);
|
|
6215
|
+
return {
|
|
6216
|
+
target,
|
|
6217
|
+
lib: current.hasExplicitLib ? current.lib : inherited?.lib,
|
|
6218
|
+
hasExplicitLib
|
|
6219
|
+
};
|
|
6220
|
+
};
|
|
6221
|
+
const readResolvedCompilerOptions = (tsConfigPath, extendsDepth, visitedPaths) => {
|
|
6222
|
+
const realPath = fs$1.realpathSync.native(tsConfigPath);
|
|
6223
|
+
if (visitedPaths.has(realPath)) return null;
|
|
6224
|
+
const tsConfig = readTsConfig(realPath);
|
|
6225
|
+
if (!tsConfig) return null;
|
|
6226
|
+
const nextVisitedPaths = new Set(visitedPaths);
|
|
6227
|
+
nextVisitedPaths.add(realPath);
|
|
6228
|
+
if (tsConfig.extends && extendsDepth < 8) {
|
|
6229
|
+
const parentPath = resolveExtendsPath(tsConfig.extends, path$1.dirname(realPath));
|
|
6230
|
+
if (parentPath && isFile(parentPath)) return mergeCompilerOptions(readResolvedCompilerOptions(parentPath, extendsDepth + 1, nextVisitedPaths), tsConfig.compilerOptions);
|
|
6231
|
+
}
|
|
6232
|
+
return tsConfig.compilerOptions;
|
|
6233
|
+
};
|
|
6234
|
+
const targetYearIsPreES2023 = (target) => {
|
|
6235
|
+
const year = ES_TARGET_YEAR_BY_NAME[target.toLowerCase()];
|
|
6236
|
+
return year !== void 0 && year < 2023;
|
|
6237
|
+
};
|
|
6238
|
+
const libEntryIncludesES2023Array = (entry) => {
|
|
6239
|
+
const normalizedEntry = entry.toLowerCase();
|
|
6240
|
+
if (normalizedEntry === "esnext" || normalizedEntry === "esnext.array") return true;
|
|
6241
|
+
const esYearMatch = /^es(\d{4})(?:\.(.+))?$/.exec(normalizedEntry);
|
|
6242
|
+
if (!esYearMatch) return false;
|
|
6243
|
+
if (Number(esYearMatch[1]) < 2023) return false;
|
|
6244
|
+
const component = esYearMatch[2];
|
|
6245
|
+
return component === void 0 || component === "array";
|
|
6246
|
+
};
|
|
6247
|
+
const libIncludesES2023 = (lib) => lib.some(libEntryIncludesES2023Array);
|
|
6248
|
+
const compilerOptionsArePreES2023 = (compilerOptions) => {
|
|
6249
|
+
if (compilerOptions.hasExplicitLib) return !libIncludesES2023(compilerOptions.lib ?? []);
|
|
6250
|
+
if (compilerOptions.target) return targetYearIsPreES2023(compilerOptions.target);
|
|
6251
|
+
return false;
|
|
6252
|
+
};
|
|
6253
|
+
const compilerOptionsDeclareTargetOrLib = (compilerOptions) => compilerOptions.hasExplicitLib || compilerOptions.target !== void 0;
|
|
6254
|
+
const detectPreES2023FromConfig = (tsConfigPath) => {
|
|
6255
|
+
const compilerOptions = readResolvedCompilerOptions(tsConfigPath, 0, /* @__PURE__ */ new Set());
|
|
6256
|
+
if (!compilerOptions) return false;
|
|
6257
|
+
if (!compilerOptionsDeclareTargetOrLib(compilerOptions)) return false;
|
|
6258
|
+
return compilerOptionsArePreES2023(compilerOptions);
|
|
6259
|
+
};
|
|
6260
|
+
const detectPreES2023Target = (directory) => {
|
|
6261
|
+
const tsConfigPath = path$1.join(directory, TSCONFIG_FILENAME);
|
|
6262
|
+
if (isFile(tsConfigPath)) return detectPreES2023FromConfig(tsConfigPath);
|
|
6263
|
+
return false;
|
|
6264
|
+
};
|
|
6067
6265
|
const REACT_DEPENDENCY_NAMES = new Set([
|
|
6068
6266
|
"react",
|
|
6069
6267
|
"react-native",
|
|
@@ -6175,11 +6373,63 @@ const discoverReactSubprojects = (rootDirectory) => {
|
|
|
6175
6373
|
return discoverReactSubprojectsByFilesystem(rootDirectory);
|
|
6176
6374
|
};
|
|
6177
6375
|
const cachedProjectInfos = /* @__PURE__ */ new Map();
|
|
6376
|
+
/**
|
|
6377
|
+
* Build a `ProjectInfo` for a directory that has no `package.json` of
|
|
6378
|
+
* its own — a monorepo subfolder like `repo/packages`, or any loose tree
|
|
6379
|
+
* of TypeScript/JavaScript files. Dependency + framework detection is
|
|
6380
|
+
* inherited from the enclosing workspace root when there is one, so
|
|
6381
|
+
* scanning a subdirectory of a React monorepo still gets the React
|
|
6382
|
+
* capabilities; a standalone non-React directory simply scans with the
|
|
6383
|
+
* framework-agnostic rules. Throws only when the directory has nothing
|
|
6384
|
+
* to scan (no enclosing project and no source files of its own).
|
|
6385
|
+
*/
|
|
6386
|
+
const discoverProjectWithoutPackageJson = (directory) => {
|
|
6387
|
+
const sourceFileCount = countSourceFiles(directory);
|
|
6388
|
+
const hasOwnTsConfig = fs$1.existsSync(path$1.join(directory, "tsconfig.json"));
|
|
6389
|
+
const monorepoRoot = findMonorepoRoot(directory);
|
|
6390
|
+
const enclosingProject = monorepoRoot !== null && isFile(path$1.join(monorepoRoot, "package.json")) ? discoverProject(monorepoRoot) : null;
|
|
6391
|
+
if (enclosingProject !== null) return {
|
|
6392
|
+
...enclosingProject,
|
|
6393
|
+
rootDirectory: directory,
|
|
6394
|
+
projectName: path$1.basename(directory),
|
|
6395
|
+
hasTypeScript: hasOwnTsConfig || enclosingProject.hasTypeScript,
|
|
6396
|
+
sourceFileCount
|
|
6397
|
+
};
|
|
6398
|
+
if (sourceFileCount === 0) throw new PackageJsonNotFoundError(directory);
|
|
6399
|
+
return {
|
|
6400
|
+
rootDirectory: directory,
|
|
6401
|
+
projectName: path$1.basename(directory),
|
|
6402
|
+
reactVersion: null,
|
|
6403
|
+
reactMajorVersion: null,
|
|
6404
|
+
tailwindVersion: null,
|
|
6405
|
+
zodVersion: null,
|
|
6406
|
+
zodMajorVersion: null,
|
|
6407
|
+
framework: "unknown",
|
|
6408
|
+
hasTypeScript: hasOwnTsConfig,
|
|
6409
|
+
hasReactCompiler: false,
|
|
6410
|
+
hasTanStackQuery: false,
|
|
6411
|
+
preactVersion: null,
|
|
6412
|
+
preactMajorVersion: null,
|
|
6413
|
+
hasReactNativeWorkspace: false,
|
|
6414
|
+
nextjsVersion: null,
|
|
6415
|
+
nextjsMajorVersion: null,
|
|
6416
|
+
expoVersion: null,
|
|
6417
|
+
shopifyFlashListVersion: null,
|
|
6418
|
+
shopifyFlashListMajorVersion: null,
|
|
6419
|
+
hasReanimated: false,
|
|
6420
|
+
isPreES2023Target: hasOwnTsConfig && detectPreES2023Target(directory),
|
|
6421
|
+
sourceFileCount
|
|
6422
|
+
};
|
|
6423
|
+
};
|
|
6178
6424
|
const discoverProject = (directory) => {
|
|
6179
6425
|
const cached = cachedProjectInfos.get(directory);
|
|
6180
6426
|
if (cached !== void 0) return cached;
|
|
6181
6427
|
const packageJsonPath = path$1.join(directory, "package.json");
|
|
6182
|
-
if (!isFile(packageJsonPath))
|
|
6428
|
+
if (!isFile(packageJsonPath)) {
|
|
6429
|
+
const synthesized = discoverProjectWithoutPackageJson(directory);
|
|
6430
|
+
cachedProjectInfos.set(directory, synthesized);
|
|
6431
|
+
return synthesized;
|
|
6432
|
+
}
|
|
6183
6433
|
const packageJson = readPackageJson$1(packageJsonPath);
|
|
6184
6434
|
let { reactVersion, tailwindVersion, zodVersion, framework } = extractDependencyInfo(packageJson);
|
|
6185
6435
|
const reactDeclaration = getDependencyDeclaration({
|
|
@@ -6265,6 +6515,7 @@ const discoverProject = (directory) => {
|
|
|
6265
6515
|
version: findNextjsVersion(directory, packageJson)
|
|
6266
6516
|
}) : null;
|
|
6267
6517
|
const preactVersion = getPreactVersion(packageJson);
|
|
6518
|
+
const isPreES2023Target = hasTypeScript && detectPreES2023Target(directory);
|
|
6268
6519
|
const projectInfo = {
|
|
6269
6520
|
rootDirectory: directory,
|
|
6270
6521
|
projectName,
|
|
@@ -6286,12 +6537,22 @@ const discoverProject = (directory) => {
|
|
|
6286
6537
|
shopifyFlashListVersion,
|
|
6287
6538
|
shopifyFlashListMajorVersion: shopifyFlashListVersion === null ? null : getLowestDependencyMajor(shopifyFlashListVersion),
|
|
6288
6539
|
hasReanimated,
|
|
6540
|
+
isPreES2023Target,
|
|
6289
6541
|
sourceFileCount
|
|
6290
6542
|
};
|
|
6291
6543
|
cachedProjectInfos.set(directory, projectInfo);
|
|
6292
6544
|
return projectInfo;
|
|
6293
6545
|
};
|
|
6294
|
-
|
|
6546
|
+
/**
|
|
6547
|
+
* A project is worth scanning when it has React/Preact (the framework-
|
|
6548
|
+
* specific rules apply) OR it simply has source files to lint. The
|
|
6549
|
+
* second arm is what lets a plain TypeScript/JavaScript codebase — no
|
|
6550
|
+
* React dependency at all — run the framework-agnostic rules
|
|
6551
|
+
* (security, architecture, zod, bundle-size, …) instead of hard-failing
|
|
6552
|
+
* with "No React dependency". Only a directory with neither React nor a
|
|
6553
|
+
* single source file has nothing to analyze.
|
|
6554
|
+
*/
|
|
6555
|
+
const isAnalyzableProject = (project) => project.reactVersion !== null || project.preactVersion !== null || project.sourceFileCount > 0;
|
|
6295
6556
|
const MAJOR_MINOR_PATTERN = /(\d{1,4})\.(\d{1,4})/;
|
|
6296
6557
|
const MAJOR_ONLY_PATTERN = /(\d{1,4})/;
|
|
6297
6558
|
const UPPER_BOUND_COMPARATOR_PATTERN = /<=?\s{0,8}\d{1,4}(?:\.\d{1,4}){0,2}(?:-[^\s,|]+)?/g;
|
|
@@ -6355,66 +6616,6 @@ const isTailwindAtLeast = (detected, required) => {
|
|
|
6355
6616
|
if (detected.major !== required.major) return detected.major > required.major;
|
|
6356
6617
|
return detected.minor >= required.minor;
|
|
6357
6618
|
};
|
|
6358
|
-
const JSX_FILE_PATTERN = /\.(tsx|jsx)$/;
|
|
6359
|
-
const MILLISECONDS_PER_SECOND = 1e3;
|
|
6360
|
-
const SCORE_API_URL = "https://www.react.doctor/api/score";
|
|
6361
|
-
const ENTERPRISE_CONTACT_URL = "https://react.doctor/enterprise";
|
|
6362
|
-
const SHARE_BASE_URL = "https://react.doctor/share";
|
|
6363
|
-
const CI_URL = "https://react.doctor/ci";
|
|
6364
|
-
const GITHUB_ACTIONS_SETUP_URL = "https://www.react.doctor/docs/ci-and-prs/github-actions-setup";
|
|
6365
|
-
const DOCS_URL = "https://react.doctor/docs";
|
|
6366
|
-
const DOCS_RULES_BASE_URL = `${DOCS_URL}/rules`;
|
|
6367
|
-
const FETCH_TIMEOUT_MS = 1e4;
|
|
6368
|
-
const GITHUB_VIEWER_PERMISSION_TIMEOUT_MS = 2e3;
|
|
6369
|
-
const DEFAULT_BRANCH_CANDIDATES = ["main", "master"];
|
|
6370
|
-
const ADOPTABLE_LINT_CONFIG_FILENAMES = [".oxlintrc.json", ".eslintrc.json"];
|
|
6371
|
-
const OXLINT_NODE_REQUIREMENT = "^20.19.0 || >=22.12.0";
|
|
6372
|
-
const GIT_SHOW_MAX_BUFFER_BYTES = 10 * 1024 * 1024;
|
|
6373
|
-
/**
|
|
6374
|
-
* Project-config files that `StagedFiles.materialize` copies into
|
|
6375
|
-
* the temp directory alongside staged sources so oxlint resolves
|
|
6376
|
-
* `tsconfig` / `package.json` / lint configs the same way it would
|
|
6377
|
-
* in the working tree. Hoisted out of the staged-files helper so
|
|
6378
|
-
* the constant lives next to the rest of the IO budget knobs.
|
|
6379
|
-
*/
|
|
6380
|
-
const STAGED_FILES_PROJECT_CONFIG_FILENAMES = [
|
|
6381
|
-
"tsconfig.json",
|
|
6382
|
-
"tsconfig.base.json",
|
|
6383
|
-
"package.json",
|
|
6384
|
-
"doctor.config.ts",
|
|
6385
|
-
"doctor.config.mts",
|
|
6386
|
-
"doctor.config.cts",
|
|
6387
|
-
"doctor.config.js",
|
|
6388
|
-
"doctor.config.mjs",
|
|
6389
|
-
"doctor.config.cjs",
|
|
6390
|
-
"doctor.config.json",
|
|
6391
|
-
"doctor.config.jsonc",
|
|
6392
|
-
"oxlint.json",
|
|
6393
|
-
".oxlintrc.json"
|
|
6394
|
-
];
|
|
6395
|
-
const CANONICAL_GITHUB_URL = "https://github.com/millionco/react-doctor";
|
|
6396
|
-
const CANONICAL_DISCORD_URL = "https://react.doctor/discord";
|
|
6397
|
-
const SKILL_NAME = "react-doctor";
|
|
6398
|
-
const OXLINT_OUTPUT_MAX_BYTES = 50 * 1024 * 1024;
|
|
6399
|
-
const OXLINT_SPAWN_TIMEOUT_MS = 6e4;
|
|
6400
|
-
const DEAD_CODE_WORKER_MAX_OLD_SPACE_MB = 8192;
|
|
6401
|
-
const RECOMMENDED_PNPM_MINIMUM_RELEASE_AGE_MINUTES = 10080;
|
|
6402
|
-
const DIAGNOSTIC_CATEGORY_BUCKETS = [
|
|
6403
|
-
"Security",
|
|
6404
|
-
"Bugs",
|
|
6405
|
-
"Performance",
|
|
6406
|
-
"Accessibility",
|
|
6407
|
-
"Maintainability"
|
|
6408
|
-
];
|
|
6409
|
-
const APP_ONLY_RULE_KEYS = new Set([
|
|
6410
|
-
"react-hooks-js/static-components",
|
|
6411
|
-
"react-doctor/no-render-prop-children",
|
|
6412
|
-
"react-doctor/prefer-explicit-variants"
|
|
6413
|
-
]);
|
|
6414
|
-
const COMPILER_CLEANUP_BUCKET = "compiler-cleanup";
|
|
6415
|
-
const COMPILER_CLEANUP_RULE_KEYS = new Set(["react-doctor/react-compiler-no-manual-memoization"]);
|
|
6416
|
-
const MAX_GLOB_PATTERN_LENGTH_CHARS = 1024;
|
|
6417
|
-
const CONFIG_CACHE_TTL_MS = 300 * 1e3;
|
|
6418
6619
|
var InvalidGlobPatternError = class extends Error {
|
|
6419
6620
|
pattern;
|
|
6420
6621
|
reason;
|
|
@@ -7920,51 +8121,51 @@ const FLAGGED_DEPENDENCIES = [
|
|
|
7920
8121
|
{
|
|
7921
8122
|
packageName: "expo-modules-autolinking",
|
|
7922
8123
|
rule: "expo-no-redundant-dependency",
|
|
7923
|
-
message: "\"expo-modules-autolinking\" should not be a direct dependency
|
|
8124
|
+
message: "\"expo-modules-autolinking\" should not be a direct dependency. Expo pins the compatible version through the SDK, and a direct entry can drift to a version that breaks prebuild, Metro, or native builds",
|
|
7924
8125
|
help: "Remove `expo-modules-autolinking` from your package.json"
|
|
7925
8126
|
},
|
|
7926
8127
|
{
|
|
7927
8128
|
packageName: "expo-dev-launcher",
|
|
7928
8129
|
rule: "expo-no-redundant-dependency",
|
|
7929
|
-
message: "\"expo-dev-launcher\" should not be a direct dependency
|
|
8130
|
+
message: "\"expo-dev-launcher\" should not be a direct dependency. `expo-dev-client` pins the compatible launcher, and a direct entry can drift to a version that breaks native builds",
|
|
7930
8131
|
help: "Remove `expo-dev-launcher` and depend on `expo-dev-client` instead"
|
|
7931
8132
|
},
|
|
7932
8133
|
{
|
|
7933
8134
|
packageName: "expo-dev-menu",
|
|
7934
8135
|
rule: "expo-no-redundant-dependency",
|
|
7935
|
-
message: "\"expo-dev-menu\" should not be a direct dependency
|
|
8136
|
+
message: "\"expo-dev-menu\" should not be a direct dependency. `expo-dev-client` pins the compatible dev menu, and a direct entry can drift to a version that breaks native builds",
|
|
7936
8137
|
help: "Remove `expo-dev-menu` and depend on `expo-dev-client` instead"
|
|
7937
8138
|
},
|
|
7938
8139
|
{
|
|
7939
8140
|
packageName: "expo-modules-core",
|
|
7940
8141
|
rule: "expo-no-redundant-dependency",
|
|
7941
|
-
message: "\"expo-modules-core\" should not be a direct dependency
|
|
8142
|
+
message: "\"expo-modules-core\" should not be a direct dependency. Expo pins the compatible native core, and a direct entry can drift to a version that breaks prebuild or native builds",
|
|
7942
8143
|
help: "Remove `expo-modules-core` from your package.json and import from `expo` instead"
|
|
7943
8144
|
},
|
|
7944
8145
|
{
|
|
7945
8146
|
packageName: "@expo/metro-config",
|
|
7946
8147
|
rule: "expo-no-redundant-dependency",
|
|
7947
|
-
message: "\"@expo/metro-config\" should not be a direct dependency
|
|
8148
|
+
message: "\"@expo/metro-config\" should not be a direct dependency. Expo pins the compatible Metro config, and a direct entry can drift to a version that breaks bundling",
|
|
7948
8149
|
help: "Remove `@expo/metro-config` and import `expo/metro-config` in your metro.config.js"
|
|
7949
8150
|
},
|
|
7950
8151
|
{
|
|
7951
8152
|
packageName: "@types/react-native",
|
|
7952
8153
|
rule: "expo-no-redundant-dependency",
|
|
7953
|
-
message: "\"@types/react-native\" should not be installed
|
|
8154
|
+
message: "\"@types/react-native\" should not be installed. React Native ships its own types since SDK 48, so the extra package can introduce duplicate or stale type definitions",
|
|
7954
8155
|
help: "Remove `@types/react-native` from your package.json",
|
|
7955
8156
|
minSdkMajor: 48
|
|
7956
8157
|
},
|
|
7957
8158
|
{
|
|
7958
8159
|
packageName: "@expo/config-plugins",
|
|
7959
8160
|
rule: "expo-no-redundant-dependency",
|
|
7960
|
-
message: "\"@expo/config-plugins\" should not be a direct dependency
|
|
8161
|
+
message: "\"@expo/config-plugins\" should not be a direct dependency. Expo pins the compatible config-plugin API, and a direct entry can drift to a version that breaks prebuild",
|
|
7961
8162
|
help: "Remove `@expo/config-plugins`; config-plugin authors should import from `expo/config-plugins`. See https://github.com/expo/expo/pull/18855",
|
|
7962
8163
|
minSdkMajor: 48
|
|
7963
8164
|
},
|
|
7964
8165
|
{
|
|
7965
8166
|
packageName: "@expo/prebuild-config",
|
|
7966
8167
|
rule: "expo-no-redundant-dependency",
|
|
7967
|
-
message: "\"@expo/prebuild-config\" should not be a direct dependency
|
|
8168
|
+
message: "\"@expo/prebuild-config\" should not be a direct dependency. Expo pins the compatible prebuild config, and a direct entry can drift to a version that breaks prebuild",
|
|
7968
8169
|
help: "Remove `@expo/prebuild-config` from your package.json",
|
|
7969
8170
|
minSdkMajor: 53
|
|
7970
8171
|
},
|
|
@@ -7978,28 +8179,28 @@ const FLAGGED_DEPENDENCIES = [
|
|
|
7978
8179
|
{
|
|
7979
8180
|
packageName: "expo-app-loading",
|
|
7980
8181
|
rule: "expo-no-redundant-dependency",
|
|
7981
|
-
message: "\"expo-app-loading\" was removed in SDK 49",
|
|
8182
|
+
message: "\"expo-app-loading\" was removed in SDK 49, so keeping it can leave imports unresolved after upgrading Expo",
|
|
7982
8183
|
help: "Remove `expo-app-loading` and use `expo-splash-screen` instead. See https://docs.expo.dev/versions/latest/sdk/splash-screen/",
|
|
7983
8184
|
minSdkMajor: 49
|
|
7984
8185
|
},
|
|
7985
8186
|
{
|
|
7986
8187
|
packageName: "expo-firebase-analytics",
|
|
7987
8188
|
rule: "expo-no-redundant-dependency",
|
|
7988
|
-
message: "\"expo-firebase-analytics\" was removed in SDK 48",
|
|
8189
|
+
message: "\"expo-firebase-analytics\" was removed in SDK 48, so keeping it can leave imports unresolved or fail native builds after upgrading Expo",
|
|
7989
8190
|
help: FIREBASE_HELP,
|
|
7990
8191
|
minSdkMajor: 48
|
|
7991
8192
|
},
|
|
7992
8193
|
{
|
|
7993
8194
|
packageName: "expo-firebase-recaptcha",
|
|
7994
8195
|
rule: "expo-no-redundant-dependency",
|
|
7995
|
-
message: "\"expo-firebase-recaptcha\" was removed in SDK 48",
|
|
8196
|
+
message: "\"expo-firebase-recaptcha\" was removed in SDK 48, so keeping it can leave imports unresolved or fail native builds after upgrading Expo",
|
|
7996
8197
|
help: FIREBASE_HELP,
|
|
7997
8198
|
minSdkMajor: 48
|
|
7998
8199
|
},
|
|
7999
8200
|
{
|
|
8000
8201
|
packageName: "expo-firebase-core",
|
|
8001
8202
|
rule: "expo-no-redundant-dependency",
|
|
8002
|
-
message: "\"expo-firebase-core\" was removed in SDK 48",
|
|
8203
|
+
message: "\"expo-firebase-core\" was removed in SDK 48, so keeping it can leave imports unresolved or fail native builds after upgrading Expo",
|
|
8003
8204
|
help: FIREBASE_HELP,
|
|
8004
8205
|
minSdkMajor: 48
|
|
8005
8206
|
}
|
|
@@ -8040,7 +8241,7 @@ const checkExpoGitignore = (context) => {
|
|
|
8040
8241
|
}));
|
|
8041
8242
|
if (findLocalModuleNativeFiles(rootDirectory).find((nativeFilePath) => isPathGitIgnored(rootDirectory, nativeFilePath) === true) !== void 0) diagnostics.push(buildExpoDiagnostic({
|
|
8042
8243
|
rule: "expo-gitignore",
|
|
8043
|
-
message: "The native `ios`/`android` directories of a local Expo module under `modules/` are gitignored
|
|
8244
|
+
message: "The native `ios`/`android` directories of a local Expo module under `modules/` are gitignored, so required native code can be missing from CI or teammate checkouts.",
|
|
8044
8245
|
help: "Use anchored patterns like `/ios` and `/android` in .gitignore so only the top-level native directories are excluded, not those inside `modules/`"
|
|
8045
8246
|
}));
|
|
8046
8247
|
return diagnostics;
|
|
@@ -8102,17 +8303,16 @@ const checkExpoPackageJsonConflicts = (context) => {
|
|
|
8102
8303
|
const conflictingScriptNames = CONFLICTING_SCRIPT_NAMES.filter((scriptName) => Boolean(packageJson.scripts?.[scriptName]));
|
|
8103
8304
|
if (conflictingScriptNames.length > 0) {
|
|
8104
8305
|
const quotedNames = conflictingScriptNames.map((name) => `"${name}"`).join(", ");
|
|
8105
|
-
const shadowsExpoCli = conflictingScriptNames.includes("expo");
|
|
8106
8306
|
diagnostics.push(buildExpoDiagnostic({
|
|
8107
8307
|
rule: "expo-package-json-conflict",
|
|
8108
|
-
message: `package.json defines ${quotedNames} ${conflictingScriptNames.length === 1 ? "as a script that
|
|
8308
|
+
message: `package.json defines ${quotedNames} ${conflictingScriptNames.length === 1 ? "as a script that shadows" : "as scripts that shadow"} Expo/React Native binaries in node_modules/.bin, so tooling can run the local script instead of the expected CLI and fail builds.`,
|
|
8109
8309
|
help: "Rename these scripts so they don't collide with the `expo` / `react-native` binaries"
|
|
8110
8310
|
}));
|
|
8111
8311
|
}
|
|
8112
8312
|
const packageName = packageJson.name;
|
|
8113
8313
|
if (typeof packageName === "string" && context.directDependencyNames.has(packageName)) diagnostics.push(buildExpoDiagnostic({
|
|
8114
8314
|
rule: "expo-package-json-conflict",
|
|
8115
|
-
message: `package.json "name" is "${packageName}", which collides with a dependency of the same name
|
|
8315
|
+
message: `package.json "name" is "${packageName}", which collides with a dependency of the same name, so package self-resolution can shadow the dependency and break imports that expect the installed package.`,
|
|
8116
8316
|
help: "Rename your package so it no longer matches one of its dependencies"
|
|
8117
8317
|
}));
|
|
8118
8318
|
return diagnostics;
|
|
@@ -8183,7 +8383,7 @@ const checkExpoRouterReactNavigation = (context) => {
|
|
|
8183
8383
|
if (reactNavigationNames.length === 0) return [];
|
|
8184
8384
|
return [buildExpoDiagnostic({
|
|
8185
8385
|
rule: "expo-router-no-react-navigation",
|
|
8186
|
-
message: `As of SDK 56, expo-router is no longer compatible with react-navigation,
|
|
8386
|
+
message: `As of SDK 56, expo-router is no longer compatible with directly installed @react-navigation packages, so keeping ${reactNavigationNames.map((name) => `"${name}"`).join(", ")} can break routing or linking behavior after the SDK upgrade.`,
|
|
8187
8387
|
help: "Remove these `@react-navigation/*` packages and replace direct imports with their expo-router equivalents. See https://docs.expo.dev/router/migrate/sdk-55-to-56/"
|
|
8188
8388
|
})];
|
|
8189
8389
|
};
|
|
@@ -8555,7 +8755,9 @@ const setColorEnabled = (enabled) => {
|
|
|
8555
8755
|
highlighter.gray = colors.gray;
|
|
8556
8756
|
highlighter.bold = colors.bold;
|
|
8557
8757
|
};
|
|
8558
|
-
const
|
|
8758
|
+
const NEXT_ENTRY_FILE_PATTERN = /^(?:\.\/)?(?:src\/)?(?:middleware|proxy)\.(?:tsx?|jsx?|mts|mjs)$/;
|
|
8759
|
+
const shouldIncludeExplicitLintPath = (filePath, project) => JSX_FILE_PATTERN.test(filePath) || project?.framework === "nextjs" && NEXT_ENTRY_FILE_PATTERN.test(filePath);
|
|
8760
|
+
const computeExplicitLintIncludePaths = (includePaths, project) => includePaths.length > 0 ? includePaths.filter((filePath) => shouldIncludeExplicitLintPath(filePath, project)) : void 0;
|
|
8559
8761
|
const LINGUIST_ATTRIBUTE_PATTERN = /^linguist-(?:vendored|generated)(?:=([a-zA-Z0-9]+))?$/i;
|
|
8560
8762
|
const FALSY_VALUES = new Set([
|
|
8561
8763
|
"false",
|
|
@@ -8635,7 +8837,7 @@ const collectIgnorePatterns = (rootDirectory) => {
|
|
|
8635
8837
|
return patterns;
|
|
8636
8838
|
};
|
|
8637
8839
|
const KNIP_JSON_FILENAME = "knip.json";
|
|
8638
|
-
const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8840
|
+
const isRecord$1$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8639
8841
|
const readJsonFileSafe = (filePath) => {
|
|
8640
8842
|
let rawContents;
|
|
8641
8843
|
try {
|
|
@@ -8651,10 +8853,10 @@ const readJsonFileSafe = (filePath) => {
|
|
|
8651
8853
|
};
|
|
8652
8854
|
const readKnipConfig = (rootDirectory) => {
|
|
8653
8855
|
const knipJson = readJsonFileSafe(path.join(rootDirectory, KNIP_JSON_FILENAME));
|
|
8654
|
-
if (isRecord$1(knipJson)) return knipJson;
|
|
8856
|
+
if (isRecord$1$1(knipJson)) return knipJson;
|
|
8655
8857
|
const packageJson = readJsonFileSafe(path.join(rootDirectory, "package.json"));
|
|
8656
|
-
const packageKnipConfig = isRecord$1(packageJson) ? packageJson.knip : null;
|
|
8657
|
-
return isRecord$1(packageKnipConfig) ? packageKnipConfig : null;
|
|
8858
|
+
const packageKnipConfig = isRecord$1$1(packageJson) ? packageJson.knip : null;
|
|
8859
|
+
return isRecord$1$1(packageKnipConfig) ? packageKnipConfig : null;
|
|
8658
8860
|
};
|
|
8659
8861
|
const normalizePatternList = (value) => {
|
|
8660
8862
|
if (typeof value === "string" && value.length > 0) return [value];
|
|
@@ -8666,10 +8868,10 @@ const prefixWorkspacePatterns = (workspacePattern, patterns) => {
|
|
|
8666
8868
|
return patterns.map((pattern) => pattern.startsWith("!") ? `!${normalizedWorkspacePattern}/${pattern.slice(1)}` : `${normalizedWorkspacePattern}/${pattern}`);
|
|
8667
8869
|
};
|
|
8668
8870
|
const collectKnipWorkspacePatterns = (workspaces, settingName) => {
|
|
8669
|
-
if (!isRecord$1(workspaces)) return [];
|
|
8871
|
+
if (!isRecord$1$1(workspaces)) return [];
|
|
8670
8872
|
const patterns = [];
|
|
8671
8873
|
for (const [workspacePattern, workspaceConfig] of Object.entries(workspaces)) {
|
|
8672
|
-
if (!isRecord$1(workspaceConfig)) continue;
|
|
8874
|
+
if (!isRecord$1$1(workspaceConfig)) continue;
|
|
8673
8875
|
patterns.push(...prefixWorkspacePatterns(workspacePattern, normalizePatternList(workspaceConfig[settingName])));
|
|
8674
8876
|
}
|
|
8675
8877
|
return patterns;
|
|
@@ -8981,7 +9183,7 @@ const checkDeadCode = async (options) => {
|
|
|
8981
9183
|
plugin: DEAD_CODE_PLUGIN,
|
|
8982
9184
|
rule: "unused-file",
|
|
8983
9185
|
severity: "warning",
|
|
8984
|
-
message: "Unused file
|
|
9186
|
+
message: "Unused file is not reachable from any entry point, so it adds maintenance surface without shipping any code.",
|
|
8985
9187
|
help: "Delete the file if it is truly unreachable, or import it from an entry point.",
|
|
8986
9188
|
line: 0,
|
|
8987
9189
|
column: 0,
|
|
@@ -8994,7 +9196,7 @@ const checkDeadCode = async (options) => {
|
|
|
8994
9196
|
plugin: DEAD_CODE_PLUGIN,
|
|
8995
9197
|
rule: unusedExport.isTypeOnly ? "unused-type" : "unused-export",
|
|
8996
9198
|
severity: "warning",
|
|
8997
|
-
message: `Unused ${label}: \`${unusedExport.name}
|
|
9199
|
+
message: `Unused ${label}: \`${unusedExport.name}\` is exported but no module imports it, so it expands the public surface and can mislead callers about supported API.`,
|
|
8998
9200
|
help: "Drop the `export` keyword (or remove the declaration) if no other module uses this symbol.",
|
|
8999
9201
|
line: unusedExport.line,
|
|
9000
9202
|
column: unusedExport.column,
|
|
@@ -9009,7 +9211,7 @@ const checkDeadCode = async (options) => {
|
|
|
9009
9211
|
rule: unusedDependency.isDevDependency ? "unused-dev-dependency" : "unused-dependency",
|
|
9010
9212
|
severity: "warning",
|
|
9011
9213
|
message: `Unused ${label}: \`${unusedDependency.name}\``,
|
|
9012
|
-
help:
|
|
9214
|
+
help: `An unused ${label} adds install time and supply-chain surface without being used; remove it from package.json if it is genuinely unused.`,
|
|
9013
9215
|
line: 0,
|
|
9014
9216
|
column: 0,
|
|
9015
9217
|
category: DEAD_CODE_CATEGORY
|
|
@@ -9022,7 +9224,7 @@ const checkDeadCode = async (options) => {
|
|
|
9022
9224
|
plugin: DEAD_CODE_PLUGIN,
|
|
9023
9225
|
rule: "circular-dependency",
|
|
9024
9226
|
severity: "warning",
|
|
9025
|
-
message: `Circular import cycle: ${cycle.files.map(toRelative).join(" → ")}
|
|
9227
|
+
message: `Circular import cycle: ${cycle.files.map(toRelative).join(" → ")}. Modules in the cycle can observe partially initialized exports, causing order-dependent bugs.`,
|
|
9026
9228
|
help: "Break the cycle by extracting the shared code into a third module that both files import.",
|
|
9027
9229
|
line: 0,
|
|
9028
9230
|
column: 0,
|
|
@@ -9105,11 +9307,11 @@ const listSourceFilesViaFilesystem = (rootDirectory) => {
|
|
|
9105
9307
|
return filePaths;
|
|
9106
9308
|
};
|
|
9107
9309
|
const listSourceFiles = (rootDirectory) => excludeMinifiedFiles(rootDirectory, listSourceFilesViaGit(rootDirectory) ?? listSourceFilesViaFilesystem(rootDirectory));
|
|
9108
|
-
const resolveLintIncludePaths = (rootDirectory, userConfig) => {
|
|
9310
|
+
const resolveLintIncludePaths = (rootDirectory, userConfig, project) => {
|
|
9109
9311
|
if (!Array.isArray(userConfig?.ignore?.files) || userConfig.ignore.files.length === 0) return;
|
|
9110
9312
|
const ignoredPatterns = compileIgnoredFilePatterns(userConfig);
|
|
9111
9313
|
return listSourceFiles(rootDirectory).filter((filePath) => {
|
|
9112
|
-
if (!
|
|
9314
|
+
if (!shouldIncludeExplicitLintPath(filePath, project)) return false;
|
|
9113
9315
|
return !isFileIgnoredByPatterns(filePath, rootDirectory, ignoredPatterns);
|
|
9114
9316
|
});
|
|
9115
9317
|
};
|
|
@@ -9812,6 +10014,7 @@ const neutralizeDisableDirectives = async (rootDirectory, includePaths) => {
|
|
|
9812
10014
|
const buildCapabilities = (project) => {
|
|
9813
10015
|
const capabilities = /* @__PURE__ */ new Set();
|
|
9814
10016
|
capabilities.add(project.framework);
|
|
10017
|
+
if (project.reactVersion !== null || project.preactVersion !== null) capabilities.add("react");
|
|
9815
10018
|
if (project.framework === "expo" || project.framework === "react-native" || project.hasReactNativeWorkspace) capabilities.add("react-native");
|
|
9816
10019
|
if (project.expoVersion !== null) capabilities.add("expo");
|
|
9817
10020
|
if (project.nextjsMajorVersion !== null && project.nextjsMajorVersion >= 15) capabilities.add("nextjs:15");
|
|
@@ -9837,6 +10040,7 @@ const buildCapabilities = (project) => {
|
|
|
9837
10040
|
capabilities.add("zod");
|
|
9838
10041
|
if (project.zodMajorVersion !== null && project.zodMajorVersion >= 4) capabilities.add("zod:4");
|
|
9839
10042
|
}
|
|
10043
|
+
if (project.isPreES2023Target) capabilities.add("pre-es2023");
|
|
9840
10044
|
if (project.hasReactCompiler) capabilities.add("react-compiler");
|
|
9841
10045
|
if (project.hasTanStackQuery) capabilities.add("tanstack-query");
|
|
9842
10046
|
if (project.hasTypeScript) capabilities.add("typescript");
|
|
@@ -9855,6 +10059,7 @@ const shouldEnableRule = (requires, tags, capabilities, ignoredTags, disabledBy)
|
|
|
9855
10059
|
if (requires) {
|
|
9856
10060
|
for (const capability of requires) if (!capabilities.has(capability)) return false;
|
|
9857
10061
|
}
|
|
10062
|
+
if (tags?.includes("react-jsx-only") && !capabilities.has("react")) return false;
|
|
9858
10063
|
if (disabledBy) {
|
|
9859
10064
|
for (const capability of disabledBy) if (capabilities.has(capability)) return false;
|
|
9860
10065
|
}
|
|
@@ -9889,16 +10094,16 @@ const readPluginShape = (pluginSpecifier, loadModule) => {
|
|
|
9889
10094
|
ruleNames: new Set(Object.keys(rules))
|
|
9890
10095
|
};
|
|
9891
10096
|
};
|
|
9892
|
-
const bundledRequire = createRequire(import.meta.url);
|
|
10097
|
+
const bundledRequire$1 = createRequire(import.meta.url);
|
|
9893
10098
|
const resolveReactHooksJsPlugin = (hasReactCompiler, customRulesOnly) => {
|
|
9894
10099
|
if (!hasReactCompiler || customRulesOnly) return null;
|
|
9895
10100
|
let pluginSpecifier;
|
|
9896
10101
|
try {
|
|
9897
|
-
pluginSpecifier = bundledRequire.resolve("eslint-plugin-react-hooks");
|
|
10102
|
+
pluginSpecifier = bundledRequire$1.resolve("eslint-plugin-react-hooks");
|
|
9898
10103
|
} catch {
|
|
9899
10104
|
return null;
|
|
9900
10105
|
}
|
|
9901
|
-
const { ruleNames } = readPluginShape(pluginSpecifier, (spec) => bundledRequire(spec));
|
|
10106
|
+
const { ruleNames } = readPluginShape(pluginSpecifier, (spec) => bundledRequire$1(spec));
|
|
9902
10107
|
return {
|
|
9903
10108
|
entry: {
|
|
9904
10109
|
name: "react-hooks-js",
|
|
@@ -11461,7 +11666,7 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
11461
11666
|
directory: scanDirectory,
|
|
11462
11667
|
repo
|
|
11463
11668
|
}).pipe(Effect.orElseSucceed(() => null)) : Effect.succeed(null));
|
|
11464
|
-
const lintIncludePaths = (input.skipJsxIncludeFilter ? input.includePaths.length > 0 ? [...input.includePaths] : void 0 :
|
|
11669
|
+
const lintIncludePaths = (input.skipJsxIncludeFilter ? input.includePaths.length > 0 ? [...input.includePaths] : void 0 : computeExplicitLintIncludePaths([...input.includePaths], project)) ?? resolveLintIncludePaths(scanDirectory, resolvedConfig.config, project);
|
|
11465
11670
|
const scannedFilePaths = input.suppressScanSummary ? (lintIncludePaths ?? (yield* filesService.listSourceFiles(scanDirectory))).map((relativePath) => path$1.resolve(scanDirectory, relativePath)) : [];
|
|
11466
11671
|
const beforeLint = hooks.beforeLint ?? NO_HOOKS.beforeLint;
|
|
11467
11672
|
const afterLint = hooks.afterLint ?? NO_HOOKS.afterLint;
|
|
@@ -12047,6 +12252,22 @@ const filterSourceFiles = (filePaths) => filePaths.filter(isLintableSourceFile);
|
|
|
12047
12252
|
* instead of being improvised per diagnostic.
|
|
12048
12253
|
*/
|
|
12049
12254
|
const buildRuleDocsUrl = (plugin, rule) => `${DOCS_RULES_BASE_URL}/${plugin}/${rule}`;
|
|
12255
|
+
const computeConfigFingerprint = (projectDirectory, version) => {
|
|
12256
|
+
const parts = [`v=${version}`];
|
|
12257
|
+
let directory = projectDirectory;
|
|
12258
|
+
for (;;) {
|
|
12259
|
+
for (const filename of CONFIG_FINGERPRINT_FILENAMES) try {
|
|
12260
|
+
const stat = fs.statSync(path.join(directory, filename));
|
|
12261
|
+
parts.push(`${directory}/${filename}=${stat.mtimeMs}:${stat.size}`);
|
|
12262
|
+
} catch {
|
|
12263
|
+
continue;
|
|
12264
|
+
}
|
|
12265
|
+
const parent = path.dirname(directory);
|
|
12266
|
+
if (parent === directory) break;
|
|
12267
|
+
directory = parent;
|
|
12268
|
+
}
|
|
12269
|
+
return crypto.createHash("sha1").update(parts.join("|")).digest("hex");
|
|
12270
|
+
};
|
|
12050
12271
|
const groupBy = (items, keyFn) => {
|
|
12051
12272
|
const groups = /* @__PURE__ */ new Map();
|
|
12052
12273
|
for (const item of items) {
|
|
@@ -12247,7 +12468,7 @@ const makeNoopConsole = () => ({
|
|
|
12247
12468
|
});
|
|
12248
12469
|
//#endregion
|
|
12249
12470
|
//#region src/cli/utils/version.ts
|
|
12250
|
-
const VERSION = "0.4.2-dev.
|
|
12471
|
+
const VERSION = "0.4.2-dev.93d4eec";
|
|
12251
12472
|
//#endregion
|
|
12252
12473
|
//#region src/cli/utils/json-mode.ts
|
|
12253
12474
|
let context = null;
|
|
@@ -12605,13 +12826,13 @@ const isDevVersion = (version) => version === "0.0.0" || version.includes("-");
|
|
|
12605
12826
|
* uploads source-map artifacts under, so stack frames symbolicate. Honors the
|
|
12606
12827
|
* standard `SENTRY_RELEASE` override.
|
|
12607
12828
|
*/
|
|
12608
|
-
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.4.2-dev.
|
|
12829
|
+
const resolveSentryRelease = () => process.env.SENTRY_RELEASE || `react-doctor@0.4.2-dev.93d4eec`;
|
|
12609
12830
|
/**
|
|
12610
12831
|
* Deployment environment shown in Sentry's environment filter. Defaults to
|
|
12611
12832
|
* `production` for tagged releases and `development` for dev/unbuilt versions,
|
|
12612
12833
|
* overridable via the standard `SENTRY_ENVIRONMENT` env var.
|
|
12613
12834
|
*/
|
|
12614
|
-
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.4.2-dev.
|
|
12835
|
+
const resolveSentryEnvironment = () => process.env.SENTRY_ENVIRONMENT || (isDevVersion("0.4.2-dev.93d4eec") ? "development" : "production");
|
|
12615
12836
|
/**
|
|
12616
12837
|
* Performance-tracing sample rate in `[0, 1]`. Reads `SENTRY_TRACES_SAMPLE_RATE`
|
|
12617
12838
|
* (set to `0` to disable tracing) and falls back to
|
|
@@ -15874,13 +16095,14 @@ const buildRuntimeLayers = (input) => {
|
|
|
15874
16095
|
const linterLayer = input.shouldSkipLint ? Linter.layerOf([]) : Linter.layerOxlint;
|
|
15875
16096
|
const deadCodeLayer = input.shouldRunDeadCode ? DeadCode.layerNode : DeadCode.layerOf([]);
|
|
15876
16097
|
const scoreLayer = input.shouldComputeScore ? Score.layerHttp : Score.layerOf(null);
|
|
16098
|
+
const projectLayer = input.projectInfoOverride === void 0 ? Project.layerNode : Project.layerOf(input.projectInfoOverride);
|
|
15877
16099
|
const progressLayer = input.shouldShowProgressSpinners ? Progress.layerOra(buildSpinnerProgressHandle) : Progress.layerNoop;
|
|
15878
16100
|
const configLayer = input.hasConfigOverride ? Config.layerOf({
|
|
15879
16101
|
config: input.userConfig,
|
|
15880
16102
|
resolvedDirectory: input.directory,
|
|
15881
16103
|
configSourceDirectory: input.configSourceDirectory
|
|
15882
16104
|
}) : Config.layerNode;
|
|
15883
|
-
const baseLayers = Layer.mergeAll(
|
|
16105
|
+
const baseLayers = Layer.mergeAll(projectLayer, configLayer, Files.layerNode, Git.layerNode, linterLayer, LintPartialFailures.layerLive, deadCodeLayer, progressLayer, Reporter.layerNoop, scoreLayer);
|
|
15884
16106
|
return input.oxlintConcurrency === void 0 ? baseLayers : Layer.mergeAll(baseLayers, Layer.succeed(OxlintConcurrency, input.oxlintConcurrency));
|
|
15885
16107
|
};
|
|
15886
16108
|
//#endregion
|
|
@@ -16606,6 +16828,11 @@ const printCategoryCountUp = (tallies) => Effect.gen(function* () {
|
|
|
16606
16828
|
});
|
|
16607
16829
|
const TOP_ERROR_DETAIL_INDENT = " ";
|
|
16608
16830
|
const pickRepresentativeDiagnostic = (ruleDiagnostics) => ruleDiagnostics.find((diagnostic) => diagnostic.line > 0) ?? ruleDiagnostics[0];
|
|
16831
|
+
const hasIndistinctSiteLocations = (ruleDiagnostics) => {
|
|
16832
|
+
const firstDiagnostic = ruleDiagnostics[0];
|
|
16833
|
+
if (firstDiagnostic === void 0) return false;
|
|
16834
|
+
return ruleDiagnostics.every((diagnostic) => diagnostic.line <= 0 && diagnostic.filePath === firstDiagnostic.filePath);
|
|
16835
|
+
};
|
|
16609
16836
|
const FRAME_CONTEXT_REACH_LINES = 3;
|
|
16610
16837
|
const clusterNearbyDiagnostics = (diagnostics) => {
|
|
16611
16838
|
const byFile = groupBy(diagnostics, (diagnostic) => diagnostic.filePath);
|
|
@@ -16669,7 +16896,9 @@ const buildRuleDetailBlock = (ruleKey, ruleDiagnostics, resolveSourceRoot, rende
|
|
|
16669
16896
|
const learnMoreLine = formatLearnMoreLine(representative);
|
|
16670
16897
|
if (learnMoreLine) lines.push(`${TOP_ERROR_DETAIL_INDENT}${highlighter.info(learnMoreLine)}`);
|
|
16671
16898
|
}
|
|
16672
|
-
|
|
16899
|
+
const isCollapsedWarningGroup = severity === "warning" && hasIndistinctSiteLocations(ruleDiagnostics);
|
|
16900
|
+
const impactMessages = isCollapsedWarningGroup ? [...new Set(ruleDiagnostics.map((diagnostic) => diagnostic.message))] : [representative.message];
|
|
16901
|
+
for (const impactMessage of impactMessages) for (const explanationLine of wrapTextToWidth(impactMessage, resolveMeasureWidth(4), { breakLongWords: false })) lines.push(`${TOP_ERROR_DETAIL_INDENT}${explanationLine}`);
|
|
16673
16902
|
if (representative.help) for (const fixLine of wrapTextToWidth(`→ ${representative.help}`, resolveMeasureWidth(4), { breakLongWords: false })) lines.push(highlighter.dim(`${TOP_ERROR_DETAIL_INDENT}${fixLine}`));
|
|
16674
16903
|
if (renderEverySite && isAgentEnvironment) {
|
|
16675
16904
|
const fixRecipeLine = formatFixRecipeLine(representative);
|
|
@@ -16677,7 +16906,7 @@ const buildRuleDetailBlock = (ruleKey, ruleDiagnostics, resolveSourceRoot, rende
|
|
|
16677
16906
|
}
|
|
16678
16907
|
const renderCodeFrame = severity === "error";
|
|
16679
16908
|
const sites = renderEverySite ? ruleDiagnostics : [representative];
|
|
16680
|
-
for (const cluster of clusterNearbyDiagnostics(sites)) lines.push(...buildDiagnosticClusterLines(cluster, resolveSourceRoot, renderCodeFrame));
|
|
16909
|
+
if (!(isCollapsedWarningGroup && representative.help.includes(representative.filePath))) for (const cluster of clusterNearbyDiagnostics(sites)) lines.push(...buildDiagnosticClusterLines(cluster, resolveSourceRoot, renderCodeFrame));
|
|
16681
16910
|
return lines;
|
|
16682
16911
|
};
|
|
16683
16912
|
const selectErrorRuleGroups = (diagnostics, rulePriority) => buildSortedRuleGroups(diagnostics.filter((diagnostic) => diagnostic.severity === "error"), rulePriority);
|
|
@@ -16806,6 +17035,9 @@ const computeProjectedScore = async (topErrorSource, rescoreSource, currentScore
|
|
|
16806
17035
|
if (!potentialScore || potentialScore.score <= currentScore.score) return null;
|
|
16807
17036
|
return potentialScore.score;
|
|
16808
17037
|
};
|
|
17038
|
+
//#endregion
|
|
17039
|
+
//#region src/cli/utils/filter-diagnostics-by-categories.ts
|
|
17040
|
+
const filterDiagnosticsByCategories = (diagnostics, categories) => categories.size === 0 ? [...diagnostics] : diagnostics.filter((diagnostic) => categories.has(diagnostic.category));
|
|
16809
17041
|
const FORCE_ONBOARDING_ENV_VAR = "REACT_DOCTOR_FORCE_ONBOARDING";
|
|
16810
17042
|
const FALSY_FLAG_VALUES = new Set([
|
|
16811
17043
|
"",
|
|
@@ -17236,11 +17468,259 @@ const resolveOxlintNodeEffect = (isLintEnabled, isQuiet) => Effect.gen(function*
|
|
|
17236
17468
|
});
|
|
17237
17469
|
const resolveOxlintNode = (isLintEnabled, isQuiet) => Effect.runPromise(resolveOxlintNodeEffect(isLintEnabled, isQuiet).pipe(Effect.provide(NodeResolver.layerNode)));
|
|
17238
17470
|
//#endregion
|
|
17471
|
+
//#region src/cli/utils/cli-input-error.ts
|
|
17472
|
+
/**
|
|
17473
|
+
* A mistake in *how the CLI was invoked* — a malformed `<file>:<line>`
|
|
17474
|
+
* argument, mutually exclusive flags, or an unknown `--project` name. This is
|
|
17475
|
+
* user input, not a react-doctor bug, so `isExpectedUserError` routes it
|
|
17476
|
+
* through `handleUserError`: a clean, single-line message with no Sentry
|
|
17477
|
+
* report and no "Something went wrong, open a prefilled issue" block.
|
|
17478
|
+
*
|
|
17479
|
+
* The `message` is rendered verbatim, so it must read as a complete,
|
|
17480
|
+
* human-readable sentence that tells the user how to fix their invocation.
|
|
17481
|
+
*/
|
|
17482
|
+
var CliInputError = class extends Error {
|
|
17483
|
+
name = "CliInputError";
|
|
17484
|
+
};
|
|
17485
|
+
//#endregion
|
|
17486
|
+
//#region src/cli/utils/resolve-cli-categories.ts
|
|
17487
|
+
const categoryByLowercase = new Map(DIAGNOSTIC_CATEGORY_BUCKETS.map((category) => [category.toLowerCase(), category]));
|
|
17488
|
+
const knownCategoryList = DIAGNOSTIC_CATEGORY_BUCKETS.join(", ");
|
|
17489
|
+
const splitCategoryFlagValue = (value) => value.split(",").map((category) => category.trim()).filter((category) => category.length > 0);
|
|
17490
|
+
const resolveCliCategories = (categoryFlag) => {
|
|
17491
|
+
const rawCategoryValues = categoryFlag === void 0 ? [] : Array.isArray(categoryFlag) ? categoryFlag : [categoryFlag];
|
|
17492
|
+
const resolvedCategories = [];
|
|
17493
|
+
const seenCategories = /* @__PURE__ */ new Set();
|
|
17494
|
+
for (const rawCategoryValue of rawCategoryValues) for (const categoryQuery of splitCategoryFlagValue(rawCategoryValue)) {
|
|
17495
|
+
const matchedCategory = categoryByLowercase.get(categoryQuery.toLowerCase());
|
|
17496
|
+
if (matchedCategory === void 0) throw new CliInputError(`Unknown category "${categoryQuery}". Expected one of: ${knownCategoryList}.`);
|
|
17497
|
+
if (!seenCategories.has(matchedCategory)) {
|
|
17498
|
+
seenCategories.add(matchedCategory);
|
|
17499
|
+
resolvedCategories.push(matchedCategory);
|
|
17500
|
+
}
|
|
17501
|
+
}
|
|
17502
|
+
if (rawCategoryValues.length > 0 && resolvedCategories.length === 0) throw new CliInputError(`--category requires one of: ${knownCategoryList}.`);
|
|
17503
|
+
return resolvedCategories.length > 0 ? resolvedCategories : void 0;
|
|
17504
|
+
};
|
|
17505
|
+
//#endregion
|
|
17506
|
+
//#region src/cli/utils/scan-result-cache.ts
|
|
17507
|
+
const CACHE_DISABLED_VALUES = new Set(["1", "true"]);
|
|
17508
|
+
const TOOLCHAIN_PACKAGE_SPECIFIERS = [
|
|
17509
|
+
"oxlint",
|
|
17510
|
+
"oxlint/package.json",
|
|
17511
|
+
"oxlint-plugin-react-doctor",
|
|
17512
|
+
"deslop-js/package.json",
|
|
17513
|
+
"eslint-plugin-react-hooks/package.json"
|
|
17514
|
+
];
|
|
17515
|
+
const bundledRequire = createRequire(import.meta.url);
|
|
17516
|
+
const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17517
|
+
const normalizeForStableJson = (value) => {
|
|
17518
|
+
if (value === null) return null;
|
|
17519
|
+
if (value === void 0) return void 0;
|
|
17520
|
+
const valueType = typeof value;
|
|
17521
|
+
if (valueType === "string" || valueType === "number" || valueType === "boolean") return value;
|
|
17522
|
+
if (valueType === "bigint" || valueType === "function" || valueType === "symbol") throw new Error("Unsupported cache key value");
|
|
17523
|
+
if (Array.isArray(value)) return value.map((item) => {
|
|
17524
|
+
const normalized = normalizeForStableJson(item);
|
|
17525
|
+
return normalized === void 0 ? null : normalized;
|
|
17526
|
+
});
|
|
17527
|
+
const prototype = Object.getPrototypeOf(value);
|
|
17528
|
+
if (prototype !== Object.prototype && prototype !== null) throw new Error("Unsupported cache key object");
|
|
17529
|
+
const record = value;
|
|
17530
|
+
const normalizedRecord = {};
|
|
17531
|
+
for (const key of Object.keys(record).sort()) {
|
|
17532
|
+
const normalized = normalizeForStableJson(record[key]);
|
|
17533
|
+
if (normalized !== void 0) normalizedRecord[key] = normalized;
|
|
17534
|
+
}
|
|
17535
|
+
return normalizedRecord;
|
|
17536
|
+
};
|
|
17537
|
+
const stringifyStableJson = (value) => {
|
|
17538
|
+
try {
|
|
17539
|
+
return JSON.stringify(normalizeForStableJson(value));
|
|
17540
|
+
} catch {
|
|
17541
|
+
return null;
|
|
17542
|
+
}
|
|
17543
|
+
};
|
|
17544
|
+
const hashString = (value) => crypto.createHash("sha1").update(value).digest("hex");
|
|
17545
|
+
const runGit$1 = (directory, args) => {
|
|
17546
|
+
try {
|
|
17547
|
+
return execFileSync("git", [...args], {
|
|
17548
|
+
cwd: directory,
|
|
17549
|
+
encoding: "utf8",
|
|
17550
|
+
stdio: [
|
|
17551
|
+
"ignore",
|
|
17552
|
+
"pipe",
|
|
17553
|
+
"ignore"
|
|
17554
|
+
]
|
|
17555
|
+
}).trim();
|
|
17556
|
+
} catch {
|
|
17557
|
+
return null;
|
|
17558
|
+
}
|
|
17559
|
+
};
|
|
17560
|
+
const readHeadSha = (projectDirectory) => runGit$1(projectDirectory, ["rev-parse", "HEAD"]);
|
|
17561
|
+
const isWorktreeClean = (projectDirectory) => {
|
|
17562
|
+
const status = runGit$1(projectDirectory, [
|
|
17563
|
+
"status",
|
|
17564
|
+
"--porcelain=v1",
|
|
17565
|
+
"--untracked-files=normal"
|
|
17566
|
+
]);
|
|
17567
|
+
return status !== null && status.length === 0;
|
|
17568
|
+
};
|
|
17569
|
+
const hasHiddenTrackedFileState = (projectDirectory) => {
|
|
17570
|
+
const output = runGit$1(projectDirectory, ["ls-files", "-v"]);
|
|
17571
|
+
if (output === null) return true;
|
|
17572
|
+
return output.split("\n").some((line) => line.length > 0 && line[0] !== "H");
|
|
17573
|
+
};
|
|
17574
|
+
const resolveCacheFilePath = (projectDirectory) => {
|
|
17575
|
+
const nodeModulesDirectory = path.join(projectDirectory, "node_modules");
|
|
17576
|
+
if (fs.existsSync(nodeModulesDirectory)) return path.join(nodeModulesDirectory, ".cache", "react-doctor", "scan-cache.json");
|
|
17577
|
+
const projectHash = hashString(projectDirectory).slice(0, 16);
|
|
17578
|
+
return path.join(os.tmpdir(), "react-doctor-cache", `scan-${projectHash}.json`);
|
|
17579
|
+
};
|
|
17580
|
+
const readPersistedCache = (cacheFilePath) => {
|
|
17581
|
+
try {
|
|
17582
|
+
const parsed = JSON.parse(fs.readFileSync(cacheFilePath, "utf8"));
|
|
17583
|
+
if (!isRecord$1(parsed) || parsed.version !== 1) return {
|
|
17584
|
+
version: 1,
|
|
17585
|
+
entries: []
|
|
17586
|
+
};
|
|
17587
|
+
if (!Array.isArray(parsed.entries)) return {
|
|
17588
|
+
version: 1,
|
|
17589
|
+
entries: []
|
|
17590
|
+
};
|
|
17591
|
+
const entries = [];
|
|
17592
|
+
for (const entry of parsed.entries) {
|
|
17593
|
+
if (!isRecord$1(entry) || typeof entry.key !== "string" || typeof entry.createdAtMs !== "number") continue;
|
|
17594
|
+
if (!isRecord$1(entry.payload) || !Array.isArray(entry.payload.diagnostics)) continue;
|
|
17595
|
+
entries.push(entry);
|
|
17596
|
+
}
|
|
17597
|
+
return {
|
|
17598
|
+
version: 1,
|
|
17599
|
+
entries
|
|
17600
|
+
};
|
|
17601
|
+
} catch {
|
|
17602
|
+
return {
|
|
17603
|
+
version: 1,
|
|
17604
|
+
entries: []
|
|
17605
|
+
};
|
|
17606
|
+
}
|
|
17607
|
+
};
|
|
17608
|
+
const writePersistedCache = (cacheFilePath, cache) => {
|
|
17609
|
+
try {
|
|
17610
|
+
fs.mkdirSync(path.dirname(cacheFilePath), { recursive: true });
|
|
17611
|
+
const tempPath = `${cacheFilePath}.${process.pid}.tmp`;
|
|
17612
|
+
fs.writeFileSync(tempPath, JSON.stringify(cache));
|
|
17613
|
+
fs.renameSync(tempPath, cacheFilePath);
|
|
17614
|
+
} catch {
|
|
17615
|
+
return;
|
|
17616
|
+
}
|
|
17617
|
+
};
|
|
17618
|
+
const isScanResultCacheDisabled = () => CACHE_DISABLED_VALUES.has(process.env.REACT_DOCTOR_NO_CACHE?.toLowerCase() ?? "");
|
|
17619
|
+
const resolveProjectIdentity = (projectDirectory) => {
|
|
17620
|
+
try {
|
|
17621
|
+
return fs.realpathSync.native(projectDirectory);
|
|
17622
|
+
} catch {
|
|
17623
|
+
return path.resolve(projectDirectory);
|
|
17624
|
+
}
|
|
17625
|
+
};
|
|
17626
|
+
const fileFingerprint = (filePath) => {
|
|
17627
|
+
try {
|
|
17628
|
+
const stat = fs.statSync(filePath);
|
|
17629
|
+
return `${filePath}:${stat.mtimeMs}:${stat.size}`;
|
|
17630
|
+
} catch {
|
|
17631
|
+
return null;
|
|
17632
|
+
}
|
|
17633
|
+
};
|
|
17634
|
+
const resolveToolchainFingerprint = (nodeBinaryPath) => {
|
|
17635
|
+
const fingerprints = [];
|
|
17636
|
+
if (nodeBinaryPath !== null) {
|
|
17637
|
+
const fingerprint = fileFingerprint(nodeBinaryPath);
|
|
17638
|
+
if (fingerprint !== null) fingerprints.push(`node=${fingerprint}`);
|
|
17639
|
+
}
|
|
17640
|
+
for (const specifier of TOOLCHAIN_PACKAGE_SPECIFIERS) try {
|
|
17641
|
+
const fingerprint = fileFingerprint(bundledRequire.resolve(specifier));
|
|
17642
|
+
if (fingerprint !== null) fingerprints.push(`${specifier}=${fingerprint}`);
|
|
17643
|
+
} catch {
|
|
17644
|
+
continue;
|
|
17645
|
+
}
|
|
17646
|
+
return fingerprints;
|
|
17647
|
+
};
|
|
17648
|
+
const buildScanResultCacheKey = (input) => {
|
|
17649
|
+
if (isScanResultCacheDisabled()) return null;
|
|
17650
|
+
if (!isWorktreeClean(input.projectDirectory)) return null;
|
|
17651
|
+
if (hasHiddenTrackedFileState(input.projectDirectory)) return null;
|
|
17652
|
+
const headSha = readHeadSha(input.projectDirectory);
|
|
17653
|
+
if (headSha === null) return null;
|
|
17654
|
+
if (stringifyStableJson(input.userConfig) === null) return null;
|
|
17655
|
+
const cacheKeyJson = stringifyStableJson({
|
|
17656
|
+
schemaVersion: 1,
|
|
17657
|
+
projectIdentity: resolveProjectIdentity(input.projectDirectory),
|
|
17658
|
+
headSha,
|
|
17659
|
+
reactDoctorVersion: input.version,
|
|
17660
|
+
nodeVersion: process.version,
|
|
17661
|
+
toolchainFingerprint: resolveToolchainFingerprint(input.nodeBinaryPath),
|
|
17662
|
+
configFingerprint: computeConfigFingerprint(input.projectDirectory, input.version),
|
|
17663
|
+
hasConfigOverride: input.hasConfigOverride,
|
|
17664
|
+
configSourceDirectory: input.configSourceDirectory,
|
|
17665
|
+
userConfig: input.userConfig,
|
|
17666
|
+
engineOptions: {
|
|
17667
|
+
lint: input.options.lint,
|
|
17668
|
+
deadCode: input.options.deadCode,
|
|
17669
|
+
includePaths: [...input.options.includePaths].sort(),
|
|
17670
|
+
customRulesOnly: input.options.customRulesOnly,
|
|
17671
|
+
respectInlineDisables: input.options.respectInlineDisables,
|
|
17672
|
+
warnings: input.options.warnings,
|
|
17673
|
+
adoptExistingLintConfig: input.options.adoptExistingLintConfig,
|
|
17674
|
+
ignoredTags: [...input.options.ignoredTags].sort(),
|
|
17675
|
+
concurrency: input.options.concurrency,
|
|
17676
|
+
baselineRef: input.options.baseline?.ref,
|
|
17677
|
+
noScore: input.options.noScore,
|
|
17678
|
+
isCi: input.options.isCi,
|
|
17679
|
+
suppressRendering: input.options.suppressRendering
|
|
17680
|
+
}
|
|
17681
|
+
});
|
|
17682
|
+
return cacheKeyJson === null ? null : hashString(cacheKeyJson);
|
|
17683
|
+
};
|
|
17684
|
+
const createScanResultCache = (projectDirectory) => {
|
|
17685
|
+
const cacheFilePath = resolveCacheFilePath(projectDirectory);
|
|
17686
|
+
const persistedCache = readPersistedCache(cacheFilePath);
|
|
17687
|
+
const entries = /* @__PURE__ */ new Map();
|
|
17688
|
+
for (const entry of persistedCache.entries) entries.set(entry.key, entry);
|
|
17689
|
+
const persist = () => {
|
|
17690
|
+
writePersistedCache(cacheFilePath, {
|
|
17691
|
+
version: 1,
|
|
17692
|
+
entries: [...entries.values()].sort((firstEntry, secondEntry) => secondEntry.createdAtMs - firstEntry.createdAtMs).slice(0, 20)
|
|
17693
|
+
});
|
|
17694
|
+
};
|
|
17695
|
+
return {
|
|
17696
|
+
lookup: (key) => entries.get(key)?.payload ?? null,
|
|
17697
|
+
store: (key, payload) => {
|
|
17698
|
+
entries.set(key, {
|
|
17699
|
+
key,
|
|
17700
|
+
createdAtMs: Date.now(),
|
|
17701
|
+
payload
|
|
17702
|
+
});
|
|
17703
|
+
persist();
|
|
17704
|
+
}
|
|
17705
|
+
};
|
|
17706
|
+
};
|
|
17707
|
+
const shouldStoreScanPayload = (payload) => !payload.didLintFail && !payload.didDeadCodeFail && payload.lintPartialFailures.length === 0;
|
|
17708
|
+
//#endregion
|
|
17239
17709
|
//#region src/inspect.ts
|
|
17240
17710
|
const silentConsole = makeNoopConsole();
|
|
17241
17711
|
const runConsole = (effect) => {
|
|
17242
17712
|
Effect.runSync(effect);
|
|
17243
17713
|
};
|
|
17714
|
+
const recordOnboardingCompletion = (options) => {
|
|
17715
|
+
const forceOnboarding = isOnboardingForced();
|
|
17716
|
+
if (shouldRecordOnboarding({
|
|
17717
|
+
paceOnboardingSections: !options.silent && !options.scoreOnly && !options.suppressRendering && !options.verbose && canAnimateOnboarding(process.stdout) && (forceOnboarding || !hasCompletedOnboarding()),
|
|
17718
|
+
forceOnboarding,
|
|
17719
|
+
verbose: options.verbose,
|
|
17720
|
+
isNonInteractiveEnvironment: options.isNonInteractiveEnvironment
|
|
17721
|
+
})) markOnboardingComplete();
|
|
17722
|
+
};
|
|
17723
|
+
const formatCategorySelection = (categoryFilters) => [...categoryFilters].join(", ");
|
|
17244
17724
|
const buildIgnoredTags = (userConfig) => {
|
|
17245
17725
|
const tags = /* @__PURE__ */ new Set();
|
|
17246
17726
|
if (userConfig?.ignore?.tags) for (const tag of userConfig.ignore.tags) tags.add(tag);
|
|
@@ -17261,6 +17741,7 @@ const mergeInspectOptions = (inputOptions, userConfig) => ({
|
|
|
17261
17741
|
share: userConfig?.share ?? true,
|
|
17262
17742
|
respectInlineDisables: inputOptions.respectInlineDisables ?? userConfig?.respectInlineDisables ?? true,
|
|
17263
17743
|
warnings: inputOptions.warnings ?? userConfig?.warnings ?? true,
|
|
17744
|
+
categoryFilters: new Set(resolveCliCategories(inputOptions.categoryFilters) ?? []),
|
|
17264
17745
|
adoptExistingLintConfig: userConfig?.adoptExistingLintConfig ?? true,
|
|
17265
17746
|
ignoredTags: buildIgnoredTags(userConfig),
|
|
17266
17747
|
outputSurface: inputOptions.outputSurface ?? "cli",
|
|
@@ -17347,6 +17828,7 @@ const runBaselineComparison = async (params) => {
|
|
|
17347
17828
|
hasConfigOverride: true,
|
|
17348
17829
|
userConfig: params.userConfig,
|
|
17349
17830
|
configSourceDirectory: null,
|
|
17831
|
+
projectInfoOverride: params.headProjectInfo,
|
|
17350
17832
|
shouldSkipLint: !params.options.lint || !params.resolvedNodeBinaryPath,
|
|
17351
17833
|
shouldRunDeadCode: false,
|
|
17352
17834
|
shouldComputeScore: false,
|
|
@@ -17393,6 +17875,40 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
17393
17875
|
const isDiffMode = options.includePaths.length > 0;
|
|
17394
17876
|
const resolvedNodeBinaryPath = await resolveOxlintNode(options.lint, options.scoreOnly || options.silent);
|
|
17395
17877
|
const lintBindingMissing = options.lint && !resolvedNodeBinaryPath;
|
|
17878
|
+
const cacheKey = buildScanResultCacheKey({
|
|
17879
|
+
projectDirectory: directory,
|
|
17880
|
+
version: VERSION,
|
|
17881
|
+
nodeBinaryPath: resolvedNodeBinaryPath,
|
|
17882
|
+
options,
|
|
17883
|
+
userConfig,
|
|
17884
|
+
hasConfigOverride,
|
|
17885
|
+
configSourceDirectory
|
|
17886
|
+
});
|
|
17887
|
+
const scanResultCache = cacheKey === null ? null : createScanResultCache(directory);
|
|
17888
|
+
const cachedPayload = cacheKey === null ? null : scanResultCache?.lookup(cacheKey) ?? null;
|
|
17889
|
+
if (cachedPayload) {
|
|
17890
|
+
recordSentryProjectContext(cachedPayload.project, rootSentrySpan);
|
|
17891
|
+
recordCount(METRIC.projectDetected, 1);
|
|
17892
|
+
await renderCachedProjectDetection({
|
|
17893
|
+
payload: cachedPayload,
|
|
17894
|
+
options,
|
|
17895
|
+
userConfig,
|
|
17896
|
+
isDiffMode
|
|
17897
|
+
});
|
|
17898
|
+
const baselineDegraded = Boolean(options.baseline) && isDiffMode && cachedPayload.baselineDelta === void 0;
|
|
17899
|
+
const result = await renderAndRecordScan({
|
|
17900
|
+
payload: cachedPayload,
|
|
17901
|
+
options,
|
|
17902
|
+
userConfig,
|
|
17903
|
+
hasCustomConfig: userConfig !== null,
|
|
17904
|
+
startTime,
|
|
17905
|
+
rootSentrySpan,
|
|
17906
|
+
scanMode: cachedPayload.baselineDelta ? "baseline" : isDiffMode ? "diff" : "full",
|
|
17907
|
+
baselineDegraded
|
|
17908
|
+
});
|
|
17909
|
+
recordOnboardingCompletion(options);
|
|
17910
|
+
return result;
|
|
17911
|
+
}
|
|
17396
17912
|
const shouldShowProgressSpinners = !options.isCiOrCodingAgentEnvironment && !options.silent && !options.scoreOnly && options.lint && Boolean(resolvedNodeBinaryPath);
|
|
17397
17913
|
const layers = buildRuntimeLayers({
|
|
17398
17914
|
directory,
|
|
@@ -17446,6 +17962,7 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
17446
17962
|
directory,
|
|
17447
17963
|
options,
|
|
17448
17964
|
userConfig,
|
|
17965
|
+
headProjectInfo: output.project,
|
|
17449
17966
|
headDiagnostics: output.diagnostics,
|
|
17450
17967
|
resolvedNodeBinaryPath,
|
|
17451
17968
|
baselineRef: options.baseline.ref
|
|
@@ -17457,12 +17974,7 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
17457
17974
|
}
|
|
17458
17975
|
const baselineDegraded = Boolean(options.baseline) && isDiffMode && baselineDelta === void 0;
|
|
17459
17976
|
const score = didLintFail ? null : output.score;
|
|
17460
|
-
const
|
|
17461
|
-
const forceOnboarding = isOnboardingForced();
|
|
17462
|
-
const paceOnboardingSections = !options.silent && !options.scoreOnly && !options.suppressRendering && !options.verbose && canAnimateOnboarding(process.stdout) && (forceOnboarding || !hasCompletedOnboarding());
|
|
17463
|
-
const finalizeInput = {
|
|
17464
|
-
options,
|
|
17465
|
-
elapsedMilliseconds,
|
|
17977
|
+
const payload = {
|
|
17466
17978
|
diagnostics: inspectDiagnostics,
|
|
17467
17979
|
score,
|
|
17468
17980
|
project: output.project,
|
|
@@ -17476,39 +17988,77 @@ const runInspectWithRuntime = async (directory, options, userConfig, hasConfigOv
|
|
|
17476
17988
|
scannedFileCount: output.scannedFileCount,
|
|
17477
17989
|
scannedFilePaths: output.scannedFilePaths,
|
|
17478
17990
|
scanElapsedMilliseconds: output.scanElapsedMilliseconds,
|
|
17479
|
-
baselineDelta
|
|
17991
|
+
baselineDelta,
|
|
17992
|
+
lintFailureReasonKind: lintBindingMissing ? "native-binding-missing" : output.lintFailureReasonKind
|
|
17480
17993
|
};
|
|
17481
|
-
|
|
17482
|
-
|
|
17483
|
-
|
|
17484
|
-
|
|
17485
|
-
|
|
17486
|
-
|
|
17487
|
-
|
|
17488
|
-
|
|
17994
|
+
if (cacheKey !== null && scanResultCache !== null && shouldStoreScanPayload(payload)) scanResultCache.store(cacheKey, payload);
|
|
17995
|
+
const result = await renderAndRecordScan({
|
|
17996
|
+
payload,
|
|
17997
|
+
options,
|
|
17998
|
+
userConfig,
|
|
17999
|
+
hasCustomConfig: userConfig !== null,
|
|
18000
|
+
startTime,
|
|
18001
|
+
rootSentrySpan,
|
|
18002
|
+
scanMode: baselineDelta ? "baseline" : isDiffMode ? "diff" : "full",
|
|
18003
|
+
baselineDegraded
|
|
18004
|
+
});
|
|
18005
|
+
recordOnboardingCompletion(options);
|
|
18006
|
+
return result;
|
|
18007
|
+
};
|
|
18008
|
+
const runMaybeSilent = (effect, silent) => silent ? effect.pipe(Effect.provideService(Console.Console, silentConsole)) : effect;
|
|
18009
|
+
const renderCachedProjectDetection = async (input) => {
|
|
18010
|
+
if (input.options.scoreOnly || input.options.suppressRendering) return;
|
|
18011
|
+
await Effect.runPromise(runMaybeSilent(printProjectDetection({
|
|
18012
|
+
projectInfo: input.payload.project,
|
|
18013
|
+
userConfig: input.userConfig,
|
|
18014
|
+
isDiffMode: input.isDiffMode,
|
|
18015
|
+
includePaths: input.options.includePaths,
|
|
18016
|
+
lintSourceFileCount: input.payload.scannedFileCount
|
|
18017
|
+
}), input.options.silent));
|
|
18018
|
+
};
|
|
18019
|
+
const renderAndRecordScan = async (input) => {
|
|
18020
|
+
const finalizeInput = {
|
|
18021
|
+
options: input.options,
|
|
18022
|
+
elapsedMilliseconds: performance.now() - input.startTime,
|
|
18023
|
+
diagnostics: input.payload.diagnostics,
|
|
18024
|
+
score: input.payload.score,
|
|
18025
|
+
project: input.payload.project,
|
|
18026
|
+
userConfig: input.payload.userConfig,
|
|
18027
|
+
didLintFail: input.payload.didLintFail,
|
|
18028
|
+
lintFailureReason: input.payload.lintFailureReason,
|
|
18029
|
+
lintPartialFailures: input.payload.lintPartialFailures,
|
|
18030
|
+
didDeadCodeFail: input.payload.didDeadCodeFail,
|
|
18031
|
+
deadCodeFailureReason: input.payload.deadCodeFailureReason,
|
|
18032
|
+
directory: input.payload.directory,
|
|
18033
|
+
scannedFileCount: input.payload.scannedFileCount,
|
|
18034
|
+
scannedFilePaths: input.payload.scannedFilePaths,
|
|
18035
|
+
scanElapsedMilliseconds: input.payload.scanElapsedMilliseconds,
|
|
18036
|
+
baselineDelta: input.payload.baselineDelta
|
|
18037
|
+
};
|
|
18038
|
+
const result = await Effect.runPromise(runMaybeSilent(finalizeAndRender(finalizeInput), input.options.silent));
|
|
17489
18039
|
recordScanMetrics({
|
|
17490
18040
|
result,
|
|
17491
|
-
mode: scanMode,
|
|
17492
|
-
baselineDegraded,
|
|
17493
|
-
parallel: options.concurrency !== void 0,
|
|
17494
|
-
workerCount: options.concurrency,
|
|
17495
|
-
lint: options.lint,
|
|
17496
|
-
deadCode: options.deadCode,
|
|
17497
|
-
scoreOnly: options.scoreOnly,
|
|
17498
|
-
noScore: options.noScore,
|
|
17499
|
-
didLintFail,
|
|
17500
|
-
lintFailureReasonKind:
|
|
17501
|
-
didDeadCodeFail:
|
|
18041
|
+
mode: input.scanMode,
|
|
18042
|
+
baselineDegraded: input.baselineDegraded,
|
|
18043
|
+
parallel: input.options.concurrency !== void 0,
|
|
18044
|
+
workerCount: input.options.concurrency,
|
|
18045
|
+
lint: input.options.lint,
|
|
18046
|
+
deadCode: input.options.deadCode,
|
|
18047
|
+
scoreOnly: input.options.scoreOnly,
|
|
18048
|
+
noScore: input.options.noScore,
|
|
18049
|
+
didLintFail: input.payload.didLintFail,
|
|
18050
|
+
lintFailureReasonKind: input.payload.lintFailureReasonKind,
|
|
18051
|
+
didDeadCodeFail: input.payload.didDeadCodeFail
|
|
17502
18052
|
});
|
|
17503
|
-
recordRunEvent(rootSentrySpan, {
|
|
17504
|
-
...buildRunEventConfig(options, userConfig,
|
|
18053
|
+
recordRunEvent(input.rootSentrySpan, {
|
|
18054
|
+
...buildRunEventConfig(input.options, input.userConfig, input.hasCustomConfig),
|
|
17505
18055
|
result,
|
|
17506
|
-
mode: scanMode,
|
|
17507
|
-
gateExempt: baselineDegraded,
|
|
17508
|
-
didLintFail,
|
|
17509
|
-
lintFailureReasonKind:
|
|
17510
|
-
lintPartialFailureCount:
|
|
17511
|
-
didDeadCodeFail:
|
|
18056
|
+
mode: input.scanMode,
|
|
18057
|
+
gateExempt: input.baselineDegraded,
|
|
18058
|
+
didLintFail: input.payload.didLintFail,
|
|
18059
|
+
lintFailureReasonKind: input.payload.lintFailureReasonKind,
|
|
18060
|
+
lintPartialFailureCount: input.payload.lintPartialFailures.length,
|
|
18061
|
+
didDeadCodeFail: input.payload.didDeadCodeFail
|
|
17512
18062
|
});
|
|
17513
18063
|
return result;
|
|
17514
18064
|
};
|
|
@@ -17544,14 +18094,16 @@ const finalizeAndRender = (input) => Effect.gen(function* () {
|
|
|
17544
18094
|
const animateRender = !options.silent && !options.verbose && canAnimateOnboarding(process.stdout);
|
|
17545
18095
|
const pause = onboardingSectionPause(animateRender);
|
|
17546
18096
|
const surfaceDiagnostics = filterDiagnosticsForSurface([...diagnostics], options.outputSurface, userConfig);
|
|
18097
|
+
const printedDiagnostics = filterDiagnosticsByCategories(surfaceDiagnostics, options.categoryFilters);
|
|
17547
18098
|
const demotedDiagnosticCount = diagnostics.length - surfaceDiagnostics.length;
|
|
17548
18099
|
const lintSourceFileCount = options.includePaths.length > 0 ? options.includePaths.length : project.sourceFileCount;
|
|
17549
|
-
if (
|
|
18100
|
+
if (printedDiagnostics.length === 0) {
|
|
17550
18101
|
yield* pause;
|
|
17551
18102
|
if (hasSkippedChecks) {
|
|
17552
18103
|
const skippedLabel = skippedChecks.join(" and ");
|
|
17553
18104
|
yield* Console.warn(highlighter.warn(`No issues detected, but ${skippedLabel} checks failed — results are incomplete.`));
|
|
17554
|
-
} else if (
|
|
18105
|
+
} else if (options.categoryFilters.size > 0) yield* Console.log(highlighter.success(`No issues found in category ${formatCategorySelection(options.categoryFilters)}!`));
|
|
18106
|
+
else if (demotedDiagnosticCount > 0) yield* Console.log(highlighter.success(`No issues found! (${demotedDiagnosticCount} demoted from the ${options.outputSurface} surface — see config.surfaces.)`));
|
|
17555
18107
|
else yield* Console.log(highlighter.success("No issues found!"));
|
|
17556
18108
|
yield* Console.log("");
|
|
17557
18109
|
yield* pause;
|
|
@@ -17564,20 +18116,20 @@ const finalizeAndRender = (input) => Effect.gen(function* () {
|
|
|
17564
18116
|
}
|
|
17565
18117
|
yield* pause;
|
|
17566
18118
|
yield* Console.log("");
|
|
17567
|
-
yield* printDiagnostics([...
|
|
18119
|
+
yield* printDiagnostics([...printedDiagnostics], options.verbose, directory, buildRulePriorityMap([score]), isCodingAgentEnvironment(), {
|
|
17568
18120
|
sectionPause: pause,
|
|
17569
18121
|
animateCountUp: animateRender
|
|
17570
18122
|
});
|
|
17571
18123
|
if (options.isNonInteractiveEnvironment && options.outputSurface !== "prComment") yield* printAgentGuidance();
|
|
17572
|
-
if (demotedDiagnosticCount > 0) {
|
|
18124
|
+
if (options.categoryFilters.size === 0 && demotedDiagnosticCount > 0) {
|
|
17573
18125
|
yield* Console.log(highlighter.gray(` ${demotedDiagnosticCount} demoted from the ${options.outputSurface} surface (e.g. design cleanup) — run \`npx react-doctor@latest .\` locally for the full list.`));
|
|
17574
18126
|
yield* Console.log("");
|
|
17575
18127
|
}
|
|
17576
|
-
const potentialScore = score ? yield* Effect.promise(() => computeProjectedScore([...
|
|
18128
|
+
const potentialScore = score ? yield* Effect.promise(() => computeProjectedScore([...printedDiagnostics], [...surfaceDiagnostics], score)) : null;
|
|
17577
18129
|
const shouldShowShareLink = !options.noScore && options.share && !options.isCi;
|
|
17578
18130
|
yield* pause;
|
|
17579
18131
|
yield* printSummary({
|
|
17580
|
-
diagnostics: [...
|
|
18132
|
+
diagnostics: [...printedDiagnostics],
|
|
17581
18133
|
elapsedMilliseconds,
|
|
17582
18134
|
scoreResult: score,
|
|
17583
18135
|
potentialScore,
|
|
@@ -17593,7 +18145,7 @@ const finalizeAndRender = (input) => Effect.gen(function* () {
|
|
|
17593
18145
|
}
|
|
17594
18146
|
yield* pause;
|
|
17595
18147
|
yield* printFooter({
|
|
17596
|
-
diagnostics: [...
|
|
18148
|
+
diagnostics: [...printedDiagnostics],
|
|
17597
18149
|
scoreResult: score,
|
|
17598
18150
|
projectName: project.projectName,
|
|
17599
18151
|
isOffline: !shouldShowShareLink
|
|
@@ -17724,21 +18276,6 @@ const handleUserError = (error, options = {}) => {
|
|
|
17724
18276
|
process.exitCode = 1;
|
|
17725
18277
|
};
|
|
17726
18278
|
//#endregion
|
|
17727
|
-
//#region src/cli/utils/cli-input-error.ts
|
|
17728
|
-
/**
|
|
17729
|
-
* A mistake in *how the CLI was invoked* — a malformed `<file>:<line>`
|
|
17730
|
-
* argument, mutually exclusive flags, or an unknown `--project` name. This is
|
|
17731
|
-
* user input, not a react-doctor bug, so `isExpectedUserError` routes it
|
|
17732
|
-
* through `handleUserError`: a clean, single-line message with no Sentry
|
|
17733
|
-
* report and no "Something went wrong, open a prefilled issue" block.
|
|
17734
|
-
*
|
|
17735
|
-
* The `message` is rendered verbatim, so it must read as a complete,
|
|
17736
|
-
* human-readable sentence that tells the user how to fix their invocation.
|
|
17737
|
-
*/
|
|
17738
|
-
var CliInputError = class extends Error {
|
|
17739
|
-
name = "CliInputError";
|
|
17740
|
-
};
|
|
17741
|
-
//#endregion
|
|
17742
18279
|
//#region src/cli/utils/is-expected-user-error.ts
|
|
17743
18280
|
/**
|
|
17744
18281
|
* Whether `error` is an expected, user-actionable failure — the user's project
|
|
@@ -19927,8 +20464,9 @@ const findLowestScoredScan = (completedScans) => {
|
|
|
19927
20464
|
};
|
|
19928
20465
|
const printMultiProjectSummary = (input) => Effect.gen(function* () {
|
|
19929
20466
|
const { completedScans, userConfig, verbose, isOffline, projectName } = input;
|
|
20467
|
+
const categoryFilters = input.categoryFilters ?? /* @__PURE__ */ new Set();
|
|
19930
20468
|
const animateRender = !verbose && canAnimateOnboarding(process.stdout);
|
|
19931
|
-
const
|
|
20469
|
+
const displayDiagnostics = filterDiagnosticsByCategories(filterDiagnosticsForSurface(completedScans.flatMap((scan) => scan.result.diagnostics), "cli", userConfig), categoryFilters);
|
|
19932
20470
|
const projectRootByDiagnostic = /* @__PURE__ */ new WeakMap();
|
|
19933
20471
|
for (const scan of completedScans) for (const diagnostic of scan.result.diagnostics) projectRootByDiagnostic.set(diagnostic, scan.result.project.rootDirectory);
|
|
19934
20472
|
const resolveDiagnosticSourceRoot = (diagnostic) => projectRootByDiagnostic.get(diagnostic) ?? "";
|
|
@@ -19942,29 +20480,30 @@ const printMultiProjectSummary = (input) => Effect.gen(function* () {
|
|
|
19942
20480
|
const totalScannedFileCount = uniqueScannedFilePaths.size + fileCountFromScansWithoutPaths;
|
|
19943
20481
|
const totalScanElapsedMilliseconds = completedScans.reduce((sum, scan) => sum + (scan.result.scanElapsedMilliseconds ?? scan.result.elapsedMilliseconds), 0);
|
|
19944
20482
|
yield* Console.log(`${highlighter.success("✔")} Scanned ${totalScannedFileCount} ${totalScannedFileCount === 1 ? "file" : "files"} in ${formatElapsedTime(totalScanElapsedMilliseconds)}`);
|
|
19945
|
-
if (
|
|
20483
|
+
if (displayDiagnostics.length > 0) {
|
|
19946
20484
|
yield* Console.log("");
|
|
19947
|
-
yield* printDiagnostics(
|
|
20485
|
+
yield* printDiagnostics(displayDiagnostics, verbose, resolveDiagnosticSourceRoot, buildRulePriorityMap(completedScans.map((scan) => scan.result.score)), isCodingAgentEnvironment(), { animateCountUp: animateRender });
|
|
19948
20486
|
}
|
|
19949
20487
|
const lowestScoredScan = findLowestScoredScan(completedScans);
|
|
19950
20488
|
const aggregateScore = lowestScoredScan?.result.score ?? null;
|
|
19951
20489
|
const totalSourceFileCount = completedScans.reduce((sum, scan) => sum + scan.result.project.sourceFileCount, 0);
|
|
19952
20490
|
yield* printSummary({
|
|
19953
|
-
diagnostics:
|
|
20491
|
+
diagnostics: displayDiagnostics,
|
|
19954
20492
|
elapsedMilliseconds: completedScans.reduce((sum, scan) => sum + scan.result.elapsedMilliseconds, 0),
|
|
19955
20493
|
scoreResult: aggregateScore,
|
|
19956
|
-
potentialScore: lowestScoredScan ? yield* Effect.promise(() => computeProjectedScore(
|
|
20494
|
+
potentialScore: lowestScoredScan ? yield* Effect.promise(() => computeProjectedScore(displayDiagnostics, filterDiagnosticsForSurface(lowestScoredScan.result.diagnostics, "cli", userConfig), lowestScoredScan.result.score)) : null,
|
|
19957
20495
|
totalSourceFileCount,
|
|
19958
20496
|
noScoreMessage: "Score unavailable.",
|
|
19959
20497
|
verbose,
|
|
19960
20498
|
animateProjection: animateRender
|
|
19961
20499
|
});
|
|
19962
20500
|
const entries = completedScans.map((scan) => {
|
|
19963
|
-
const
|
|
20501
|
+
const projectDiagnostics = filterDiagnosticsByCategories(filterDiagnosticsForSurface([...scan.result.diagnostics], "cli", userConfig), categoryFilters);
|
|
20502
|
+
const errorCount = projectDiagnostics.filter((diagnostic) => diagnostic.severity === "error").length;
|
|
19964
20503
|
return {
|
|
19965
20504
|
projectName: scan.result.project.projectName,
|
|
19966
20505
|
score: scan.result.score?.score ?? null,
|
|
19967
|
-
issueCount:
|
|
20506
|
+
issueCount: projectDiagnostics.length,
|
|
19968
20507
|
errorCount
|
|
19969
20508
|
};
|
|
19970
20509
|
});
|
|
@@ -19972,7 +20511,7 @@ const printMultiProjectSummary = (input) => Effect.gen(function* () {
|
|
|
19972
20511
|
yield* Console.log("");
|
|
19973
20512
|
for (const entry of entries) yield* Console.log(buildSummaryLine(entry, longestProjectNameLength));
|
|
19974
20513
|
yield* printFooter({
|
|
19975
|
-
diagnostics:
|
|
20514
|
+
diagnostics: displayDiagnostics,
|
|
19976
20515
|
scoreResult: aggregateScore,
|
|
19977
20516
|
projectName,
|
|
19978
20517
|
isOffline
|
|
@@ -20062,7 +20601,8 @@ const resolveCliInspectOptions = (flags, userConfig) => {
|
|
|
20062
20601
|
noScore: flags.score === false || flags.telemetry === false || (userConfig?.noScore ?? false),
|
|
20063
20602
|
isCi: isCiEnvironment(),
|
|
20064
20603
|
silent: Boolean(flags.json),
|
|
20065
|
-
concurrency: resolveParallelFlag(flags.parallel)
|
|
20604
|
+
concurrency: resolveParallelFlag(flags.parallel),
|
|
20605
|
+
categoryFilters: resolveCliCategories(flags.category)
|
|
20066
20606
|
};
|
|
20067
20607
|
};
|
|
20068
20608
|
//#endregion
|
|
@@ -20315,6 +20855,16 @@ const validateModeFlags = (flags) => {
|
|
|
20315
20855
|
};
|
|
20316
20856
|
//#endregion
|
|
20317
20857
|
//#region src/cli/commands/inspect.ts
|
|
20858
|
+
const filterCompletedScansByCategories = (completedScans, categoryFilters) => {
|
|
20859
|
+
if (categoryFilters.size === 0) return [...completedScans];
|
|
20860
|
+
return completedScans.map((scan) => ({
|
|
20861
|
+
...scan,
|
|
20862
|
+
result: {
|
|
20863
|
+
...scan.result,
|
|
20864
|
+
diagnostics: filterDiagnosticsByCategories(scan.result.diagnostics, categoryFilters)
|
|
20865
|
+
}
|
|
20866
|
+
}));
|
|
20867
|
+
};
|
|
20318
20868
|
/**
|
|
20319
20869
|
* Post-scan finalization shared by the staged-arm and project-loop
|
|
20320
20870
|
* paths of `inspectAction`: emit the JSON report (when in JSON mode)
|
|
@@ -20327,6 +20877,7 @@ const finalizeScans = (input) => {
|
|
|
20327
20877
|
const baselineComputed = input.completedScans.length > 0 && input.completedScans.every((scan) => scan.result.baselineDelta !== void 0);
|
|
20328
20878
|
const baselineDegraded = input.baselineIntended && !baselineComputed;
|
|
20329
20879
|
const mode = baselineDegraded ? "diff" : input.mode;
|
|
20880
|
+
const jsonCompletedScans = filterCompletedScansByCategories(input.completedScans, input.categoryFilters);
|
|
20330
20881
|
if (input.isJsonMode) {
|
|
20331
20882
|
const baseline = baselineComputed && baselineDeltas.length > 0 ? {
|
|
20332
20883
|
baseRef: baselineDeltas[0].baseRef,
|
|
@@ -20338,7 +20889,7 @@ const finalizeScans = (input) => {
|
|
|
20338
20889
|
directory: input.resolvedDirectory,
|
|
20339
20890
|
mode,
|
|
20340
20891
|
diff: input.diff,
|
|
20341
|
-
scans:
|
|
20892
|
+
scans: jsonCompletedScans,
|
|
20342
20893
|
totalElapsedMilliseconds: performance.now() - input.startTime,
|
|
20343
20894
|
baseline
|
|
20344
20895
|
}));
|
|
@@ -20412,6 +20963,7 @@ const inspectAction = async (directory, flags) => {
|
|
|
20412
20963
|
await Effect.runPromise(playWelcomeScene({ speedMultiplier: isReturningUser ? 2 : 1 }));
|
|
20413
20964
|
} else Effect.runSync(printBrandedHeader);
|
|
20414
20965
|
const scanOptions = resolveCliInspectOptions(flags, userConfig);
|
|
20966
|
+
const categoryFilters = new Set(scanOptions.categoryFilters ?? []);
|
|
20415
20967
|
const skipPrompts = shouldSkipPrompts({
|
|
20416
20968
|
yes: flags.yes,
|
|
20417
20969
|
json: flags.json
|
|
@@ -20472,6 +21024,7 @@ const inspectAction = async (directory, flags) => {
|
|
|
20472
21024
|
isJsonMode,
|
|
20473
21025
|
isScoreOnly,
|
|
20474
21026
|
flags,
|
|
21027
|
+
categoryFilters,
|
|
20475
21028
|
userConfig,
|
|
20476
21029
|
resolvedDirectory,
|
|
20477
21030
|
startTime
|
|
@@ -20531,6 +21084,7 @@ const inspectAction = async (directory, flags) => {
|
|
|
20531
21084
|
const shouldShowShareLink = !scanOptions.noScore && (userConfig?.share ?? true) && !scanOptions.isCi;
|
|
20532
21085
|
await Effect.runPromise(printMultiProjectSummary({
|
|
20533
21086
|
completedScans,
|
|
21087
|
+
categoryFilters,
|
|
20534
21088
|
userConfig,
|
|
20535
21089
|
verbose: Boolean(flags.verbose),
|
|
20536
21090
|
isOffline: !shouldShowShareLink,
|
|
@@ -20546,14 +21100,15 @@ const inspectAction = async (directory, flags) => {
|
|
|
20546
21100
|
isJsonMode,
|
|
20547
21101
|
isScoreOnly,
|
|
20548
21102
|
flags,
|
|
21103
|
+
categoryFilters,
|
|
20549
21104
|
userConfig,
|
|
20550
21105
|
resolvedDirectory,
|
|
20551
21106
|
startTime
|
|
20552
21107
|
});
|
|
20553
|
-
const
|
|
20554
|
-
if (!isQuiet && !skipPrompts && process.stdout.isTTY === true && !isCiOrCodingAgentEnvironment() &&
|
|
21108
|
+
const selectedSurfaceDiagnostics = filterDiagnosticsByCategories(filterDiagnosticsForSurface(allDiagnostics, scanOptions.outputSurface ?? "cli", userConfig), categoryFilters);
|
|
21109
|
+
if (!isQuiet && !skipPrompts && process.stdout.isTTY === true && !isCiOrCodingAgentEnvironment() && selectedSurfaceDiagnostics.length > 0) {
|
|
20555
21110
|
await handoffToAgent({
|
|
20556
|
-
diagnostics:
|
|
21111
|
+
diagnostics: selectedSurfaceDiagnostics,
|
|
20557
21112
|
projectName: path$1.basename(resolvedDirectory),
|
|
20558
21113
|
rootDirectory: resolvedDirectory,
|
|
20559
21114
|
interactive: true
|
|
@@ -20984,7 +21539,7 @@ const rulesListAction = async (options) => {
|
|
|
20984
21539
|
});
|
|
20985
21540
|
const catalog = buildRuleCatalog();
|
|
20986
21541
|
const config = validateConfigTypes((await resolveRuleConfigTarget(resolveProjectRoot(options))).config);
|
|
20987
|
-
const categoryFilter = options.category
|
|
21542
|
+
const categoryFilter = typeof options.category === "string" ? options.category.toLowerCase() : void 0;
|
|
20988
21543
|
const frameworkFilter = options.framework?.toLowerCase();
|
|
20989
21544
|
const rows = catalog.filter((entry) => {
|
|
20990
21545
|
if (categoryFilter && entry.category.toLowerCase() !== categoryFilter) return false;
|
|
@@ -21347,6 +21902,7 @@ const ROOT_FLAG_SPEC = {
|
|
|
21347
21902
|
"--yes"
|
|
21348
21903
|
]),
|
|
21349
21904
|
longOptionsWithRequiredValues: new Set([
|
|
21905
|
+
"--category",
|
|
21350
21906
|
"--changed-files-from",
|
|
21351
21907
|
"--blocking",
|
|
21352
21908
|
"--fail-on",
|
|
@@ -21503,6 +22059,7 @@ ${formatExampleLines([
|
|
|
21503
22059
|
["react-doctor ./apps/web", "scan a specific directory"],
|
|
21504
22060
|
["react-doctor --diff main", "scan only files changed vs. main"],
|
|
21505
22061
|
["react-doctor --staged", "scan staged files (pre-commit hook)"],
|
|
22062
|
+
["react-doctor --category Security", "show only one diagnostic category"],
|
|
21506
22063
|
["react-doctor --blocking warning", "fail CI on warnings too (default: error)"],
|
|
21507
22064
|
["react-doctor --json > report.json", "write a machine-readable report"],
|
|
21508
22065
|
["react-doctor why src/App.tsx:42", "explain why a rule fired there"],
|
|
@@ -21531,7 +22088,8 @@ ${formatExampleLines([
|
|
|
21531
22088
|
${highlighter.dim("Learn more:")}
|
|
21532
22089
|
${highlighter.info(CANONICAL_GITHUB_URL)}
|
|
21533
22090
|
`;
|
|
21534
|
-
const
|
|
22091
|
+
const collectCategoryOption = (value, previousValues) => [...previousValues ?? [], value];
|
|
22092
|
+
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").addOption(new Option$1("--category <category>", "only show diagnostics in a category (repeatable; e.g. Security)").argParser(collectCategoryOption)).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);
|
|
21535
22093
|
program.action(inspectAction);
|
|
21536
22094
|
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));
|
|
21537
22095
|
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);
|
|
@@ -21574,4 +22132,4 @@ Promise.resolve().then(() => assertNoRemovedFlags(process.argv)).then(() => prog
|
|
|
21574
22132
|
export {};
|
|
21575
22133
|
|
|
21576
22134
|
//# sourceMappingURL=cli.js.map
|
|
21577
|
-
//# debugId=
|
|
22135
|
+
//# debugId=299ab690-e278-5f22-b581-ff28a76a28b8
|