react-doctor 0.2.14-dev.52ecf12 → 0.2.14-dev.5976266
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -2
- package/dist/cli.js +12422 -2602
- package/dist/index.d.ts +116 -13
- package/dist/index.js +1158 -255
- package/dist/skills/doctor-explain/SKILL.md +75 -0
- package/dist/skills/react-doctor/SKILL.md +4 -0
- package/package.json +11 -4
- package/dist/cli-logger-CSZagq1E.js +0 -7564
- package/dist/rolldown-runtime-uZX_iqCz.js +0 -35
package/dist/index.js
CHANGED
|
@@ -14,7 +14,10 @@ import * as Redacted from "effect/Redacted";
|
|
|
14
14
|
import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient";
|
|
15
15
|
import * as Otlp from "effect/unstable/observability/Otlp";
|
|
16
16
|
import * as Context from "effect/Context";
|
|
17
|
+
import os from "node:os";
|
|
17
18
|
import * as Console from "effect/Console";
|
|
19
|
+
import { parseJSON5 } from "confbox";
|
|
20
|
+
import { createJiti } from "jiti";
|
|
18
21
|
import * as Fiber from "effect/Fiber";
|
|
19
22
|
import * as Filter from "effect/Filter";
|
|
20
23
|
import * as Option from "effect/Option";
|
|
@@ -26,7 +29,6 @@ import * as NodeFileSystem from "@effect/platform-node-shared/NodeFileSystem";
|
|
|
26
29
|
import * as NodePath from "@effect/platform-node-shared/NodePath";
|
|
27
30
|
import * as ChildProcess from "effect/unstable/process/ChildProcess";
|
|
28
31
|
import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner";
|
|
29
|
-
import os from "node:os";
|
|
30
32
|
import * as ts from "typescript";
|
|
31
33
|
import { gzipSync } from "node:zlib";
|
|
32
34
|
//#region \0rolldown/runtime.js
|
|
@@ -59,6 +61,7 @@ var Diagnostic = class extends Schema.Class("Diagnostic")({
|
|
|
59
61
|
plugin: Schema.String,
|
|
60
62
|
rule: Schema.String,
|
|
61
63
|
severity: Severity,
|
|
64
|
+
title: Schema.optional(Schema.String),
|
|
62
65
|
message: Schema.String,
|
|
63
66
|
help: Schema.String,
|
|
64
67
|
url: Schema.optional(Schema.String),
|
|
@@ -2094,6 +2097,8 @@ const isFile = (filePath) => {
|
|
|
2094
2097
|
}
|
|
2095
2098
|
};
|
|
2096
2099
|
const SOURCE_FILE_PATTERN = /\.(tsx?|jsx?)$/;
|
|
2100
|
+
const GENERATED_BUNDLE_FILE_PATTERN = /\.(iife|umd|global|min)\.js$/i;
|
|
2101
|
+
const MINIFIED_SNIFF_BYTES = 65536;
|
|
2097
2102
|
const GIT_LS_FILES_MAX_BUFFER_BYTES = 50 * 1024 * 1024;
|
|
2098
2103
|
const IGNORED_DIRECTORIES = new Set([
|
|
2099
2104
|
".git",
|
|
@@ -2109,6 +2114,34 @@ const IGNORED_DIRECTORIES = new Set([
|
|
|
2109
2114
|
"out",
|
|
2110
2115
|
"storybook-static"
|
|
2111
2116
|
]);
|
|
2117
|
+
const isLintableSourceFile = (filePath) => SOURCE_FILE_PATTERN.test(filePath) && !GENERATED_BUNDLE_FILE_PATTERN.test(filePath);
|
|
2118
|
+
const isMinifiedSource = (absolutePath) => {
|
|
2119
|
+
let fileDescriptor;
|
|
2120
|
+
try {
|
|
2121
|
+
fileDescriptor = fs.openSync(absolutePath, "r");
|
|
2122
|
+
const buffer = Buffer.alloc(MINIFIED_SNIFF_BYTES);
|
|
2123
|
+
const bytesRead = fs.readSync(fileDescriptor, buffer, 0, MINIFIED_SNIFF_BYTES, 0);
|
|
2124
|
+
const prefix = buffer.toString("utf8", 0, bytesRead);
|
|
2125
|
+
const lines = prefix.split("\n");
|
|
2126
|
+
const longestLineLength = lines.reduce((longest, line) => Math.max(longest, line.length), 0);
|
|
2127
|
+
const averageLineLength = prefix.length / lines.length;
|
|
2128
|
+
return longestLineLength > 1e3 && averageLineLength > 500;
|
|
2129
|
+
} catch {
|
|
2130
|
+
return false;
|
|
2131
|
+
} finally {
|
|
2132
|
+
if (fileDescriptor !== void 0) fs.closeSync(fileDescriptor);
|
|
2133
|
+
}
|
|
2134
|
+
};
|
|
2135
|
+
const isLargeMinifiedFile = (absolutePath) => {
|
|
2136
|
+
let sizeBytes;
|
|
2137
|
+
try {
|
|
2138
|
+
sizeBytes = fs.statSync(absolutePath).size;
|
|
2139
|
+
} catch {
|
|
2140
|
+
return false;
|
|
2141
|
+
}
|
|
2142
|
+
if (sizeBytes < 2e4) return false;
|
|
2143
|
+
return isMinifiedSource(absolutePath);
|
|
2144
|
+
};
|
|
2112
2145
|
const IGNORABLE_READDIR_ERROR_CODES = new Set([
|
|
2113
2146
|
"EACCES",
|
|
2114
2147
|
"EPERM",
|
|
@@ -2139,7 +2172,7 @@ const countSourceFilesViaFilesystem = (rootDirectory) => {
|
|
|
2139
2172
|
if (!entry.name.startsWith(".") && !IGNORED_DIRECTORIES.has(entry.name)) stack.push(path.join(currentDirectory, entry.name));
|
|
2140
2173
|
continue;
|
|
2141
2174
|
}
|
|
2142
|
-
if (entry.isFile() &&
|
|
2175
|
+
if (entry.isFile() && isLintableSourceFile(entry.name) && !isLargeMinifiedFile(path.join(currentDirectory, entry.name))) count++;
|
|
2143
2176
|
}
|
|
2144
2177
|
}
|
|
2145
2178
|
return count;
|
|
@@ -2157,7 +2190,7 @@ const countSourceFilesViaGit = (rootDirectory) => {
|
|
|
2157
2190
|
maxBuffer: GIT_LS_FILES_MAX_BUFFER_BYTES
|
|
2158
2191
|
});
|
|
2159
2192
|
if (result.error || result.status !== 0) return null;
|
|
2160
|
-
return result.stdout.split("\0").filter((filePath) => filePath.length > 0 &&
|
|
2193
|
+
return result.stdout.split("\0").filter((filePath) => filePath.length > 0 && isLintableSourceFile(filePath) && !isLargeMinifiedFile(path.resolve(rootDirectory, filePath))).length;
|
|
2161
2194
|
};
|
|
2162
2195
|
const countSourceFiles = (rootDirectory) => countSourceFilesViaGit(rootDirectory) ?? countSourceFilesViaFilesystem(rootDirectory);
|
|
2163
2196
|
const cachedPackageJsons = /* @__PURE__ */ new Map();
|
|
@@ -2843,29 +2876,34 @@ const findDependencyInfoFromMonorepoRoot = (directory) => {
|
|
|
2843
2876
|
framework: rootInfo.framework !== "unknown" ? rootInfo.framework : workspaceInfo.framework
|
|
2844
2877
|
};
|
|
2845
2878
|
};
|
|
2846
|
-
const
|
|
2847
|
-
|
|
2879
|
+
const findInWorkspacePackageJsons = (rootDirectory, rootPackageJson, select) => {
|
|
2880
|
+
const rootValue = select(rootPackageJson);
|
|
2881
|
+
if (rootValue !== null) return rootValue;
|
|
2848
2882
|
const patterns = getWorkspacePatterns(rootDirectory, rootPackageJson);
|
|
2849
|
-
if (patterns.length === 0) return
|
|
2883
|
+
if (patterns.length === 0) return null;
|
|
2850
2884
|
const visitedDirectories = /* @__PURE__ */ new Set();
|
|
2851
2885
|
for (const pattern of patterns) {
|
|
2852
|
-
const directories = resolveWorkspaceDirectories(rootDirectory, pattern);
|
|
2886
|
+
const directories = [...resolveWorkspaceDirectories(rootDirectory, pattern)].sort();
|
|
2853
2887
|
for (const workspaceDirectory of directories) {
|
|
2854
2888
|
if (visitedDirectories.has(workspaceDirectory)) continue;
|
|
2855
2889
|
visitedDirectories.add(workspaceDirectory);
|
|
2856
|
-
|
|
2890
|
+
const value = select(readPackageJson(path.join(workspaceDirectory, "package.json")));
|
|
2891
|
+
if (value !== null) return value;
|
|
2857
2892
|
}
|
|
2858
2893
|
}
|
|
2859
|
-
return
|
|
2894
|
+
return null;
|
|
2860
2895
|
};
|
|
2896
|
+
const someWorkspacePackageJson = (rootDirectory, rootPackageJson, predicate) => findInWorkspacePackageJsons(rootDirectory, rootPackageJson, (packageJson) => predicate(packageJson) ? true : null) !== null;
|
|
2861
2897
|
const NAMES = new Set([
|
|
2862
2898
|
"react-native",
|
|
2863
2899
|
"react-native-tvos",
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2900
|
+
...new Set([
|
|
2901
|
+
"expo",
|
|
2902
|
+
"expo-router",
|
|
2903
|
+
"@expo/cli",
|
|
2904
|
+
"@expo/metro-config",
|
|
2905
|
+
"@expo/metro-runtime"
|
|
2906
|
+
]),
|
|
2869
2907
|
"react-native-windows",
|
|
2870
2908
|
"react-native-macos"
|
|
2871
2909
|
]);
|
|
@@ -2889,6 +2927,11 @@ const isPackageJsonReactNativeAware = (packageJson) => {
|
|
|
2889
2927
|
return false;
|
|
2890
2928
|
};
|
|
2891
2929
|
const hasReactNativeWorkspaceAnywhere = (rootDirectory, rootPackageJson) => someWorkspacePackageJson(rootDirectory, rootPackageJson, isPackageJsonReactNativeAware);
|
|
2930
|
+
const getExpoDependencySpec = (packageJson) => {
|
|
2931
|
+
const spec = packageJson.dependencies?.expo ?? packageJson.devDependencies?.expo ?? packageJson.peerDependencies?.expo ?? packageJson.optionalDependencies?.expo;
|
|
2932
|
+
return typeof spec === "string" ? spec : null;
|
|
2933
|
+
};
|
|
2934
|
+
const findExpoVersion = (rootDirectory, rootPackageJson) => findInWorkspacePackageJsons(rootDirectory, rootPackageJson, getExpoDependencySpec);
|
|
2892
2935
|
const getPreactVersion = (packageJson) => {
|
|
2893
2936
|
return {
|
|
2894
2937
|
...packageJson.peerDependencies,
|
|
@@ -3128,6 +3171,19 @@ const discoverProject = (directory) => {
|
|
|
3128
3171
|
const hasTypeScript = fs.existsSync(path.join(directory, "tsconfig.json"));
|
|
3129
3172
|
const sourceFileCount = countSourceFiles(directory);
|
|
3130
3173
|
const hasReactNativeWorkspace = framework === "expo" || framework === "react-native" || hasReactNativeWorkspaceAnywhere(directory, packageJson);
|
|
3174
|
+
let expoVersion = hasReactNativeWorkspace ? findExpoVersion(directory, packageJson) : null;
|
|
3175
|
+
if (expoVersion !== null && isCatalogReference(expoVersion)) {
|
|
3176
|
+
const catalogName = extractCatalogName(expoVersion);
|
|
3177
|
+
let resolvedExpoVersion = resolveCatalogVersion(packageJson, "expo", directory, catalogName);
|
|
3178
|
+
if (!resolvedExpoVersion) {
|
|
3179
|
+
const monorepoRoot = findMonorepoRoot(directory);
|
|
3180
|
+
if (monorepoRoot) {
|
|
3181
|
+
const monorepoPackageJsonPath = path.join(monorepoRoot, "package.json");
|
|
3182
|
+
if (isFile(monorepoPackageJsonPath)) resolvedExpoVersion = resolveCatalogVersion(readPackageJson(monorepoPackageJsonPath), "expo", monorepoRoot, catalogName);
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
expoVersion = resolvedExpoVersion ?? expoVersion;
|
|
3186
|
+
}
|
|
3131
3187
|
const hasReanimated = hasReactNativeWorkspace && someWorkspacePackageJson(directory, packageJson, isPackageJsonReanimatedAware);
|
|
3132
3188
|
const preactVersion = getPreactVersion(packageJson);
|
|
3133
3189
|
const projectInfo = {
|
|
@@ -3145,6 +3201,7 @@ const discoverProject = (directory) => {
|
|
|
3145
3201
|
preactVersion,
|
|
3146
3202
|
preactMajorVersion: parseReactMajor(preactVersion),
|
|
3147
3203
|
hasReactNativeWorkspace,
|
|
3204
|
+
expoVersion,
|
|
3148
3205
|
hasReanimated,
|
|
3149
3206
|
sourceFileCount
|
|
3150
3207
|
};
|
|
@@ -3234,13 +3291,31 @@ const STAGED_FILES_PROJECT_CONFIG_FILENAMES = [
|
|
|
3234
3291
|
"tsconfig.json",
|
|
3235
3292
|
"tsconfig.base.json",
|
|
3236
3293
|
"package.json",
|
|
3237
|
-
"
|
|
3294
|
+
"doctor.config.ts",
|
|
3295
|
+
"doctor.config.mts",
|
|
3296
|
+
"doctor.config.cts",
|
|
3297
|
+
"doctor.config.js",
|
|
3298
|
+
"doctor.config.mjs",
|
|
3299
|
+
"doctor.config.cjs",
|
|
3300
|
+
"doctor.config.json",
|
|
3301
|
+
"doctor.config.jsonc",
|
|
3238
3302
|
"oxlint.json",
|
|
3239
3303
|
".oxlintrc.json"
|
|
3240
3304
|
];
|
|
3241
3305
|
const OXLINT_OUTPUT_MAX_BYTES = 50 * 1024 * 1024;
|
|
3242
3306
|
const OXLINT_SPAWN_TIMEOUT_MS = 6e4;
|
|
3307
|
+
const DEAD_CODE_WORKER_MAX_OLD_SPACE_MB = 8192;
|
|
3243
3308
|
const RECOMMENDED_PNPM_MINIMUM_RELEASE_AGE_MINUTES = 10080;
|
|
3309
|
+
const DIAGNOSTIC_CATEGORY_BUCKETS = [
|
|
3310
|
+
"Security",
|
|
3311
|
+
"Bugs",
|
|
3312
|
+
"Performance",
|
|
3313
|
+
"Accessibility",
|
|
3314
|
+
"Maintainability"
|
|
3315
|
+
];
|
|
3316
|
+
const APP_ONLY_RULE_KEYS = new Set(["react-hooks-js/static-components", "react-doctor/no-render-prop-children"]);
|
|
3317
|
+
const COMPILER_CLEANUP_BUCKET = "compiler-cleanup";
|
|
3318
|
+
const COMPILER_CLEANUP_RULE_KEYS = new Set(["react-doctor/react-compiler-no-manual-memoization"]);
|
|
3244
3319
|
const MAX_GLOB_PATTERN_LENGTH_CHARS = 1024;
|
|
3245
3320
|
const CONFIG_CACHE_TTL_MS = 300 * 1e3;
|
|
3246
3321
|
var InvalidGlobPatternError = class extends Error {
|
|
@@ -3360,10 +3435,11 @@ const restampSeverity = (diagnostic, override) => {
|
|
|
3360
3435
|
*/
|
|
3361
3436
|
const buildRuleSeverityControls = (config) => {
|
|
3362
3437
|
if (!config) return void 0;
|
|
3363
|
-
if (config.rules === void 0 && config.categories === void 0
|
|
3438
|
+
if (config.rules === void 0 && config.categories === void 0 && config.buckets === void 0) return;
|
|
3364
3439
|
return {
|
|
3365
3440
|
...config.rules !== void 0 ? { rules: config.rules } : {},
|
|
3366
|
-
...config.categories !== void 0 ? { categories: config.categories } : {}
|
|
3441
|
+
...config.categories !== void 0 ? { categories: config.categories } : {},
|
|
3442
|
+
...config.buckets !== void 0 ? { buckets: config.buckets } : {}
|
|
3367
3443
|
};
|
|
3368
3444
|
};
|
|
3369
3445
|
const JSX_OPENER_TAG_PATTERN = /<[A-Za-z][\w.]*/g;
|
|
@@ -3727,6 +3803,69 @@ const resolveRuleSeverityOverride = (input, controls) => {
|
|
|
3727
3803
|
}
|
|
3728
3804
|
return input.category !== void 0 ? controls.categories?.[input.category] : void 0;
|
|
3729
3805
|
};
|
|
3806
|
+
const cachedRoleByPackageDirectory = /* @__PURE__ */ new Map();
|
|
3807
|
+
const cachedPackageDirectoryByFilename = /* @__PURE__ */ new Map();
|
|
3808
|
+
const findNearestPackageDirectory = (filename) => {
|
|
3809
|
+
if (!filename) return null;
|
|
3810
|
+
const fromCache = cachedPackageDirectoryByFilename.get(filename);
|
|
3811
|
+
if (fromCache !== void 0) return fromCache;
|
|
3812
|
+
let currentDirectory = path.dirname(filename);
|
|
3813
|
+
while (true) {
|
|
3814
|
+
const candidatePackageJsonPath = path.join(currentDirectory, "package.json");
|
|
3815
|
+
let hasPackageJson = false;
|
|
3816
|
+
try {
|
|
3817
|
+
hasPackageJson = fs.statSync(candidatePackageJsonPath).isFile();
|
|
3818
|
+
} catch {
|
|
3819
|
+
hasPackageJson = false;
|
|
3820
|
+
}
|
|
3821
|
+
if (hasPackageJson) {
|
|
3822
|
+
cachedPackageDirectoryByFilename.set(filename, currentDirectory);
|
|
3823
|
+
return currentDirectory;
|
|
3824
|
+
}
|
|
3825
|
+
const parentDirectory = path.dirname(currentDirectory);
|
|
3826
|
+
if (parentDirectory === currentDirectory) {
|
|
3827
|
+
cachedPackageDirectoryByFilename.set(filename, null);
|
|
3828
|
+
return null;
|
|
3829
|
+
}
|
|
3830
|
+
currentDirectory = parentDirectory;
|
|
3831
|
+
}
|
|
3832
|
+
};
|
|
3833
|
+
const readManifest = (packageJsonPath) => {
|
|
3834
|
+
try {
|
|
3835
|
+
const parsed = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
3836
|
+
if (typeof parsed === "object" && parsed !== null) return parsed;
|
|
3837
|
+
return null;
|
|
3838
|
+
} catch {
|
|
3839
|
+
return null;
|
|
3840
|
+
}
|
|
3841
|
+
};
|
|
3842
|
+
const hasPublishContract = (manifest) => typeof manifest.name === "string" && manifest.name.length > 0 && manifest.exports !== void 0 && manifest.exports !== null && manifest.private !== true;
|
|
3843
|
+
const classifyByDirectoryCohort = (packageDirectory) => {
|
|
3844
|
+
let current = packageDirectory;
|
|
3845
|
+
while (true) {
|
|
3846
|
+
if (path.basename(current) === "apps") return "app";
|
|
3847
|
+
const parent = path.dirname(current);
|
|
3848
|
+
if (parent === current) return null;
|
|
3849
|
+
current = parent;
|
|
3850
|
+
}
|
|
3851
|
+
};
|
|
3852
|
+
const clearPackageRoleCache = () => {
|
|
3853
|
+
cachedRoleByPackageDirectory.clear();
|
|
3854
|
+
cachedPackageDirectoryByFilename.clear();
|
|
3855
|
+
};
|
|
3856
|
+
const classifyPackageRole = (filename) => {
|
|
3857
|
+
if (!filename) return "unknown";
|
|
3858
|
+
const packageDirectory = findNearestPackageDirectory(filename);
|
|
3859
|
+
if (!packageDirectory) return "unknown";
|
|
3860
|
+
const cached = cachedRoleByPackageDirectory.get(packageDirectory);
|
|
3861
|
+
if (cached !== void 0) return cached;
|
|
3862
|
+
const manifest = readManifest(path.join(packageDirectory, "package.json"));
|
|
3863
|
+
let result;
|
|
3864
|
+
if (manifest && hasPublishContract(manifest)) result = "library";
|
|
3865
|
+
else result = classifyByDirectoryCohort(path.dirname(packageDirectory)) ?? "unknown";
|
|
3866
|
+
cachedRoleByPackageDirectory.set(packageDirectory, result);
|
|
3867
|
+
return result;
|
|
3868
|
+
};
|
|
3730
3869
|
/**
|
|
3731
3870
|
* Resolves the absolute path to read for a diagnostic's `filePath`,
|
|
3732
3871
|
* accounting for the various shapes oxlint emits:
|
|
@@ -3862,10 +4001,13 @@ const collectStringSet = (values) => {
|
|
|
3862
4001
|
* wins over `test-noise`)
|
|
3863
4002
|
* 2. severity overrides (top-level `rules` / `categories`, with
|
|
3864
4003
|
* `"off"` dropping)
|
|
3865
|
-
* 3.
|
|
3866
|
-
*
|
|
4004
|
+
* 3. warning suppression (only when `showWarnings` is false: drops every
|
|
4005
|
+
* `"warning"`-severity diagnostic unless a severity override opts a
|
|
4006
|
+
* specific rule / category back in)
|
|
4007
|
+
* 4. ignore filters (rules / file patterns / per-file overrides)
|
|
4008
|
+
* 5. `rn-no-raw-text` suppression via configured `textComponents` and
|
|
3867
4009
|
* `rawTextWrapperComponents` (config-driven JSX enclosure checks)
|
|
3868
|
-
*
|
|
4010
|
+
* 6. inline suppressions (`// react-doctor-disable-next-line ...`)
|
|
3869
4011
|
*
|
|
3870
4012
|
* Returns `null` when the diagnostic is dropped, the (possibly
|
|
3871
4013
|
* severity-restamped) diagnostic otherwise.
|
|
@@ -3875,7 +4017,7 @@ const collectStringSet = (values) => {
|
|
|
3875
4017
|
* `mergeAndFilterDiagnostics` wrapper apply this closure per element.
|
|
3876
4018
|
*/
|
|
3877
4019
|
const buildDiagnosticPipeline = (input) => {
|
|
3878
|
-
const { rootDirectory, userConfig, readFileLinesSync, respectInlineDisables } = input;
|
|
4020
|
+
const { rootDirectory, userConfig, readFileLinesSync, respectInlineDisables, showWarnings } = input;
|
|
3879
4021
|
const severityControls = buildRuleSeverityControls(userConfig);
|
|
3880
4022
|
const ignoredRules = new Set(Array.isArray(userConfig?.ignore?.rules) ? userConfig.ignore.rules.filter((rule) => typeof rule === "string") : []);
|
|
3881
4023
|
const ignoredFilePatterns = compileIgnoredFilePatterns(userConfig);
|
|
@@ -3886,6 +4028,15 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
3886
4028
|
const hasRawTextWrappers = rawTextWrapperComponentNames.size > 0;
|
|
3887
4029
|
const fileLinesCache = /* @__PURE__ */ new Map();
|
|
3888
4030
|
const testFileCache = /* @__PURE__ */ new Map();
|
|
4031
|
+
const libraryFileCache = /* @__PURE__ */ new Map();
|
|
4032
|
+
const isLibraryFile = (filePath) => {
|
|
4033
|
+
let cached = libraryFileCache.get(filePath);
|
|
4034
|
+
if (cached === void 0) {
|
|
4035
|
+
cached = classifyPackageRole(resolveCandidateReadPath(rootDirectory, filePath)) === "library";
|
|
4036
|
+
libraryFileCache.set(filePath, cached);
|
|
4037
|
+
}
|
|
4038
|
+
return cached;
|
|
4039
|
+
};
|
|
3889
4040
|
const getFileLines = (filePath) => {
|
|
3890
4041
|
const cached = fileLinesCache.get(filePath);
|
|
3891
4042
|
if (cached !== void 0) return cached;
|
|
@@ -3912,6 +4063,10 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
3912
4063
|
for (const ignored of ignoredRules) if (isSameRuleKey(ignored, ruleIdentifier)) return true;
|
|
3913
4064
|
return false;
|
|
3914
4065
|
};
|
|
4066
|
+
const isAppOnlyRule = (ruleIdentifier) => {
|
|
4067
|
+
for (const appOnlyRuleKey of APP_ONLY_RULE_KEYS) if (isSameRuleKey(appOnlyRuleKey, ruleIdentifier)) return true;
|
|
4068
|
+
return false;
|
|
4069
|
+
};
|
|
3915
4070
|
const isRnRawTextSuppressedByConfig = (diagnostic) => {
|
|
3916
4071
|
if (diagnostic.rule !== "rn-no-raw-text") return false;
|
|
3917
4072
|
if (diagnostic.line <= 0) return false;
|
|
@@ -3925,15 +4080,22 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
3925
4080
|
return { apply: (diagnostic) => {
|
|
3926
4081
|
if (shouldAutoSuppress(diagnostic)) return null;
|
|
3927
4082
|
let current = diagnostic;
|
|
4083
|
+
let explicitSeverityOverride;
|
|
4084
|
+
let explicitRuleOverride;
|
|
3928
4085
|
if (severityControls) {
|
|
3929
4086
|
const { ruleKey, category } = getDiagnosticRuleIdentity(current);
|
|
3930
|
-
|
|
4087
|
+
explicitRuleOverride = resolveRuleSeverityOverride({ ruleKey }, severityControls);
|
|
4088
|
+
explicitSeverityOverride = resolveRuleSeverityOverride({
|
|
3931
4089
|
ruleKey,
|
|
3932
4090
|
category
|
|
3933
4091
|
}, severityControls);
|
|
3934
|
-
if (
|
|
3935
|
-
if (
|
|
4092
|
+
if (explicitSeverityOverride === "off") return null;
|
|
4093
|
+
if (explicitSeverityOverride !== void 0) current = restampSeverity(current, explicitSeverityOverride);
|
|
3936
4094
|
}
|
|
4095
|
+
if (explicitRuleOverride === void 0) {
|
|
4096
|
+
if (isAppOnlyRule(`${current.plugin}/${current.rule}`) && isLibraryFile(current.filePath)) return null;
|
|
4097
|
+
}
|
|
4098
|
+
if (!showWarnings && current.severity === "warning" && explicitSeverityOverride !== "warn") return null;
|
|
3937
4099
|
if (userConfig) {
|
|
3938
4100
|
if (isRuleIgnored(`${current.plugin}/${current.rule}`)) return null;
|
|
3939
4101
|
if (isFileIgnoredByPatterns(current.filePath, rootDirectory, ignoredFilePatterns)) return null;
|
|
@@ -4118,6 +4280,17 @@ const layerOtlp = Layer.unwrap(Effect.gen(function* () {
|
|
|
4118
4280
|
}).pipe(Layer.provide(FetchHttpClient.layer));
|
|
4119
4281
|
}).pipe(Effect.orDie));
|
|
4120
4282
|
/**
|
|
4283
|
+
* Resolves a requested lint worker count to a clamped integer within
|
|
4284
|
+
* `[MIN_SCAN_CONCURRENCY, MAX_SCAN_CONCURRENCY]`. `"auto"` uses the
|
|
4285
|
+
* machine's CPU cores; out-of-range or non-finite requests degrade to
|
|
4286
|
+
* `MIN_SCAN_CONCURRENCY` rather than oversubscribing or running zero workers.
|
|
4287
|
+
*/
|
|
4288
|
+
const resolveScanConcurrency = (requested) => {
|
|
4289
|
+
const desired = requested === "auto" ? os.availableParallelism() : requested;
|
|
4290
|
+
if (!Number.isFinite(desired) || desired < 1) return 1;
|
|
4291
|
+
return Math.max(1, Math.min(Math.floor(desired), 16));
|
|
4292
|
+
};
|
|
4293
|
+
/**
|
|
4121
4294
|
* Per-batch oxlint wall-clock budget. Reads from the env var on
|
|
4122
4295
|
* startup so the eval harness can raise the budget under sandbox
|
|
4123
4296
|
* microVMs without recompiling react-doctor. Tests override via
|
|
@@ -4137,6 +4310,30 @@ var OxlintSpawnTimeoutMs = class extends Context.Reference("react-doctor/OxlintS
|
|
|
4137
4310
|
* tests that exercise the cap behavior.
|
|
4138
4311
|
*/
|
|
4139
4312
|
var OxlintOutputMaxBytes = class extends Context.Reference("react-doctor/OxlintOutputMaxBytes", { defaultValue: () => OXLINT_OUTPUT_MAX_BYTES }) {};
|
|
4313
|
+
/**
|
|
4314
|
+
* Number of oxlint subprocesses the lint pass runs in parallel. Defaults
|
|
4315
|
+
* to `1` (serial — the historical behavior) so resource usage is opt-in.
|
|
4316
|
+
* The CLI's `--experimental-parallel` flag overrides this via `Layer.succeed`; the
|
|
4317
|
+
* `REACT_DOCTOR_PARALLEL` env var seeds the default for programmatic /
|
|
4318
|
+
* CI callers that never touch the flag:
|
|
4319
|
+
*
|
|
4320
|
+
* - unset / `0` / `false` / `off` → `1` (serial)
|
|
4321
|
+
* - `auto` / `true` / `on` → available CPU cores (clamped)
|
|
4322
|
+
* - a positive integer → that many workers (clamped)
|
|
4323
|
+
*
|
|
4324
|
+
* The resolved value is always within
|
|
4325
|
+
* `[MIN_SCAN_CONCURRENCY, MAX_SCAN_CONCURRENCY]`.
|
|
4326
|
+
*/
|
|
4327
|
+
var OxlintConcurrency = class extends Context.Reference("react-doctor/OxlintConcurrency", { defaultValue: () => {
|
|
4328
|
+
const raw = process.env["REACT_DOCTOR_PARALLEL"];
|
|
4329
|
+
if (raw === void 0) return 1;
|
|
4330
|
+
const normalized = raw.trim().toLowerCase();
|
|
4331
|
+
if (normalized === "" || normalized === "0" || normalized === "false" || normalized === "off") return 1;
|
|
4332
|
+
if (normalized === "auto" || normalized === "true" || normalized === "on") return resolveScanConcurrency("auto");
|
|
4333
|
+
const parsed = Number.parseInt(normalized, 10);
|
|
4334
|
+
if (!Number.isInteger(parsed) || parsed <= 0) return 1;
|
|
4335
|
+
return resolveScanConcurrency(parsed);
|
|
4336
|
+
} }) {};
|
|
4140
4337
|
const DIAGNOSTIC_SURFACES = [
|
|
4141
4338
|
"cli",
|
|
4142
4339
|
"prComment",
|
|
@@ -4165,10 +4362,18 @@ const VALID_RULE_SEVERITIES = [
|
|
|
4165
4362
|
"warn",
|
|
4166
4363
|
"off"
|
|
4167
4364
|
];
|
|
4365
|
+
const KNOWN_CATEGORY_LABEL = DIAGNOSTIC_CATEGORY_BUCKETS.join(", ");
|
|
4366
|
+
const isDiagnosticCategoryBucket = (value) => DIAGNOSTIC_CATEGORY_BUCKETS.includes(value);
|
|
4367
|
+
const filterKnownCategories = (fieldName, categories) => categories.filter((category) => {
|
|
4368
|
+
if (isDiagnosticCategoryBucket(category)) return true;
|
|
4369
|
+
warnConfigIssue(`config field "${fieldName}" lists "${category}", which is not a known category (expected one of: ${KNOWN_CATEGORY_LABEL}); ignoring the entry.`);
|
|
4370
|
+
return false;
|
|
4371
|
+
});
|
|
4168
4372
|
const BOOLEAN_FIELD_NAMES = [
|
|
4169
4373
|
"lint",
|
|
4170
4374
|
"deadCode",
|
|
4171
4375
|
"verbose",
|
|
4376
|
+
"warnings",
|
|
4172
4377
|
"customRulesOnly",
|
|
4173
4378
|
"share",
|
|
4174
4379
|
"noScore",
|
|
@@ -4217,13 +4422,15 @@ const validateSurfaceControls = (surface, rawControls) => {
|
|
|
4217
4422
|
warnConfigIssue(`config field "surfaces.${surface}" must be an object (got ${typeof rawControls}); ignoring this surface.`);
|
|
4218
4423
|
return;
|
|
4219
4424
|
}
|
|
4220
|
-
const
|
|
4425
|
+
const validatedSurfaceControls = {};
|
|
4221
4426
|
for (const fieldName of SURFACE_CONTROL_FIELD_NAMES) {
|
|
4222
4427
|
if (rawControls[fieldName] === void 0) continue;
|
|
4223
|
-
const
|
|
4224
|
-
|
|
4428
|
+
const qualifiedName = `surfaces.${surface}.${fieldName}`;
|
|
4429
|
+
const result = validateStringArrayField(qualifiedName, rawControls[fieldName]);
|
|
4430
|
+
if (result === void 0) continue;
|
|
4431
|
+
validatedSurfaceControls[fieldName] = fieldName === "includeCategories" || fieldName === "excludeCategories" ? filterKnownCategories(qualifiedName, result) : result;
|
|
4225
4432
|
}
|
|
4226
|
-
return
|
|
4433
|
+
return validatedSurfaceControls;
|
|
4227
4434
|
};
|
|
4228
4435
|
const validateSurfacesField = (rawSurfaces) => {
|
|
4229
4436
|
if (!isPlainObject$1(rawSurfaces)) {
|
|
@@ -4241,7 +4448,7 @@ const validateSurfacesField = (rawSurfaces) => {
|
|
|
4241
4448
|
}
|
|
4242
4449
|
return validated;
|
|
4243
4450
|
};
|
|
4244
|
-
const validateSeverityMap = (fieldName, rawMap) => {
|
|
4451
|
+
const validateSeverityMap = (fieldName, rawMap, keysAreCategories = false) => {
|
|
4245
4452
|
if (!isPlainObject$1(rawMap)) {
|
|
4246
4453
|
warnConfigIssue(`config field "${fieldName}" must be an object (got ${typeof rawMap}); ignoring this field.`);
|
|
4247
4454
|
return;
|
|
@@ -4252,6 +4459,10 @@ const validateSeverityMap = (fieldName, rawMap) => {
|
|
|
4252
4459
|
warnConfigIssue(`config field "${fieldName}" has an empty key; ignoring the entry.`);
|
|
4253
4460
|
continue;
|
|
4254
4461
|
}
|
|
4462
|
+
if (keysAreCategories && !isDiagnosticCategoryBucket(key)) {
|
|
4463
|
+
warnConfigIssue(`config field "${fieldName}.${key}" is not a known category (expected one of: ${KNOWN_CATEGORY_LABEL}); ignoring the entry.`);
|
|
4464
|
+
continue;
|
|
4465
|
+
}
|
|
4255
4466
|
if (!isRuleSeverity(value)) {
|
|
4256
4467
|
warnConfigIssue(`config field "${fieldName}.${key}" must be one of: ${VALID_RULE_SEVERITIES.join(", ")} (got ${formatType(value)}); ignoring the entry.`);
|
|
4257
4468
|
continue;
|
|
@@ -4272,76 +4483,116 @@ const validateConfigTypes = (config) => {
|
|
|
4272
4483
|
for (const fieldName of BOOLEAN_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => coerceMaybeBooleanString(fieldName, value));
|
|
4273
4484
|
for (const fieldName of STRING_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => validateString(fieldName, value));
|
|
4274
4485
|
applyFieldValidator(config, validated, "surfaces", validateSurfacesField);
|
|
4275
|
-
for (const fieldName of SEVERITY_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => validateSeverityMap(fieldName, value));
|
|
4486
|
+
for (const fieldName of SEVERITY_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => validateSeverityMap(fieldName, value, fieldName === "categories"));
|
|
4276
4487
|
applyFieldValidator(config, validated, "plugins", (value) => validateStringArrayField("plugins", value));
|
|
4277
4488
|
return validated;
|
|
4278
4489
|
};
|
|
4279
4490
|
const warn = (message) => {
|
|
4280
4491
|
Effect.runSync(Console.warn(message));
|
|
4281
4492
|
};
|
|
4282
|
-
const
|
|
4493
|
+
const CONFIG_BASENAME = "doctor.config";
|
|
4494
|
+
const CONFIG_EXTENSIONS = [
|
|
4495
|
+
"ts",
|
|
4496
|
+
"mts",
|
|
4497
|
+
"cts",
|
|
4498
|
+
"js",
|
|
4499
|
+
"mjs",
|
|
4500
|
+
"cjs",
|
|
4501
|
+
"json",
|
|
4502
|
+
"jsonc"
|
|
4503
|
+
];
|
|
4504
|
+
const DATA_CONFIG_EXTENSIONS = new Set(["json", "jsonc"]);
|
|
4505
|
+
const PACKAGE_JSON_FILENAME = "package.json";
|
|
4283
4506
|
const PACKAGE_JSON_CONFIG_KEY = "reactDoctor";
|
|
4284
|
-
const
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
const packageJsonPath = path.join(directory, "package.json");
|
|
4298
|
-
if (isFile(packageJsonPath)) try {
|
|
4299
|
-
const fileContent = fs.readFileSync(packageJsonPath, "utf-8");
|
|
4300
|
-
const packageJson = JSON.parse(fileContent);
|
|
4507
|
+
const LEGACY_CONFIG_FILENAME = "react-doctor.config.json";
|
|
4508
|
+
const jiti = createJiti(import.meta.url);
|
|
4509
|
+
const formatError = (error) => error instanceof Error ? error.message : String(error);
|
|
4510
|
+
const loadModuleConfig = async (filePath) => {
|
|
4511
|
+
const imported = await jiti.import(filePath);
|
|
4512
|
+
return imported?.default ?? imported;
|
|
4513
|
+
};
|
|
4514
|
+
const readDataConfig = (filePath) => parseJSON5(fs.readFileSync(filePath, "utf-8"));
|
|
4515
|
+
const readEmbeddedPackageJsonConfig = (directory) => {
|
|
4516
|
+
const packageJsonPath = path.join(directory, PACKAGE_JSON_FILENAME);
|
|
4517
|
+
if (!isFile(packageJsonPath)) return null;
|
|
4518
|
+
try {
|
|
4519
|
+
const packageJson = parseJSON5(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
4301
4520
|
if (isPlainObject(packageJson)) {
|
|
4302
4521
|
const embeddedConfig = packageJson[PACKAGE_JSON_CONFIG_KEY];
|
|
4303
|
-
if (isPlainObject(embeddedConfig)) return
|
|
4304
|
-
|
|
4305
|
-
|
|
4522
|
+
if (isPlainObject(embeddedConfig)) return embeddedConfig;
|
|
4523
|
+
}
|
|
4524
|
+
} catch {}
|
|
4525
|
+
return null;
|
|
4526
|
+
};
|
|
4527
|
+
const loadPackageJsonConfig = (directory) => {
|
|
4528
|
+
const embeddedConfig = readEmbeddedPackageJsonConfig(directory);
|
|
4529
|
+
if (!embeddedConfig) return null;
|
|
4530
|
+
return {
|
|
4531
|
+
config: validateConfigTypes(embeddedConfig),
|
|
4532
|
+
sourceDirectory: directory,
|
|
4533
|
+
configFilePath: path.join(directory, PACKAGE_JSON_FILENAME),
|
|
4534
|
+
format: "package-json"
|
|
4535
|
+
};
|
|
4536
|
+
};
|
|
4537
|
+
const loadConfigFromDirectory = async (directory) => {
|
|
4538
|
+
let sawBrokenConfigFile = false;
|
|
4539
|
+
for (const extension of CONFIG_EXTENSIONS) {
|
|
4540
|
+
const filePath = path.join(directory, `${CONFIG_BASENAME}.${extension}`);
|
|
4541
|
+
if (!isFile(filePath)) continue;
|
|
4542
|
+
const isDataFile = DATA_CONFIG_EXTENSIONS.has(extension);
|
|
4543
|
+
try {
|
|
4544
|
+
const parsed = isDataFile ? readDataConfig(filePath) : await loadModuleConfig(filePath);
|
|
4545
|
+
if (isPlainObject(parsed)) return {
|
|
4546
|
+
status: "found",
|
|
4547
|
+
loaded: {
|
|
4548
|
+
config: validateConfigTypes(parsed),
|
|
4549
|
+
sourceDirectory: directory,
|
|
4550
|
+
configFilePath: filePath,
|
|
4551
|
+
format: isDataFile ? "json" : "module"
|
|
4552
|
+
}
|
|
4306
4553
|
};
|
|
4554
|
+
warn(`${CONFIG_BASENAME}.${extension} must export an object, ignoring.`);
|
|
4555
|
+
sawBrokenConfigFile = true;
|
|
4556
|
+
} catch (error) {
|
|
4557
|
+
warn(`Failed to load ${CONFIG_BASENAME}.${extension}: ${formatError(error)}`);
|
|
4558
|
+
sawBrokenConfigFile = true;
|
|
4307
4559
|
}
|
|
4308
|
-
} catch {
|
|
4309
|
-
return null;
|
|
4310
4560
|
}
|
|
4311
|
-
|
|
4561
|
+
const packageJsonConfig = loadPackageJsonConfig(directory);
|
|
4562
|
+
if (packageJsonConfig) return {
|
|
4563
|
+
status: "found",
|
|
4564
|
+
loaded: packageJsonConfig
|
|
4565
|
+
};
|
|
4566
|
+
if (isFile(path.join(directory, LEGACY_CONFIG_FILENAME))) warn(`${LEGACY_CONFIG_FILENAME} is no longer read — rename it to ${CONFIG_BASENAME}.json (or author a ${CONFIG_BASENAME}.ts).`);
|
|
4567
|
+
return {
|
|
4568
|
+
status: sawBrokenConfigFile ? "invalid" : "absent",
|
|
4569
|
+
loaded: null
|
|
4570
|
+
};
|
|
4312
4571
|
};
|
|
4313
4572
|
const cachedConfigs = /* @__PURE__ */ new Map();
|
|
4314
4573
|
const clearConfigCache = () => {
|
|
4315
4574
|
cachedConfigs.clear();
|
|
4316
4575
|
};
|
|
4317
|
-
const
|
|
4318
|
-
const
|
|
4319
|
-
if (
|
|
4320
|
-
|
|
4321
|
-
if (localConfig) {
|
|
4322
|
-
cachedConfigs.set(rootDirectory, localConfig);
|
|
4323
|
-
return localConfig;
|
|
4324
|
-
}
|
|
4325
|
-
if (isProjectBoundary(rootDirectory)) {
|
|
4326
|
-
cachedConfigs.set(rootDirectory, null);
|
|
4327
|
-
return null;
|
|
4328
|
-
}
|
|
4576
|
+
const loadConfigWalkingUp = async (rootDirectory) => {
|
|
4577
|
+
const localResult = await loadConfigFromDirectory(rootDirectory);
|
|
4578
|
+
if (localResult.status === "found") return localResult.loaded;
|
|
4579
|
+
if (localResult.status === "invalid" || isProjectBoundary(rootDirectory)) return null;
|
|
4329
4580
|
let ancestorDirectory = path.dirname(rootDirectory);
|
|
4330
4581
|
while (ancestorDirectory !== path.dirname(ancestorDirectory)) {
|
|
4331
|
-
const
|
|
4332
|
-
if (
|
|
4333
|
-
|
|
4334
|
-
return ancestorConfig;
|
|
4335
|
-
}
|
|
4336
|
-
if (isProjectBoundary(ancestorDirectory)) {
|
|
4337
|
-
cachedConfigs.set(rootDirectory, null);
|
|
4338
|
-
return null;
|
|
4339
|
-
}
|
|
4582
|
+
const ancestorResult = await loadConfigFromDirectory(ancestorDirectory);
|
|
4583
|
+
if (ancestorResult.status === "found") return ancestorResult.loaded;
|
|
4584
|
+
if (isProjectBoundary(ancestorDirectory)) return null;
|
|
4340
4585
|
ancestorDirectory = path.dirname(ancestorDirectory);
|
|
4341
4586
|
}
|
|
4342
|
-
cachedConfigs.set(rootDirectory, null);
|
|
4343
4587
|
return null;
|
|
4344
4588
|
};
|
|
4589
|
+
const loadConfigWithSource = (rootDirectory) => {
|
|
4590
|
+
const cached = cachedConfigs.get(rootDirectory);
|
|
4591
|
+
if (cached !== void 0) return cached;
|
|
4592
|
+
const loadPromise = loadConfigWalkingUp(rootDirectory);
|
|
4593
|
+
cachedConfigs.set(rootDirectory, loadPromise);
|
|
4594
|
+
return loadPromise;
|
|
4595
|
+
};
|
|
4345
4596
|
const resolveConfigRootDir = (config, configSourceDirectory) => {
|
|
4346
4597
|
if (!config || !configSourceDirectory) return null;
|
|
4347
4598
|
const rawRootDir = config.rootDir;
|
|
@@ -4356,11 +4607,12 @@ const resolveConfigRootDir = (config, configSourceDirectory) => {
|
|
|
4356
4607
|
}
|
|
4357
4608
|
return resolvedRootDir;
|
|
4358
4609
|
};
|
|
4359
|
-
const resolveDiagnoseTarget = (directory) => {
|
|
4610
|
+
const resolveDiagnoseTarget = (directory, options = {}) => {
|
|
4360
4611
|
if (isFile(path.join(directory, "package.json"))) return directory;
|
|
4361
4612
|
const reactSubprojects = discoverReactSubprojects(directory);
|
|
4362
4613
|
if (reactSubprojects.length === 0) return null;
|
|
4363
4614
|
if (reactSubprojects.length === 1) return reactSubprojects[0].directory;
|
|
4615
|
+
if (options.allowAmbiguous === true) return null;
|
|
4364
4616
|
throw new AmbiguousProjectError(directory, reactSubprojects.map((subproject) => path.relative(directory, subproject.directory)).toSorted());
|
|
4365
4617
|
};
|
|
4366
4618
|
/**
|
|
@@ -4368,13 +4620,13 @@ const resolveDiagnoseTarget = (directory) => {
|
|
|
4368
4620
|
* (`inspect()`, `diagnose()`, and the CLI's `inspectAction`):
|
|
4369
4621
|
*
|
|
4370
4622
|
* 1. Resolve the requested directory to absolute.
|
|
4371
|
-
* 2. Load `
|
|
4372
|
-
* if present.
|
|
4623
|
+
* 2. Load `doctor.config.*` / `package.json#reactDoctor` if present.
|
|
4373
4624
|
* 3. Honor `config.rootDir` to redirect the scan to a nested
|
|
4374
4625
|
* project root, if configured.
|
|
4375
4626
|
* 4. Walk into a nested React subproject when the requested
|
|
4376
4627
|
* directory has no `package.json` of its own (raises
|
|
4377
|
-
* `AmbiguousProjectError` when multiple candidates exist
|
|
4628
|
+
* `AmbiguousProjectError` when multiple candidates exist unless
|
|
4629
|
+
* the caller opts into keeping the wrapper directory).
|
|
4378
4630
|
*
|
|
4379
4631
|
* Throws `ProjectNotFoundError` when neither the requested directory
|
|
4380
4632
|
* nor any discoverable nested project has a `package.json`.
|
|
@@ -4386,14 +4638,14 @@ const resolveDiagnoseTarget = (directory) => {
|
|
|
4386
4638
|
* via its own cache). Routing through `resolveScanTarget` keeps every
|
|
4387
4639
|
* shell in agreement on what "the scan directory" means.
|
|
4388
4640
|
*/
|
|
4389
|
-
const resolveScanTarget = (requestedDirectory) => {
|
|
4641
|
+
const resolveScanTarget = async (requestedDirectory, options = {}) => {
|
|
4390
4642
|
const absoluteRequested = path.resolve(requestedDirectory);
|
|
4391
|
-
const loadedConfig = loadConfigWithSource(absoluteRequested);
|
|
4643
|
+
const loadedConfig = await loadConfigWithSource(absoluteRequested);
|
|
4392
4644
|
const userConfig = loadedConfig?.config ?? null;
|
|
4393
4645
|
const configSourceDirectory = loadedConfig?.sourceDirectory ?? null;
|
|
4394
4646
|
const redirectedDirectory = resolveConfigRootDir(userConfig, configSourceDirectory);
|
|
4395
4647
|
const directoryAfterRedirect = redirectedDirectory ?? absoluteRequested;
|
|
4396
|
-
const resolvedDirectory = resolveDiagnoseTarget(directoryAfterRedirect) ?? directoryAfterRedirect;
|
|
4648
|
+
const resolvedDirectory = resolveDiagnoseTarget(directoryAfterRedirect, options) ?? directoryAfterRedirect;
|
|
4397
4649
|
if (!isDirectory(resolvedDirectory)) throw existsSync(resolvedDirectory) ? new NotADirectoryError(resolvedDirectory) : new ProjectNotFoundError(resolvedDirectory);
|
|
4398
4650
|
return {
|
|
4399
4651
|
resolvedDirectory,
|
|
@@ -4403,6 +4655,359 @@ const resolveScanTarget = (requestedDirectory) => {
|
|
|
4403
4655
|
didRedirectViaRootDir: redirectedDirectory !== null
|
|
4404
4656
|
};
|
|
4405
4657
|
};
|
|
4658
|
+
const getDirectDependencyNames = (packageJson) => new Set([...Object.keys(packageJson.dependencies ?? {}), ...Object.keys(packageJson.devDependencies ?? {})]);
|
|
4659
|
+
const buildExpoCheckContext = (rootDirectory, expoVersion) => {
|
|
4660
|
+
const packageJson = readPackageJson(path.join(rootDirectory, "package.json"));
|
|
4661
|
+
return {
|
|
4662
|
+
rootDirectory,
|
|
4663
|
+
packageJson,
|
|
4664
|
+
directDependencyNames: getDirectDependencyNames(packageJson),
|
|
4665
|
+
expoSdkMajor: getLowestDependencyMajor(expoVersion)
|
|
4666
|
+
};
|
|
4667
|
+
};
|
|
4668
|
+
const buildExpoDiagnostic = (input) => ({
|
|
4669
|
+
filePath: input.filePath ?? "package.json",
|
|
4670
|
+
plugin: "react-doctor",
|
|
4671
|
+
rule: input.rule,
|
|
4672
|
+
severity: input.severity ?? "warning",
|
|
4673
|
+
message: input.message,
|
|
4674
|
+
help: input.help,
|
|
4675
|
+
line: input.line ?? 0,
|
|
4676
|
+
column: input.column ?? 0,
|
|
4677
|
+
category: input.category ?? "Correctness"
|
|
4678
|
+
});
|
|
4679
|
+
const CRITICAL_OVERRIDE_NAMES = new Set([
|
|
4680
|
+
"@expo/cli",
|
|
4681
|
+
"@expo/config",
|
|
4682
|
+
"@expo/metro-config",
|
|
4683
|
+
"@expo/metro-runtime",
|
|
4684
|
+
"@expo/metro",
|
|
4685
|
+
"metro"
|
|
4686
|
+
]);
|
|
4687
|
+
const isCriticalOverrideName = (packageName) => CRITICAL_OVERRIDE_NAMES.has(packageName) || packageName.startsWith("metro-");
|
|
4688
|
+
const collectOverrideNames = (packageJson) => new Set([
|
|
4689
|
+
...Object.keys(packageJson.overrides ?? {}),
|
|
4690
|
+
...Object.keys(packageJson.resolutions ?? {}),
|
|
4691
|
+
...Object.keys(packageJson.pnpm?.overrides ?? {})
|
|
4692
|
+
]);
|
|
4693
|
+
const checkExpoDependencyOverrides = (context) => {
|
|
4694
|
+
const overriddenCriticalNames = [...collectOverrideNames(context.packageJson)].filter(isCriticalOverrideName).sort();
|
|
4695
|
+
if (overriddenCriticalNames.length === 0) return [];
|
|
4696
|
+
const quotedNames = overriddenCriticalNames.map((name) => `"${name}"`).join(", ");
|
|
4697
|
+
return [buildExpoDiagnostic({
|
|
4698
|
+
rule: "expo-no-conflicting-dependency-override",
|
|
4699
|
+
message: `package.json pins SDK-critical ${overriddenCriticalNames.length === 1 ? "package" : "packages"} via overrides/resolutions (${quotedNames}) — these versions are tied to the Expo SDK release and overriding them is unsupported and may break Metro or native builds`,
|
|
4700
|
+
help: `Remove the override/resolution for ${quotedNames} and reinstall so the Expo-pinned versions are used`
|
|
4701
|
+
})];
|
|
4702
|
+
};
|
|
4703
|
+
const isPathGitIgnored = (rootDirectory, absolutePath) => {
|
|
4704
|
+
const result = spawnSync("git", [
|
|
4705
|
+
"check-ignore",
|
|
4706
|
+
"-q",
|
|
4707
|
+
absolutePath
|
|
4708
|
+
], {
|
|
4709
|
+
cwd: rootDirectory,
|
|
4710
|
+
stdio: [
|
|
4711
|
+
"ignore",
|
|
4712
|
+
"ignore",
|
|
4713
|
+
"ignore"
|
|
4714
|
+
]
|
|
4715
|
+
});
|
|
4716
|
+
if (result.error) return null;
|
|
4717
|
+
if (result.status === 0) return true;
|
|
4718
|
+
if (result.status === 1) return false;
|
|
4719
|
+
return null;
|
|
4720
|
+
};
|
|
4721
|
+
const LOCAL_ENV_FILE_NAMES = [
|
|
4722
|
+
".env.local",
|
|
4723
|
+
".env.development.local",
|
|
4724
|
+
".env.production.local",
|
|
4725
|
+
".env.test.local"
|
|
4726
|
+
];
|
|
4727
|
+
const checkExpoEnvLocalFiles = (context) => {
|
|
4728
|
+
const { rootDirectory } = context;
|
|
4729
|
+
const committedEnvFiles = LOCAL_ENV_FILE_NAMES.filter((fileName) => {
|
|
4730
|
+
const filePath = path.join(rootDirectory, fileName);
|
|
4731
|
+
if (!isFile(filePath)) return false;
|
|
4732
|
+
return isPathGitIgnored(rootDirectory, filePath) === false;
|
|
4733
|
+
});
|
|
4734
|
+
if (committedEnvFiles.length === 0) return [];
|
|
4735
|
+
return [buildExpoDiagnostic({
|
|
4736
|
+
rule: "expo-env-local-not-gitignored",
|
|
4737
|
+
category: "Security",
|
|
4738
|
+
message: `Local environment ${committedEnvFiles.length === 1 ? "file" : "files"} (${committedEnvFiles.join(", ")}) ${committedEnvFiles.length === 1 ? "is" : "are"} not ignored by Git — committing \`.env*.local\` risks leaking secrets and overriding committed defaults for everyone who clones the project`,
|
|
4739
|
+
help: `Add \`.env*.local\` to your .gitignore. If already committed, untrack with \`git rm --cached ${committedEnvFiles.join(" ")}\``
|
|
4740
|
+
})];
|
|
4741
|
+
};
|
|
4742
|
+
const isExpoSdkAtLeast = (expoSdkMajor, minMajor) => expoSdkMajor !== null && expoSdkMajor >= minMajor;
|
|
4743
|
+
const UNIMODULES_HELP = "Remove every `@unimodules/*` and `react-native-unimodules` package — their functionality now lives in `expo-modules-core`. See https://expo.fyi/r/sdk-44-remove-unimodules";
|
|
4744
|
+
const FIREBASE_HELP = "Use the Firebase JS SDK or React Native Firebase directly. See https://expo.fyi/firebase-migration-guide";
|
|
4745
|
+
const unimodulesEntry = (packageName) => ({
|
|
4746
|
+
packageName,
|
|
4747
|
+
rule: "expo-no-unimodules-packages",
|
|
4748
|
+
message: `"${packageName}" is a legacy unimodules package that is incompatible with Expo SDK 44+ and will break native builds`,
|
|
4749
|
+
help: UNIMODULES_HELP
|
|
4750
|
+
});
|
|
4751
|
+
const FLAGGED_DEPENDENCIES = [
|
|
4752
|
+
unimodulesEntry("@unimodules/core"),
|
|
4753
|
+
unimodulesEntry("@unimodules/react-native-adapter"),
|
|
4754
|
+
unimodulesEntry("react-native-unimodules"),
|
|
4755
|
+
{
|
|
4756
|
+
packageName: "expo-cli",
|
|
4757
|
+
rule: "expo-no-cli-dependencies",
|
|
4758
|
+
message: "`expo-cli` (the legacy global CLI) is a project dependency — the CLI now ships inside the `expo` package, and keeping `expo-cli` causes failures such as `unknown option --fix` when running `npx expo install --fix`",
|
|
4759
|
+
help: "Remove `expo-cli` from your dependencies and use the bundled CLI via `npx expo`"
|
|
4760
|
+
},
|
|
4761
|
+
{
|
|
4762
|
+
packageName: "eas-cli",
|
|
4763
|
+
rule: "expo-no-cli-dependencies",
|
|
4764
|
+
message: "`eas-cli` is a project dependency — pinning it in package.json drifts from the latest EAS CLI and bloats installs",
|
|
4765
|
+
help: "Remove `eas-cli` from your dependencies and run it on demand with `npx eas-cli` (or install it globally)"
|
|
4766
|
+
},
|
|
4767
|
+
{
|
|
4768
|
+
packageName: "expo-modules-autolinking",
|
|
4769
|
+
rule: "expo-no-redundant-dependency",
|
|
4770
|
+
message: "\"expo-modules-autolinking\" should not be a direct dependency — Expo installs it transitively as needed",
|
|
4771
|
+
help: "Remove `expo-modules-autolinking` from your package.json"
|
|
4772
|
+
},
|
|
4773
|
+
{
|
|
4774
|
+
packageName: "expo-dev-launcher",
|
|
4775
|
+
rule: "expo-no-redundant-dependency",
|
|
4776
|
+
message: "\"expo-dev-launcher\" should not be a direct dependency — it is pulled in by `expo-dev-client`",
|
|
4777
|
+
help: "Remove `expo-dev-launcher` and depend on `expo-dev-client` instead"
|
|
4778
|
+
},
|
|
4779
|
+
{
|
|
4780
|
+
packageName: "expo-dev-menu",
|
|
4781
|
+
rule: "expo-no-redundant-dependency",
|
|
4782
|
+
message: "\"expo-dev-menu\" should not be a direct dependency — it is pulled in by `expo-dev-client`",
|
|
4783
|
+
help: "Remove `expo-dev-menu` and depend on `expo-dev-client` instead"
|
|
4784
|
+
},
|
|
4785
|
+
{
|
|
4786
|
+
packageName: "expo-modules-core",
|
|
4787
|
+
rule: "expo-no-redundant-dependency",
|
|
4788
|
+
message: "\"expo-modules-core\" should not be a direct dependency — use the API re-exported from the `expo` package",
|
|
4789
|
+
help: "Remove `expo-modules-core` from your package.json and import from `expo` instead"
|
|
4790
|
+
},
|
|
4791
|
+
{
|
|
4792
|
+
packageName: "@expo/metro-config",
|
|
4793
|
+
rule: "expo-no-redundant-dependency",
|
|
4794
|
+
message: "\"@expo/metro-config\" should not be a direct dependency — use the `expo/metro-config` sub-export of the `expo` package",
|
|
4795
|
+
help: "Remove `@expo/metro-config` and import `expo/metro-config` in your metro.config.js"
|
|
4796
|
+
},
|
|
4797
|
+
{
|
|
4798
|
+
packageName: "@types/react-native",
|
|
4799
|
+
rule: "expo-no-redundant-dependency",
|
|
4800
|
+
message: "\"@types/react-native\" should not be installed — React Native ships its own types since SDK 48",
|
|
4801
|
+
help: "Remove `@types/react-native` from your package.json",
|
|
4802
|
+
minSdkMajor: 48
|
|
4803
|
+
},
|
|
4804
|
+
{
|
|
4805
|
+
packageName: "@expo/config-plugins",
|
|
4806
|
+
rule: "expo-no-redundant-dependency",
|
|
4807
|
+
message: "\"@expo/config-plugins\" should not be a direct dependency — use the `expo/config-plugins` sub-export of the `expo` package",
|
|
4808
|
+
help: "Remove `@expo/config-plugins`; config-plugin authors should import from `expo/config-plugins`. See https://github.com/expo/expo/pull/18855",
|
|
4809
|
+
minSdkMajor: 48
|
|
4810
|
+
},
|
|
4811
|
+
{
|
|
4812
|
+
packageName: "@expo/prebuild-config",
|
|
4813
|
+
rule: "expo-no-redundant-dependency",
|
|
4814
|
+
message: "\"@expo/prebuild-config\" should not be a direct dependency — Expo installs it transitively",
|
|
4815
|
+
help: "Remove `@expo/prebuild-config` from your package.json",
|
|
4816
|
+
minSdkMajor: 53
|
|
4817
|
+
},
|
|
4818
|
+
{
|
|
4819
|
+
packageName: "expo-permissions",
|
|
4820
|
+
rule: "expo-no-redundant-dependency",
|
|
4821
|
+
message: "\"expo-permissions\" was deprecated in SDK 41 and may no longer compile — permissions moved onto each module (e.g. `MediaLibrary.requestPermissionsAsync()`)",
|
|
4822
|
+
help: "Remove `expo-permissions` and request permissions from the relevant module instead",
|
|
4823
|
+
minSdkMajor: 50
|
|
4824
|
+
},
|
|
4825
|
+
{
|
|
4826
|
+
packageName: "expo-app-loading",
|
|
4827
|
+
rule: "expo-no-redundant-dependency",
|
|
4828
|
+
message: "\"expo-app-loading\" was removed in SDK 49",
|
|
4829
|
+
help: "Remove `expo-app-loading` and use `expo-splash-screen` instead. See https://docs.expo.dev/versions/latest/sdk/splash-screen/",
|
|
4830
|
+
minSdkMajor: 49
|
|
4831
|
+
},
|
|
4832
|
+
{
|
|
4833
|
+
packageName: "expo-firebase-analytics",
|
|
4834
|
+
rule: "expo-no-redundant-dependency",
|
|
4835
|
+
message: "\"expo-firebase-analytics\" was removed in SDK 48",
|
|
4836
|
+
help: FIREBASE_HELP,
|
|
4837
|
+
minSdkMajor: 48
|
|
4838
|
+
},
|
|
4839
|
+
{
|
|
4840
|
+
packageName: "expo-firebase-recaptcha",
|
|
4841
|
+
rule: "expo-no-redundant-dependency",
|
|
4842
|
+
message: "\"expo-firebase-recaptcha\" was removed in SDK 48",
|
|
4843
|
+
help: FIREBASE_HELP,
|
|
4844
|
+
minSdkMajor: 48
|
|
4845
|
+
},
|
|
4846
|
+
{
|
|
4847
|
+
packageName: "expo-firebase-core",
|
|
4848
|
+
rule: "expo-no-redundant-dependency",
|
|
4849
|
+
message: "\"expo-firebase-core\" was removed in SDK 48",
|
|
4850
|
+
help: FIREBASE_HELP,
|
|
4851
|
+
minSdkMajor: 48
|
|
4852
|
+
}
|
|
4853
|
+
];
|
|
4854
|
+
const checkExpoFlaggedDependencies = (context) => FLAGGED_DEPENDENCIES.filter((flaggedDependency) => {
|
|
4855
|
+
if (!context.directDependencyNames.has(flaggedDependency.packageName)) return false;
|
|
4856
|
+
if (flaggedDependency.minSdkMajor === void 0) return true;
|
|
4857
|
+
return isExpoSdkAtLeast(context.expoSdkMajor, flaggedDependency.minSdkMajor);
|
|
4858
|
+
}).map((flaggedDependency) => buildExpoDiagnostic({
|
|
4859
|
+
rule: flaggedDependency.rule,
|
|
4860
|
+
message: flaggedDependency.message,
|
|
4861
|
+
help: flaggedDependency.help
|
|
4862
|
+
}));
|
|
4863
|
+
const findLocalModuleNativeFiles = (rootDirectory) => {
|
|
4864
|
+
const modulesDirectory = path.join(rootDirectory, "modules");
|
|
4865
|
+
if (!isDirectory(modulesDirectory)) return [];
|
|
4866
|
+
const nativeFilePaths = [];
|
|
4867
|
+
for (const moduleEntry of readDirectoryEntries(modulesDirectory)) {
|
|
4868
|
+
if (!moduleEntry.isDirectory()) continue;
|
|
4869
|
+
const moduleDirectory = path.join(modulesDirectory, moduleEntry.name);
|
|
4870
|
+
const gradlePath = path.join(moduleDirectory, "android", "build.gradle");
|
|
4871
|
+
if (isFile(gradlePath)) nativeFilePaths.push(gradlePath);
|
|
4872
|
+
const iosDirectory = path.join(moduleDirectory, "ios");
|
|
4873
|
+
if (isDirectory(iosDirectory)) {
|
|
4874
|
+
for (const iosEntry of readDirectoryEntries(iosDirectory)) if (iosEntry.isFile() && iosEntry.name.endsWith(".podspec")) nativeFilePaths.push(path.join(iosDirectory, iosEntry.name));
|
|
4875
|
+
}
|
|
4876
|
+
}
|
|
4877
|
+
return nativeFilePaths;
|
|
4878
|
+
};
|
|
4879
|
+
const checkExpoGitignore = (context) => {
|
|
4880
|
+
const { rootDirectory } = context;
|
|
4881
|
+
const diagnostics = [];
|
|
4882
|
+
const expoStateDirectory = path.join(rootDirectory, ".expo");
|
|
4883
|
+
if (isDirectory(expoStateDirectory) && isPathGitIgnored(rootDirectory, expoStateDirectory) === false) diagnostics.push(buildExpoDiagnostic({
|
|
4884
|
+
rule: "expo-gitignore",
|
|
4885
|
+
message: "The `.expo` directory is not ignored by Git — it holds machine-specific device history and dev-server settings that should not be committed",
|
|
4886
|
+
help: "Add `.expo/` to your .gitignore"
|
|
4887
|
+
}));
|
|
4888
|
+
if (findLocalModuleNativeFiles(rootDirectory).find((nativeFilePath) => isPathGitIgnored(rootDirectory, nativeFilePath) === true) !== void 0) diagnostics.push(buildExpoDiagnostic({
|
|
4889
|
+
rule: "expo-gitignore",
|
|
4890
|
+
message: "The native `ios`/`android` directories of a local Expo module under `modules/` are gitignored — usually caused by an overly broad `ios`/`android` ignore rule",
|
|
4891
|
+
help: "Use anchored patterns like `/ios` and `/android` in .gitignore so only the top-level native directories are excluded, not those inside `modules/`"
|
|
4892
|
+
}));
|
|
4893
|
+
return diagnostics;
|
|
4894
|
+
};
|
|
4895
|
+
const LOCKFILE_NAMES = [
|
|
4896
|
+
"pnpm-lock.yaml",
|
|
4897
|
+
"yarn.lock",
|
|
4898
|
+
"package-lock.json",
|
|
4899
|
+
"bun.lockb",
|
|
4900
|
+
"bun.lock"
|
|
4901
|
+
];
|
|
4902
|
+
const checkExpoLockfile = (context) => {
|
|
4903
|
+
const workspaceRoot = isMonorepoRoot(context.rootDirectory) ? context.rootDirectory : findMonorepoRoot(context.rootDirectory) ?? context.rootDirectory;
|
|
4904
|
+
const presentLockfiles = LOCKFILE_NAMES.filter((lockfileName) => isFile(path.join(workspaceRoot, lockfileName)));
|
|
4905
|
+
if (presentLockfiles.length === 0) return [buildExpoDiagnostic({
|
|
4906
|
+
rule: "expo-lockfile",
|
|
4907
|
+
message: "No lock file detected at the project root — installs are not reproducible, and EAS Build cannot infer your package manager",
|
|
4908
|
+
help: "Install dependencies with your package manager to generate a lock file, then commit it"
|
|
4909
|
+
})];
|
|
4910
|
+
if (presentLockfiles.length > 1) return [buildExpoDiagnostic({
|
|
4911
|
+
rule: "expo-lockfile",
|
|
4912
|
+
message: `Multiple lock files detected (${presentLockfiles.join(", ")}) — CI environments such as EAS Build infer the package manager from the lock file, so this is ambiguous`,
|
|
4913
|
+
help: "Delete the lock files for the package managers you are not using and keep only one"
|
|
4914
|
+
})];
|
|
4915
|
+
return [];
|
|
4916
|
+
};
|
|
4917
|
+
const METRO_CONFIG_FILE_NAMES = [
|
|
4918
|
+
"metro.config.js",
|
|
4919
|
+
"metro.config.cjs",
|
|
4920
|
+
"metro.config.mjs",
|
|
4921
|
+
"metro.config.ts"
|
|
4922
|
+
];
|
|
4923
|
+
const EXPO_METRO_CONFIG_EXTEND_SIGNALS = [
|
|
4924
|
+
"expo/metro-config",
|
|
4925
|
+
"@sentry/react-native/metro",
|
|
4926
|
+
"getSentryExpoConfig"
|
|
4927
|
+
];
|
|
4928
|
+
const checkExpoMetroConfig = (context) => {
|
|
4929
|
+
const metroConfigPath = METRO_CONFIG_FILE_NAMES.map((fileName) => path.join(context.rootDirectory, fileName)).find((candidatePath) => isFile(candidatePath));
|
|
4930
|
+
if (metroConfigPath === void 0) return [];
|
|
4931
|
+
let contents;
|
|
4932
|
+
try {
|
|
4933
|
+
contents = fs.readFileSync(metroConfigPath, "utf-8");
|
|
4934
|
+
} catch {
|
|
4935
|
+
return [];
|
|
4936
|
+
}
|
|
4937
|
+
if (EXPO_METRO_CONFIG_EXTEND_SIGNALS.some((signal) => contents.includes(signal))) return [];
|
|
4938
|
+
return [buildExpoDiagnostic({
|
|
4939
|
+
rule: "expo-metro-config",
|
|
4940
|
+
filePath: path.basename(metroConfigPath),
|
|
4941
|
+
message: "Your metro.config does not extend `expo/metro-config` — a custom Metro config that doesn't extend Expo's leads to unexpected, hard-to-debug bundling issues",
|
|
4942
|
+
help: "Update your metro config to extend `expo/metro-config`. See https://docs.expo.dev/guides/customizing-metro/"
|
|
4943
|
+
})];
|
|
4944
|
+
};
|
|
4945
|
+
const CONFLICTING_SCRIPT_NAMES = ["expo", "react-native"];
|
|
4946
|
+
const checkExpoPackageJsonConflicts = (context) => {
|
|
4947
|
+
const { packageJson } = context;
|
|
4948
|
+
const diagnostics = [];
|
|
4949
|
+
const conflictingScriptNames = CONFLICTING_SCRIPT_NAMES.filter((scriptName) => Boolean(packageJson.scripts?.[scriptName]));
|
|
4950
|
+
if (conflictingScriptNames.length > 0) {
|
|
4951
|
+
const quotedNames = conflictingScriptNames.map((name) => `"${name}"`).join(", ");
|
|
4952
|
+
const shadowsExpoCli = conflictingScriptNames.includes("expo");
|
|
4953
|
+
diagnostics.push(buildExpoDiagnostic({
|
|
4954
|
+
rule: "expo-package-json-conflict",
|
|
4955
|
+
message: `package.json defines ${quotedNames} ${conflictingScriptNames.length === 1 ? "as a script that conflicts" : "as scripts that conflict"} with binaries in node_modules/.bin${shadowsExpoCli ? " — a `expo` script shadows the Expo CLI and will likely cause build failures" : ""}`,
|
|
4956
|
+
help: "Rename these scripts so they don't collide with the `expo` / `react-native` binaries"
|
|
4957
|
+
}));
|
|
4958
|
+
}
|
|
4959
|
+
const packageName = packageJson.name;
|
|
4960
|
+
if (typeof packageName === "string" && context.directDependencyNames.has(packageName)) diagnostics.push(buildExpoDiagnostic({
|
|
4961
|
+
rule: "expo-package-json-conflict",
|
|
4962
|
+
message: `package.json "name" is "${packageName}", which collides with a dependency of the same name`,
|
|
4963
|
+
help: "Rename your package so it no longer matches one of its dependencies"
|
|
4964
|
+
}));
|
|
4965
|
+
return diagnostics;
|
|
4966
|
+
};
|
|
4967
|
+
const EXPO_ROUTER_REACT_NAVIGATION_MIN_SDK_MAJOR = 56;
|
|
4968
|
+
const EXPO_ROUTER_REACT_NAVIGATION_MAX_SDK_MAJOR_EXCLUSIVE = 57;
|
|
4969
|
+
const checkExpoRouterReactNavigation = (context) => {
|
|
4970
|
+
const { expoSdkMajor } = context;
|
|
4971
|
+
if (!isExpoSdkAtLeast(expoSdkMajor, EXPO_ROUTER_REACT_NAVIGATION_MIN_SDK_MAJOR)) return [];
|
|
4972
|
+
if (expoSdkMajor !== null && expoSdkMajor >= EXPO_ROUTER_REACT_NAVIGATION_MAX_SDK_MAJOR_EXCLUSIVE) return [];
|
|
4973
|
+
if (!context.directDependencyNames.has("expo-router")) return [];
|
|
4974
|
+
const reactNavigationNames = [...context.directDependencyNames].filter((packageName) => packageName.startsWith("@react-navigation/")).sort();
|
|
4975
|
+
if (reactNavigationNames.length === 0) return [];
|
|
4976
|
+
return [buildExpoDiagnostic({
|
|
4977
|
+
rule: "expo-router-no-react-navigation",
|
|
4978
|
+
message: `As of SDK 56, expo-router is no longer compatible with react-navigation, but ${reactNavigationNames.map((name) => `"${name}"`).join(", ")} ${reactNavigationNames.length === 1 ? "is" : "are"} installed as direct ${reactNavigationNames.length === 1 ? "dependency" : "dependencies"}`,
|
|
4979
|
+
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/"
|
|
4980
|
+
})];
|
|
4981
|
+
};
|
|
4982
|
+
const VECTOR_ICONS_MIN_SDK_MAJOR = 56;
|
|
4983
|
+
const SCOPED_VECTOR_ICONS_NAMESPACE = "@react-native-vector-icons/";
|
|
4984
|
+
const CONFLICTING_VECTOR_ICONS_PACKAGES = ["@expo/vector-icons", "react-native-vector-icons"];
|
|
4985
|
+
const checkExpoVectorIcons = (context) => {
|
|
4986
|
+
if (!isExpoSdkAtLeast(context.expoSdkMajor, VECTOR_ICONS_MIN_SDK_MAJOR)) return [];
|
|
4987
|
+
const hasScopedPackage = [...context.directDependencyNames].some((packageName) => packageName.startsWith(SCOPED_VECTOR_ICONS_NAMESPACE));
|
|
4988
|
+
const hasConflictingPackage = CONFLICTING_VECTOR_ICONS_PACKAGES.some((packageName) => context.directDependencyNames.has(packageName));
|
|
4989
|
+
if (!hasScopedPackage || !hasConflictingPackage) return [];
|
|
4990
|
+
return [buildExpoDiagnostic({
|
|
4991
|
+
rule: "expo-vector-icons-conflict",
|
|
4992
|
+
message: "This project installs both the scoped `@react-native-vector-icons/*` packages and `@expo/vector-icons` (or the deprecated `react-native-vector-icons`) — mixing them causes icon-rendering conflicts",
|
|
4993
|
+
help: "Migrate to the scoped packages by running `npx @react-native-vector-icons/codemod`, then remove the conflicting package"
|
|
4994
|
+
})];
|
|
4995
|
+
};
|
|
4996
|
+
const checkExpoProject = (rootDirectory, project) => {
|
|
4997
|
+
if (project.expoVersion === null) return [];
|
|
4998
|
+
const context = buildExpoCheckContext(rootDirectory, project.expoVersion);
|
|
4999
|
+
return [
|
|
5000
|
+
...checkExpoFlaggedDependencies(context),
|
|
5001
|
+
...checkExpoDependencyOverrides(context),
|
|
5002
|
+
...checkExpoRouterReactNavigation(context),
|
|
5003
|
+
...checkExpoVectorIcons(context),
|
|
5004
|
+
...checkExpoPackageJsonConflicts(context),
|
|
5005
|
+
...checkExpoLockfile(context),
|
|
5006
|
+
...checkExpoGitignore(context),
|
|
5007
|
+
...checkExpoEnvLocalFiles(context),
|
|
5008
|
+
...checkExpoMetroConfig(context)
|
|
5009
|
+
];
|
|
5010
|
+
};
|
|
4406
5011
|
const PNPM_WORKSPACE_FILE = "pnpm-workspace.yaml";
|
|
4407
5012
|
const PNPM_LOCKFILE = "pnpm-lock.yaml";
|
|
4408
5013
|
const PACKAGE_JSON_FILE = "package.json";
|
|
@@ -4572,99 +5177,6 @@ const checkReducedMotion = (rootDirectory) => {
|
|
|
4572
5177
|
return [MISSING_REDUCED_MOTION_DIAGNOSTIC];
|
|
4573
5178
|
};
|
|
4574
5179
|
const computeJsxIncludePaths = (includePaths) => includePaths.length > 0 ? includePaths.filter((filePath) => JSX_FILE_PATTERN.test(filePath)) : void 0;
|
|
4575
|
-
const toStringSet = (values) => {
|
|
4576
|
-
if (!values || values.length === 0) return /* @__PURE__ */ new Set();
|
|
4577
|
-
return new Set(values.filter((value) => typeof value === "string" && value.length > 0));
|
|
4578
|
-
};
|
|
4579
|
-
const buildResolvedControls = (surface, userControls) => {
|
|
4580
|
-
const excludeTags = new Set(DEFAULT_SURFACE_EXCLUDED_TAGS[surface]);
|
|
4581
|
-
const includeTags = toStringSet(userControls?.includeTags);
|
|
4582
|
-
for (const tag of includeTags) excludeTags.delete(tag);
|
|
4583
|
-
for (const tag of toStringSet(userControls?.excludeTags)) excludeTags.add(tag);
|
|
4584
|
-
return {
|
|
4585
|
-
includeTags,
|
|
4586
|
-
excludeTags,
|
|
4587
|
-
includeCategories: toStringSet(userControls?.includeCategories),
|
|
4588
|
-
excludeCategories: toStringSet(userControls?.excludeCategories),
|
|
4589
|
-
includeRuleKeys: toStringSet(userControls?.includeRules),
|
|
4590
|
-
excludeRuleKeys: toStringSet(userControls?.excludeRules)
|
|
4591
|
-
};
|
|
4592
|
-
};
|
|
4593
|
-
const intersects = (values, candidates) => values.some((value) => candidates.has(value));
|
|
4594
|
-
const isDiagnosticOnSurface = (diagnostic, surface, config) => {
|
|
4595
|
-
const resolved = buildResolvedControls(surface, config?.surfaces?.[surface]);
|
|
4596
|
-
const { ruleKey, category, tags } = getDiagnosticRuleIdentity(diagnostic);
|
|
4597
|
-
if (resolved.includeRuleKeys.has(ruleKey)) return true;
|
|
4598
|
-
if (resolved.includeCategories.has(category)) return true;
|
|
4599
|
-
if (intersects(tags, resolved.includeTags)) return true;
|
|
4600
|
-
if (resolved.excludeRuleKeys.has(ruleKey)) return false;
|
|
4601
|
-
if (resolved.excludeCategories.has(category)) return false;
|
|
4602
|
-
if (intersects(tags, resolved.excludeTags)) return false;
|
|
4603
|
-
return true;
|
|
4604
|
-
};
|
|
4605
|
-
const filterDiagnosticsForSurface = (diagnostics, surface, config) => diagnostics.filter((diagnostic) => isDiagnosticOnSurface(diagnostic, surface, config));
|
|
4606
|
-
const listSourceFilesViaGit = (rootDirectory) => {
|
|
4607
|
-
const result = spawnSync("git", [
|
|
4608
|
-
"ls-files",
|
|
4609
|
-
"-z",
|
|
4610
|
-
"--cached",
|
|
4611
|
-
"--others",
|
|
4612
|
-
"--exclude-standard"
|
|
4613
|
-
], {
|
|
4614
|
-
cwd: rootDirectory,
|
|
4615
|
-
encoding: "utf-8",
|
|
4616
|
-
maxBuffer: GIT_LS_FILES_MAX_BUFFER_BYTES
|
|
4617
|
-
});
|
|
4618
|
-
if (result.error || result.status !== 0) return null;
|
|
4619
|
-
return result.stdout.split("\0").filter((filePath) => filePath.length > 0 && SOURCE_FILE_PATTERN.test(filePath));
|
|
4620
|
-
};
|
|
4621
|
-
const listSourceFilesViaFilesystem = (rootDirectory) => {
|
|
4622
|
-
const filePaths = [];
|
|
4623
|
-
const stack = [rootDirectory];
|
|
4624
|
-
while (stack.length > 0) {
|
|
4625
|
-
const currentDirectory = stack.pop();
|
|
4626
|
-
const entries = readDirectoryEntries(currentDirectory);
|
|
4627
|
-
for (const entry of entries) {
|
|
4628
|
-
const absolutePath = path.join(currentDirectory, entry.name);
|
|
4629
|
-
if (entry.isDirectory()) {
|
|
4630
|
-
if (!entry.name.startsWith(".") && !IGNORED_DIRECTORIES.has(entry.name)) stack.push(absolutePath);
|
|
4631
|
-
continue;
|
|
4632
|
-
}
|
|
4633
|
-
if (entry.isFile() && SOURCE_FILE_PATTERN.test(entry.name)) filePaths.push(path.relative(rootDirectory, absolutePath).replace(/\\/g, "/"));
|
|
4634
|
-
}
|
|
4635
|
-
}
|
|
4636
|
-
return filePaths;
|
|
4637
|
-
};
|
|
4638
|
-
const listSourceFiles = (rootDirectory) => listSourceFilesViaGit(rootDirectory) ?? listSourceFilesViaFilesystem(rootDirectory);
|
|
4639
|
-
const resolveLintIncludePaths = (rootDirectory, userConfig) => {
|
|
4640
|
-
if (!Array.isArray(userConfig?.ignore?.files) || userConfig.ignore.files.length === 0) return;
|
|
4641
|
-
const ignoredPatterns = compileIgnoredFilePatterns(userConfig);
|
|
4642
|
-
return listSourceFiles(rootDirectory).filter((filePath) => {
|
|
4643
|
-
if (!JSX_FILE_PATTERN.test(filePath)) return false;
|
|
4644
|
-
return !isFileIgnoredByPatterns(filePath, rootDirectory, ignoredPatterns);
|
|
4645
|
-
});
|
|
4646
|
-
};
|
|
4647
|
-
var Config = class Config extends Context.Service()("react-doctor/Config") {
|
|
4648
|
-
static layerNode = Layer.effect(Config, Effect.gen(function* () {
|
|
4649
|
-
const cache = yield* Cache.make({
|
|
4650
|
-
capacity: 16,
|
|
4651
|
-
timeToLive: CONFIG_CACHE_TTL_MS,
|
|
4652
|
-
lookup: (directory) => Effect.sync(() => {
|
|
4653
|
-
const loaded = loadConfigWithSource(directory);
|
|
4654
|
-
const redirected = resolveConfigRootDir(loaded?.config ?? null, loaded?.sourceDirectory ?? null);
|
|
4655
|
-
return {
|
|
4656
|
-
config: loaded?.config ?? null,
|
|
4657
|
-
resolvedDirectory: redirected ?? directory,
|
|
4658
|
-
configSourceDirectory: loaded?.sourceDirectory ?? null
|
|
4659
|
-
};
|
|
4660
|
-
})
|
|
4661
|
-
});
|
|
4662
|
-
return Config.of({ resolve: Effect.fn("Config.resolve")(function* (directory) {
|
|
4663
|
-
return yield* Cache.get(cache, directory);
|
|
4664
|
-
}) });
|
|
4665
|
-
}));
|
|
4666
|
-
static layerOf = (resolved) => Layer.succeed(Config, Config.of({ resolve: () => Effect.succeed(resolved) }));
|
|
4667
|
-
};
|
|
4668
5180
|
const LINGUIST_ATTRIBUTE_PATTERN = /^linguist-(?:vendored|generated)(?:=([a-zA-Z0-9]+))?$/i;
|
|
4669
5181
|
const FALSY_VALUES = new Set([
|
|
4670
5182
|
"false",
|
|
@@ -4746,6 +5258,30 @@ const collectIgnorePatterns = (rootDirectory) => {
|
|
|
4746
5258
|
cachedPatternsByRoot.set(rootDirectory, patterns);
|
|
4747
5259
|
return patterns;
|
|
4748
5260
|
};
|
|
5261
|
+
/**
|
|
5262
|
+
* Resolves a path to its canonical, symlink-free form, falling back to
|
|
5263
|
+
* the input when it cannot be realpath'd (broken symlink, permission
|
|
5264
|
+
* error) so a best-effort normalization never throws.
|
|
5265
|
+
*
|
|
5266
|
+
* deslop's dead-code module graph is collected with `fast-glob` (which
|
|
5267
|
+
* keeps the scan root's symlinks intact) while imports are resolved
|
|
5268
|
+
* through `oxc-resolver` (which returns realpath'd targets). When the
|
|
5269
|
+
* project root sits behind a symlink — e.g. macOS iCloud-synced
|
|
5270
|
+
* `~/Documents` / `~/Desktop`, or a symlinked checkout — those two path
|
|
5271
|
+
* spaces diverge: every resolved import misses the graph and the files
|
|
5272
|
+
* they point at (commonly every `@/…` alias target) are mis-reported as
|
|
5273
|
+
* unreachable. Canonicalizing the root before the scan keeps both path
|
|
5274
|
+
* spaces in agreement.
|
|
5275
|
+
*/
|
|
5276
|
+
const toCanonicalPath = (filePath) => {
|
|
5277
|
+
try {
|
|
5278
|
+
return fs.realpathSync(filePath);
|
|
5279
|
+
} catch {
|
|
5280
|
+
return filePath;
|
|
5281
|
+
}
|
|
5282
|
+
};
|
|
5283
|
+
const DEAD_CODE_PLUGIN = "deslop";
|
|
5284
|
+
const DEAD_CODE_CATEGORY = "Maintainability";
|
|
4749
5285
|
const TSCONFIG_FILENAMES$1 = ["tsconfig.json", "tsconfig.base.json"];
|
|
4750
5286
|
const DEAD_CODE_WORKER_SCRIPT = `
|
|
4751
5287
|
const inputChunks = [];
|
|
@@ -4921,7 +5457,11 @@ const buildDeadCodeWorkerError = (workerError) => {
|
|
|
4921
5457
|
return error;
|
|
4922
5458
|
};
|
|
4923
5459
|
const createDeadCodeWorker = (input) => {
|
|
4924
|
-
const child = spawn(process.execPath, [
|
|
5460
|
+
const child = spawn(process.execPath, [
|
|
5461
|
+
`--max-old-space-size=${DEAD_CODE_WORKER_MAX_OLD_SPACE_MB}`,
|
|
5462
|
+
"-e",
|
|
5463
|
+
DEAD_CODE_WORKER_SCRIPT
|
|
5464
|
+
], {
|
|
4925
5465
|
stdio: [
|
|
4926
5466
|
"pipe",
|
|
4927
5467
|
"pipe",
|
|
@@ -4996,7 +5536,8 @@ const runDeadCodeWorkerWithTimeout = (handle, timeoutMs) => new Promise((resolve
|
|
|
4996
5536
|
});
|
|
4997
5537
|
});
|
|
4998
5538
|
const checkDeadCode = async (options) => {
|
|
4999
|
-
const {
|
|
5539
|
+
const { userConfig } = options;
|
|
5540
|
+
const rootDirectory = toCanonicalPath(options.rootDirectory);
|
|
5000
5541
|
if (!fs.existsSync(path.join(rootDirectory, "package.json"))) return [];
|
|
5001
5542
|
const ignorePatterns = collectDeadCodeIgnorePatterns(rootDirectory, userConfig);
|
|
5002
5543
|
const result = parseDeadCodeWorkerResult(await runDeadCodeWorkerWithTimeout((options.createWorker ?? createDeadCodeWorker)({
|
|
@@ -5009,59 +5550,162 @@ const checkDeadCode = async (options) => {
|
|
|
5009
5550
|
const diagnostics = [];
|
|
5010
5551
|
for (const unusedFile of result.unusedFiles) diagnostics.push({
|
|
5011
5552
|
filePath: toRelative(unusedFile.path),
|
|
5012
|
-
plugin:
|
|
5553
|
+
plugin: DEAD_CODE_PLUGIN,
|
|
5013
5554
|
rule: "unused-file",
|
|
5014
5555
|
severity: "warning",
|
|
5015
5556
|
message: "Unused file — not reachable from any entry point",
|
|
5016
5557
|
help: "Delete the file if it is truly unreachable, or import it from an entry point.",
|
|
5017
5558
|
line: 0,
|
|
5018
5559
|
column: 0,
|
|
5019
|
-
category:
|
|
5560
|
+
category: DEAD_CODE_CATEGORY
|
|
5020
5561
|
});
|
|
5021
5562
|
for (const unusedExport of result.unusedExports) {
|
|
5022
5563
|
const label = unusedExport.isTypeOnly ? "type export" : "export";
|
|
5023
5564
|
diagnostics.push({
|
|
5024
5565
|
filePath: toRelative(unusedExport.path),
|
|
5025
|
-
plugin:
|
|
5566
|
+
plugin: DEAD_CODE_PLUGIN,
|
|
5026
5567
|
rule: unusedExport.isTypeOnly ? "unused-type" : "unused-export",
|
|
5027
5568
|
severity: "warning",
|
|
5028
5569
|
message: `Unused ${label}: \`${unusedExport.name}\``,
|
|
5029
5570
|
help: "Drop the `export` keyword (or remove the declaration) if no other module uses this symbol.",
|
|
5030
5571
|
line: unusedExport.line,
|
|
5031
5572
|
column: unusedExport.column,
|
|
5032
|
-
category:
|
|
5573
|
+
category: DEAD_CODE_CATEGORY
|
|
5033
5574
|
});
|
|
5034
5575
|
}
|
|
5035
5576
|
for (const unusedDependency of result.unusedDependencies) {
|
|
5036
5577
|
const label = unusedDependency.isDevDependency ? "devDependency" : "dependency";
|
|
5037
5578
|
diagnostics.push({
|
|
5038
5579
|
filePath: "package.json",
|
|
5039
|
-
plugin:
|
|
5580
|
+
plugin: DEAD_CODE_PLUGIN,
|
|
5040
5581
|
rule: unusedDependency.isDevDependency ? "unused-dev-dependency" : "unused-dependency",
|
|
5041
5582
|
severity: "warning",
|
|
5042
5583
|
message: `Unused ${label}: \`${unusedDependency.name}\``,
|
|
5043
5584
|
help: "Remove the dependency from package.json if it is genuinely unused.",
|
|
5044
5585
|
line: 0,
|
|
5045
5586
|
column: 0,
|
|
5046
|
-
category:
|
|
5587
|
+
category: DEAD_CODE_CATEGORY
|
|
5047
5588
|
});
|
|
5048
5589
|
}
|
|
5049
5590
|
for (const cycle of result.circularDependencies) {
|
|
5050
5591
|
if (cycle.files.length === 0) continue;
|
|
5051
5592
|
diagnostics.push({
|
|
5052
5593
|
filePath: toRelative(cycle.files[0]),
|
|
5053
|
-
plugin:
|
|
5594
|
+
plugin: DEAD_CODE_PLUGIN,
|
|
5054
5595
|
rule: "circular-dependency",
|
|
5055
5596
|
severity: "warning",
|
|
5056
5597
|
message: `Circular import cycle: ${cycle.files.map(toRelative).join(" → ")}`,
|
|
5057
5598
|
help: "Break the cycle by extracting the shared code into a third module that both files import.",
|
|
5058
5599
|
line: 0,
|
|
5059
5600
|
column: 0,
|
|
5060
|
-
category:
|
|
5601
|
+
category: DEAD_CODE_CATEGORY
|
|
5061
5602
|
});
|
|
5062
5603
|
}
|
|
5063
5604
|
return diagnostics;
|
|
5064
5605
|
};
|
|
5606
|
+
const DEAD_CODE_RULE_KEY_PREFIX = `${DEAD_CODE_PLUGIN}/`;
|
|
5607
|
+
const isSurfacingOverride = (override) => override === "warn" || override === "error";
|
|
5608
|
+
const deadCodeMaySurfaceWhenWarningsHidden = (userConfig) => {
|
|
5609
|
+
const severityControls = buildRuleSeverityControls(userConfig);
|
|
5610
|
+
if (!severityControls) return false;
|
|
5611
|
+
if (isSurfacingOverride(severityControls.categories?.["Maintainability"])) return true;
|
|
5612
|
+
for (const [ruleKey, override] of Object.entries(severityControls.rules ?? {})) if (ruleKey.startsWith(DEAD_CODE_RULE_KEY_PREFIX) && isSurfacingOverride(override)) return true;
|
|
5613
|
+
return false;
|
|
5614
|
+
};
|
|
5615
|
+
const toStringSet = (values) => {
|
|
5616
|
+
if (!values || values.length === 0) return /* @__PURE__ */ new Set();
|
|
5617
|
+
return new Set(values.filter((value) => typeof value === "string" && value.length > 0));
|
|
5618
|
+
};
|
|
5619
|
+
const buildResolvedControls = (surface, userControls) => {
|
|
5620
|
+
const excludeTags = new Set(DEFAULT_SURFACE_EXCLUDED_TAGS[surface]);
|
|
5621
|
+
const includeTags = toStringSet(userControls?.includeTags);
|
|
5622
|
+
for (const tag of includeTags) excludeTags.delete(tag);
|
|
5623
|
+
for (const tag of toStringSet(userControls?.excludeTags)) excludeTags.add(tag);
|
|
5624
|
+
return {
|
|
5625
|
+
includeTags,
|
|
5626
|
+
excludeTags,
|
|
5627
|
+
includeCategories: toStringSet(userControls?.includeCategories),
|
|
5628
|
+
excludeCategories: toStringSet(userControls?.excludeCategories),
|
|
5629
|
+
includeRuleKeys: toStringSet(userControls?.includeRules),
|
|
5630
|
+
excludeRuleKeys: toStringSet(userControls?.excludeRules)
|
|
5631
|
+
};
|
|
5632
|
+
};
|
|
5633
|
+
const intersects = (values, candidates) => values.some((value) => candidates.has(value));
|
|
5634
|
+
const isDiagnosticOnSurface = (diagnostic, surface, config) => {
|
|
5635
|
+
const resolved = buildResolvedControls(surface, config?.surfaces?.[surface]);
|
|
5636
|
+
const { ruleKey, category, tags } = getDiagnosticRuleIdentity(diagnostic);
|
|
5637
|
+
if (resolved.includeRuleKeys.has(ruleKey)) return true;
|
|
5638
|
+
if (resolved.includeCategories.has(category)) return true;
|
|
5639
|
+
if (intersects(tags, resolved.includeTags)) return true;
|
|
5640
|
+
if (resolved.excludeRuleKeys.has(ruleKey)) return false;
|
|
5641
|
+
if (resolved.excludeCategories.has(category)) return false;
|
|
5642
|
+
if (intersects(tags, resolved.excludeTags)) return false;
|
|
5643
|
+
return true;
|
|
5644
|
+
};
|
|
5645
|
+
const filterDiagnosticsForSurface = (diagnostics, surface, config) => diagnostics.filter((diagnostic) => isDiagnosticOnSurface(diagnostic, surface, config));
|
|
5646
|
+
const excludeMinifiedFiles = (rootDirectory, relativePaths) => relativePaths.filter((relativePath) => !isLargeMinifiedFile(path.resolve(rootDirectory, relativePath)));
|
|
5647
|
+
const listSourceFilesViaGit = (rootDirectory) => {
|
|
5648
|
+
const result = spawnSync("git", [
|
|
5649
|
+
"ls-files",
|
|
5650
|
+
"-z",
|
|
5651
|
+
"--cached",
|
|
5652
|
+
"--others",
|
|
5653
|
+
"--exclude-standard"
|
|
5654
|
+
], {
|
|
5655
|
+
cwd: rootDirectory,
|
|
5656
|
+
encoding: "utf-8",
|
|
5657
|
+
maxBuffer: GIT_LS_FILES_MAX_BUFFER_BYTES
|
|
5658
|
+
});
|
|
5659
|
+
if (result.error || result.status !== 0) return null;
|
|
5660
|
+
return result.stdout.split("\0").filter((filePath) => filePath.length > 0 && isLintableSourceFile(filePath));
|
|
5661
|
+
};
|
|
5662
|
+
const listSourceFilesViaFilesystem = (rootDirectory) => {
|
|
5663
|
+
const filePaths = [];
|
|
5664
|
+
const stack = [rootDirectory];
|
|
5665
|
+
while (stack.length > 0) {
|
|
5666
|
+
const currentDirectory = stack.pop();
|
|
5667
|
+
const entries = readDirectoryEntries(currentDirectory);
|
|
5668
|
+
for (const entry of entries) {
|
|
5669
|
+
const absolutePath = path.join(currentDirectory, entry.name);
|
|
5670
|
+
if (entry.isDirectory()) {
|
|
5671
|
+
if (!entry.name.startsWith(".") && !IGNORED_DIRECTORIES.has(entry.name)) stack.push(absolutePath);
|
|
5672
|
+
continue;
|
|
5673
|
+
}
|
|
5674
|
+
if (entry.isFile() && isLintableSourceFile(entry.name)) filePaths.push(path.relative(rootDirectory, absolutePath).replace(/\\/g, "/"));
|
|
5675
|
+
}
|
|
5676
|
+
}
|
|
5677
|
+
return filePaths;
|
|
5678
|
+
};
|
|
5679
|
+
const listSourceFiles = (rootDirectory) => excludeMinifiedFiles(rootDirectory, listSourceFilesViaGit(rootDirectory) ?? listSourceFilesViaFilesystem(rootDirectory));
|
|
5680
|
+
const resolveLintIncludePaths = (rootDirectory, userConfig) => {
|
|
5681
|
+
if (!Array.isArray(userConfig?.ignore?.files) || userConfig.ignore.files.length === 0) return;
|
|
5682
|
+
const ignoredPatterns = compileIgnoredFilePatterns(userConfig);
|
|
5683
|
+
return listSourceFiles(rootDirectory).filter((filePath) => {
|
|
5684
|
+
if (!JSX_FILE_PATTERN.test(filePath)) return false;
|
|
5685
|
+
return !isFileIgnoredByPatterns(filePath, rootDirectory, ignoredPatterns);
|
|
5686
|
+
});
|
|
5687
|
+
};
|
|
5688
|
+
var Config = class Config extends Context.Service()("react-doctor/Config") {
|
|
5689
|
+
static layerNode = Layer.effect(Config, Effect.gen(function* () {
|
|
5690
|
+
const cache = yield* Cache.make({
|
|
5691
|
+
capacity: 16,
|
|
5692
|
+
timeToLive: CONFIG_CACHE_TTL_MS,
|
|
5693
|
+
lookup: (directory) => Effect.promise(async () => {
|
|
5694
|
+
const loaded = await loadConfigWithSource(directory);
|
|
5695
|
+
const redirected = resolveConfigRootDir(loaded?.config ?? null, loaded?.sourceDirectory ?? null);
|
|
5696
|
+
return {
|
|
5697
|
+
config: loaded?.config ?? null,
|
|
5698
|
+
resolvedDirectory: redirected ?? directory,
|
|
5699
|
+
configSourceDirectory: loaded?.sourceDirectory ?? null
|
|
5700
|
+
};
|
|
5701
|
+
})
|
|
5702
|
+
});
|
|
5703
|
+
return Config.of({ resolve: Effect.fn("Config.resolve")(function* (directory) {
|
|
5704
|
+
return yield* Cache.get(cache, directory);
|
|
5705
|
+
}) });
|
|
5706
|
+
}));
|
|
5707
|
+
static layerOf = (resolved) => Layer.succeed(Config, Config.of({ resolve: () => Effect.succeed(resolved) }));
|
|
5708
|
+
};
|
|
5065
5709
|
/**
|
|
5066
5710
|
* `DeadCode` runs whole-project reachability analysis and streams
|
|
5067
5711
|
* diagnostics. Reachability is a whole-project property — the
|
|
@@ -5567,12 +6211,12 @@ const findFilesWithDisableDirectivesViaGit = async (rootDirectory, includePaths)
|
|
|
5567
6211
|
return null;
|
|
5568
6212
|
}
|
|
5569
6213
|
if (grepResult === null) return null;
|
|
5570
|
-
return grepResult.stdout.split("\n").filter((filePath) => filePath.length > 0 &&
|
|
6214
|
+
return grepResult.stdout.split("\n").filter((filePath) => filePath.length > 0 && isLintableSourceFile(filePath));
|
|
5571
6215
|
};
|
|
5572
6216
|
const findFilesWithDisableDirectivesViaFilesystem = (rootDirectory, includePaths) => {
|
|
5573
6217
|
const matches = [];
|
|
5574
6218
|
const checkFile = (relativePath) => {
|
|
5575
|
-
if (!
|
|
6219
|
+
if (!isLintableSourceFile(relativePath)) return;
|
|
5576
6220
|
const absolutePath = path.join(rootDirectory, relativePath);
|
|
5577
6221
|
let content;
|
|
5578
6222
|
try {
|
|
@@ -5644,6 +6288,7 @@ const buildCapabilities = (project) => {
|
|
|
5644
6288
|
const capabilities = /* @__PURE__ */ new Set();
|
|
5645
6289
|
capabilities.add(project.framework);
|
|
5646
6290
|
if (project.framework === "expo" || project.framework === "react-native" || project.hasReactNativeWorkspace) capabilities.add("react-native");
|
|
6291
|
+
if (project.expoVersion !== null) capabilities.add("expo");
|
|
5647
6292
|
const reactMajor = project.reactMajorVersion;
|
|
5648
6293
|
if (reactMajor !== null) {
|
|
5649
6294
|
const cappedReactMajor = Math.min(reactMajor, 30);
|
|
@@ -5815,10 +6460,14 @@ const resolveSettingsRootDirectory = (rootDirectory) => {
|
|
|
5815
6460
|
if (!fs.existsSync(rootDirectory)) return rootDirectory;
|
|
5816
6461
|
return fs.realpathSync(rootDirectory);
|
|
5817
6462
|
};
|
|
6463
|
+
const resolveCompilerCleanupBucketSeverity = (ruleKey, severityControls) => {
|
|
6464
|
+
if (!COMPILER_CLEANUP_RULE_KEYS.has(ruleKey)) return void 0;
|
|
6465
|
+
return severityControls?.buckets?.[COMPILER_CLEANUP_BUCKET];
|
|
6466
|
+
};
|
|
5818
6467
|
const applyRuleSeverityControls = (rules, severityControls) => {
|
|
5819
6468
|
const enabledRules = {};
|
|
5820
6469
|
for (const [ruleKey, defaultSeverity] of Object.entries(rules)) {
|
|
5821
|
-
const severity = resolveRuleSeverityOverride({ ruleKey }, severityControls) ?? defaultSeverity;
|
|
6470
|
+
const severity = resolveRuleSeverityOverride({ ruleKey }, severityControls) ?? resolveCompilerCleanupBucketSeverity(ruleKey, severityControls) ?? defaultSeverity;
|
|
5822
6471
|
if (severity === "off") continue;
|
|
5823
6472
|
enabledRules[ruleKey] = severity;
|
|
5824
6473
|
}
|
|
@@ -5860,7 +6509,7 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
|
|
|
5860
6509
|
category: rule.category
|
|
5861
6510
|
}, severityControls);
|
|
5862
6511
|
if (rule.defaultEnabled === false && explicitSeverity === void 0) continue;
|
|
5863
|
-
const severity = explicitSeverity ?? rule.severity;
|
|
6512
|
+
const severity = explicitSeverity ?? resolveCompilerCleanupBucketSeverity(registryEntry.key, severityControls) ?? rule.severity;
|
|
5864
6513
|
if (severity === "off") continue;
|
|
5865
6514
|
enabledReactDoctorRules[registryEntry.key] = severity;
|
|
5866
6515
|
}
|
|
@@ -5917,6 +6566,44 @@ const dedupeDiagnostics = (diagnostics) => {
|
|
|
5917
6566
|
}
|
|
5918
6567
|
return uniqueDiagnostics;
|
|
5919
6568
|
};
|
|
6569
|
+
/**
|
|
6570
|
+
* Runs `task` over `items` with at most `concurrency` tasks in flight at
|
|
6571
|
+
* once, returning results in input order. A pool of workers each pulls the
|
|
6572
|
+
* next not-yet-started index until the list drains — so a worker that
|
|
6573
|
+
* finishes a fast task immediately picks up the next one (greedy load
|
|
6574
|
+
* balancing), which matters when tasks have uneven durations (oxlint
|
|
6575
|
+
* batches do).
|
|
6576
|
+
*
|
|
6577
|
+
* Failure semantics mirror a bounded `Promise.all`: on the first rejection
|
|
6578
|
+
* no further tasks are started, the already-in-flight tasks are awaited to
|
|
6579
|
+
* settle (so no subprocess is orphaned mid-write), and the returned promise
|
|
6580
|
+
* rejects with that first error. This keeps the caller's fail-fast retry
|
|
6581
|
+
* path (e.g. oxlint's retry-without-extends) from spawning a second wave on
|
|
6582
|
+
* top of a still-running first one.
|
|
6583
|
+
*/
|
|
6584
|
+
const mapWithConcurrency = async (items, concurrency, task) => {
|
|
6585
|
+
const results = new Array(items.length);
|
|
6586
|
+
if (items.length === 0) return results;
|
|
6587
|
+
const workerCount = Math.min(Math.max(1, Math.floor(concurrency) || 1), items.length);
|
|
6588
|
+
let nextIndex = 0;
|
|
6589
|
+
const errors = [];
|
|
6590
|
+
const runWorker = async () => {
|
|
6591
|
+
while (errors.length === 0) {
|
|
6592
|
+
const index = nextIndex;
|
|
6593
|
+
nextIndex += 1;
|
|
6594
|
+
if (index >= items.length) return;
|
|
6595
|
+
try {
|
|
6596
|
+
results[index] = await task(items[index], index);
|
|
6597
|
+
} catch (error) {
|
|
6598
|
+
errors.push(error);
|
|
6599
|
+
return;
|
|
6600
|
+
}
|
|
6601
|
+
}
|
|
6602
|
+
};
|
|
6603
|
+
await Promise.all(Array.from({ length: workerCount }, runWorker));
|
|
6604
|
+
if (errors.length > 0) throw errors[0];
|
|
6605
|
+
return results;
|
|
6606
|
+
};
|
|
5920
6607
|
const getPublicEnvPrefix = (framework) => {
|
|
5921
6608
|
switch (framework) {
|
|
5922
6609
|
case "nextjs": return "NEXT_PUBLIC_*";
|
|
@@ -5939,6 +6626,149 @@ const appendReanimatedSharedValueHint = (help, rule, project) => {
|
|
|
5939
6626
|
if (!help) return REANIMATED_SHARED_VALUE_HINT;
|
|
5940
6627
|
return `${help}\n\n${REANIMATED_SHARED_VALUE_HINT}`;
|
|
5941
6628
|
};
|
|
6629
|
+
const REDACTED_PLACEHOLDER = "<redacted>";
|
|
6630
|
+
const KEEP_PREFIX = `$1${REDACTED_PLACEHOLDER}`;
|
|
6631
|
+
const KNOWN_SECRET_RULES = [
|
|
6632
|
+
{
|
|
6633
|
+
pattern: /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g,
|
|
6634
|
+
replacement: REDACTED_PLACEHOLDER
|
|
6635
|
+
},
|
|
6636
|
+
{
|
|
6637
|
+
pattern: /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g,
|
|
6638
|
+
replacement: REDACTED_PLACEHOLDER
|
|
6639
|
+
},
|
|
6640
|
+
{
|
|
6641
|
+
pattern: /(?<=:\/\/)[^\s/:@]+:[^\s/@]+(?=@)/g,
|
|
6642
|
+
replacement: REDACTED_PLACEHOLDER
|
|
6643
|
+
},
|
|
6644
|
+
{
|
|
6645
|
+
pattern: /\b(AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA|A3T[A-Z0-9])[0-9A-Z]{16,}/g,
|
|
6646
|
+
replacement: KEEP_PREFIX
|
|
6647
|
+
},
|
|
6648
|
+
{
|
|
6649
|
+
pattern: /\b(gh[pousr]_)[A-Za-z0-9]{36,}/g,
|
|
6650
|
+
replacement: KEEP_PREFIX
|
|
6651
|
+
},
|
|
6652
|
+
{
|
|
6653
|
+
pattern: /\b(github_pat_)[A-Za-z0-9_]{22,}/g,
|
|
6654
|
+
replacement: KEEP_PREFIX
|
|
6655
|
+
},
|
|
6656
|
+
{
|
|
6657
|
+
pattern: /\b(glpat-)[A-Za-z0-9_-]{20,}/g,
|
|
6658
|
+
replacement: KEEP_PREFIX
|
|
6659
|
+
},
|
|
6660
|
+
{
|
|
6661
|
+
pattern: /\b(xox[baprs]-)[A-Za-z0-9-]{10,}/g,
|
|
6662
|
+
replacement: KEEP_PREFIX
|
|
6663
|
+
},
|
|
6664
|
+
{
|
|
6665
|
+
pattern: /(?<=hooks\.slack\.com\/services\/)[A-Za-z0-9/+_-]{20,}/g,
|
|
6666
|
+
replacement: REDACTED_PLACEHOLDER
|
|
6667
|
+
},
|
|
6668
|
+
{
|
|
6669
|
+
pattern: /\b((?:sk|rk)_(?:live|test)_)[0-9A-Za-z]{10,}/g,
|
|
6670
|
+
replacement: KEEP_PREFIX
|
|
6671
|
+
},
|
|
6672
|
+
{
|
|
6673
|
+
pattern: /\b(sk-(?:proj-|ant-)?)[A-Za-z0-9_-]{20,}/g,
|
|
6674
|
+
replacement: KEEP_PREFIX
|
|
6675
|
+
},
|
|
6676
|
+
{
|
|
6677
|
+
pattern: /\b(AIza)[0-9A-Za-z_-]{35,}/g,
|
|
6678
|
+
replacement: KEEP_PREFIX
|
|
6679
|
+
},
|
|
6680
|
+
{
|
|
6681
|
+
pattern: /\b(ya29\.)[0-9A-Za-z_-]{20,}/g,
|
|
6682
|
+
replacement: KEEP_PREFIX
|
|
6683
|
+
},
|
|
6684
|
+
{
|
|
6685
|
+
pattern: /\b(npm_)[A-Za-z0-9]{36,}/g,
|
|
6686
|
+
replacement: KEEP_PREFIX
|
|
6687
|
+
},
|
|
6688
|
+
{
|
|
6689
|
+
pattern: /\b(SG\.)[A-Za-z0-9_-]{22,}\.[A-Za-z0-9_-]{43,}/g,
|
|
6690
|
+
replacement: KEEP_PREFIX
|
|
6691
|
+
},
|
|
6692
|
+
{
|
|
6693
|
+
pattern: /\b(SK)[0-9a-fA-F]{32,}/g,
|
|
6694
|
+
replacement: KEEP_PREFIX
|
|
6695
|
+
},
|
|
6696
|
+
{
|
|
6697
|
+
pattern: /\b(dop_v1_)[a-f0-9]{64,}/g,
|
|
6698
|
+
replacement: KEEP_PREFIX
|
|
6699
|
+
},
|
|
6700
|
+
{
|
|
6701
|
+
pattern: /\b(shp(?:at|ca|pa|ss)_)[a-fA-F0-9]{32,}/g,
|
|
6702
|
+
replacement: KEEP_PREFIX
|
|
6703
|
+
},
|
|
6704
|
+
{
|
|
6705
|
+
pattern: /\b(sq0[a-z]{3}-)[0-9A-Za-z_-]{22,}/g,
|
|
6706
|
+
replacement: KEEP_PREFIX
|
|
6707
|
+
},
|
|
6708
|
+
{
|
|
6709
|
+
pattern: /\b([0-9]{8,10}:AA)[0-9A-Za-z_-]{32,}/g,
|
|
6710
|
+
replacement: KEEP_PREFIX
|
|
6711
|
+
},
|
|
6712
|
+
{
|
|
6713
|
+
pattern: /(?<=\bBearer\s)[A-Za-z0-9._~+/=-]{16,}/g,
|
|
6714
|
+
replacement: REDACTED_PLACEHOLDER
|
|
6715
|
+
},
|
|
6716
|
+
{
|
|
6717
|
+
pattern: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g,
|
|
6718
|
+
replacement: REDACTED_PLACEHOLDER
|
|
6719
|
+
}
|
|
6720
|
+
];
|
|
6721
|
+
const CANDIDATE_TOKEN_PATTERN = /[A-Za-z0-9_][A-Za-z0-9_-]*/g;
|
|
6722
|
+
const HEX_DIGEST_PATTERN = /^(?:[0-9a-f]{32}|[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
6723
|
+
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
6724
|
+
const HAS_LETTER_PATTERN = /[A-Za-z]/;
|
|
6725
|
+
const HAS_DIGIT_PATTERN = /[0-9]/;
|
|
6726
|
+
const shannonEntropyBits = (value) => {
|
|
6727
|
+
const counts = /* @__PURE__ */ new Map();
|
|
6728
|
+
for (const char of value) counts.set(char, (counts.get(char) ?? 0) + 1);
|
|
6729
|
+
let bits = 0;
|
|
6730
|
+
for (const count of counts.values()) {
|
|
6731
|
+
const probability = count / value.length;
|
|
6732
|
+
bits -= probability * Math.log2(probability);
|
|
6733
|
+
}
|
|
6734
|
+
return bits;
|
|
6735
|
+
};
|
|
6736
|
+
const looksLikeHighEntropySecret = (token) => {
|
|
6737
|
+
if (token.length < 32) return false;
|
|
6738
|
+
if (!HAS_LETTER_PATTERN.test(token) || !HAS_DIGIT_PATTERN.test(token)) return false;
|
|
6739
|
+
if (HEX_DIGEST_PATTERN.test(token) || UUID_PATTERN.test(token)) return false;
|
|
6740
|
+
return shannonEntropyBits(token) >= 3;
|
|
6741
|
+
};
|
|
6742
|
+
const redactHighEntropyTokens = (text) => text.replace(CANDIDATE_TOKEN_PATTERN, (token) => looksLikeHighEntropySecret(token) ? REDACTED_PLACEHOLDER : token);
|
|
6743
|
+
/**
|
|
6744
|
+
* Masks API keys, tokens, private keys, credentialed URLs, and emails
|
|
6745
|
+
* found anywhere inside a free-text string, returning the scrubbed text.
|
|
6746
|
+
* Applied to every diagnostic's `message` / `help` at construction time
|
|
6747
|
+
* so secrets never reach the terminal, the JSON report, or the score
|
|
6748
|
+
* API — react-doctor must never echo or transmit a user's secrets.
|
|
6749
|
+
*
|
|
6750
|
+
* Provider tokens keep their non-secret, type-identifying prefix (e.g.
|
|
6751
|
+
* `sk_live_<redacted>`, `ghp_<redacted>`, `AKIA<redacted>`) so the leaked
|
|
6752
|
+
* credential's type stays visible; structural or unknown-format secrets
|
|
6753
|
+
* with no meaningful prefix are masked whole.
|
|
6754
|
+
*
|
|
6755
|
+
* Runs the high-precision known-shape detectors first, then a generic
|
|
6756
|
+
* entropy-gated sweep for unknown-format secrets. Idempotent: the inert
|
|
6757
|
+
* `<redacted>` placeholder matches none of the detectors and is too
|
|
6758
|
+
* short for the generic sweep, so re-running leaves the text unchanged.
|
|
6759
|
+
*
|
|
6760
|
+
* Accepts `unknown` on purpose: callers feed it diagnostic `message` /
|
|
6761
|
+
* `help` that originate from oxlint JSON, which is only shape-checked at
|
|
6762
|
+
* the top level (the per-field `string` types are assumed, not validated).
|
|
6763
|
+
* A malformed non-string value returns `""` instead of throwing on
|
|
6764
|
+
* `.replace`, so one bad diagnostic can't abort parsing the whole batch.
|
|
6765
|
+
*/
|
|
6766
|
+
const redactSensitiveText = (text) => {
|
|
6767
|
+
if (typeof text !== "string" || text === "") return "";
|
|
6768
|
+
let redacted = text;
|
|
6769
|
+
for (const rule of KNOWN_SECRET_RULES) redacted = redacted.replace(rule.pattern, rule.replacement);
|
|
6770
|
+
return redactHighEntropyTokens(redacted);
|
|
6771
|
+
};
|
|
5942
6772
|
const REACT_MODULE_SOURCE = "react";
|
|
5943
6773
|
const REQUIRE_IDENTIFIER = "require";
|
|
5944
6774
|
const USE_IDENTIFIER = "use";
|
|
@@ -6233,25 +7063,26 @@ const shouldSuppressLocalUseHookDiagnostic = (diagnostic, rootDirectory) => {
|
|
|
6233
7063
|
return bindingResolution !== null && !bindingResolution.isReactUseBinding;
|
|
6234
7064
|
};
|
|
6235
7065
|
const FILEPATH_WITH_LOCATION_PATTERN = /\S+\.\w+:\d+:\d+[\s\S]*$/;
|
|
6236
|
-
const
|
|
7066
|
+
const REACT_COMPILER_TITLE = "React Compiler can't optimize this";
|
|
7067
|
+
const REACT_COMPILER_MESSAGE = "This component misses React Compiler's automatic memoization & re-renders more than it should. Rewrite the flagged code so the compiler can optimize it.";
|
|
6237
7068
|
const PLUGIN_CATEGORY_MAP = {
|
|
6238
|
-
react: "
|
|
6239
|
-
"react-hooks": "
|
|
6240
|
-
"react-hooks-js": "
|
|
6241
|
-
"react-doctor": "
|
|
7069
|
+
react: "Bugs",
|
|
7070
|
+
"react-hooks": "Bugs",
|
|
7071
|
+
"react-hooks-js": "Performance",
|
|
7072
|
+
"react-doctor": "Bugs",
|
|
6242
7073
|
"jsx-a11y": "Accessibility",
|
|
6243
|
-
effect: "
|
|
6244
|
-
eslint: "
|
|
6245
|
-
oxc: "
|
|
6246
|
-
typescript: "
|
|
6247
|
-
unicorn: "
|
|
6248
|
-
import: "
|
|
6249
|
-
promise: "
|
|
6250
|
-
n: "
|
|
6251
|
-
node: "
|
|
6252
|
-
vitest: "
|
|
6253
|
-
jest: "
|
|
6254
|
-
nextjs: "
|
|
7074
|
+
effect: "Bugs",
|
|
7075
|
+
eslint: "Bugs",
|
|
7076
|
+
oxc: "Bugs",
|
|
7077
|
+
typescript: "Bugs",
|
|
7078
|
+
unicorn: "Bugs",
|
|
7079
|
+
import: "Performance",
|
|
7080
|
+
promise: "Bugs",
|
|
7081
|
+
n: "Bugs",
|
|
7082
|
+
node: "Bugs",
|
|
7083
|
+
vitest: "Bugs",
|
|
7084
|
+
jest: "Bugs",
|
|
7085
|
+
nextjs: "Bugs"
|
|
6255
7086
|
};
|
|
6256
7087
|
const lookupOwnString = (record, key) => Object.hasOwn(record, key) ? record[key] : void 0;
|
|
6257
7088
|
const getRuleRecommendation = (ruleName, project) => {
|
|
@@ -6259,7 +7090,16 @@ const getRuleRecommendation = (ruleName, project) => {
|
|
|
6259
7090
|
return reactDoctorPlugin.rules[ruleName]?.recommendation;
|
|
6260
7091
|
};
|
|
6261
7092
|
const getRuleCategory = (ruleName) => reactDoctorPlugin.rules[ruleName]?.category;
|
|
7093
|
+
const getRuleTitle = (ruleName) => reactDoctorPlugin.rules[ruleName]?.title;
|
|
7094
|
+
const resolveDiagnosticTitle = (plugin, rule) => plugin === "react-hooks-js" ? REACT_COMPILER_TITLE : getRuleTitle(rule);
|
|
6262
7095
|
const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
|
|
7096
|
+
const cleaned = resolveCleanedDiagnostic(typeof message === "string" ? message : "", typeof help === "string" ? help : "", plugin, rule, project);
|
|
7097
|
+
return {
|
|
7098
|
+
message: redactSensitiveText(cleaned.message),
|
|
7099
|
+
help: redactSensitiveText(cleaned.help)
|
|
7100
|
+
};
|
|
7101
|
+
};
|
|
7102
|
+
const resolveCleanedDiagnostic = (message, help, plugin, rule, project) => {
|
|
6263
7103
|
if (plugin === "react-hooks-js") return {
|
|
6264
7104
|
message: REACT_COMPILER_MESSAGE,
|
|
6265
7105
|
help: appendReanimatedSharedValueHint(message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim() || help, rule, project)
|
|
@@ -6280,7 +7120,7 @@ const parseRuleCode = (code) => {
|
|
|
6280
7120
|
rule: match[2]
|
|
6281
7121
|
};
|
|
6282
7122
|
};
|
|
6283
|
-
const resolveDiagnosticCategory = (plugin, rule) => getRuleCategory(rule) ?? lookupOwnString(PLUGIN_CATEGORY_MAP, plugin) ?? "
|
|
7123
|
+
const resolveDiagnosticCategory = (plugin, rule) => getRuleCategory(rule) ?? lookupOwnString(PLUGIN_CATEGORY_MAP, plugin) ?? "Bugs";
|
|
6284
7124
|
const isOxlintOutput = (value) => {
|
|
6285
7125
|
if (typeof value !== "object" || value === null) return false;
|
|
6286
7126
|
const candidate = value;
|
|
@@ -6304,7 +7144,16 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
6304
7144
|
throw new ReactDoctorError({ reason: new OxlintOutputUnparseable({ preview: stdout.slice(0, 200) }) });
|
|
6305
7145
|
}
|
|
6306
7146
|
if (!isOxlintOutput(parsed)) throw new ReactDoctorError({ reason: new OxlintOutputUnparseable({ preview: stdout.slice(0, 200) }) });
|
|
6307
|
-
|
|
7147
|
+
const minifiedFileCache = /* @__PURE__ */ new Map();
|
|
7148
|
+
const isMinifiedDiagnosticFile = (filename) => {
|
|
7149
|
+
const absolutePath = path.isAbsolute(filename) ? filename : path.resolve(rootDirectory || ".", filename);
|
|
7150
|
+
const cached = minifiedFileCache.get(absolutePath);
|
|
7151
|
+
if (cached !== void 0) return cached;
|
|
7152
|
+
const minified = isMinifiedSource(absolutePath);
|
|
7153
|
+
minifiedFileCache.set(absolutePath, minified);
|
|
7154
|
+
return minified;
|
|
7155
|
+
};
|
|
7156
|
+
return parsed.diagnostics.filter((diagnostic) => diagnostic.code && isLintableSourceFile(diagnostic.filename) && !isMinifiedDiagnosticFile(diagnostic.filename) && !shouldSuppressLocalUseHookDiagnostic(diagnostic, rootDirectory)).map((diagnostic) => {
|
|
6308
7157
|
const { plugin, rule } = parseRuleCode(diagnostic.code);
|
|
6309
7158
|
const primaryLabel = diagnostic.labels[0];
|
|
6310
7159
|
const cleaned = cleanDiagnosticMessage(diagnostic.message, diagnostic.help, plugin, rule, project);
|
|
@@ -6313,6 +7162,7 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
6313
7162
|
plugin,
|
|
6314
7163
|
rule,
|
|
6315
7164
|
severity: diagnostic.severity,
|
|
7165
|
+
title: resolveDiagnosticTitle(plugin, rule),
|
|
6316
7166
|
message: cleaned.message,
|
|
6317
7167
|
help: cleaned.help,
|
|
6318
7168
|
url: diagnostic.url,
|
|
@@ -6436,6 +7286,7 @@ const spawnOxlint = (args, rootDirectory, nodeBinaryPath, spawnTimeoutMs = OXLIN
|
|
|
6436
7286
|
*/
|
|
6437
7287
|
const spawnLintBatches = async (input) => {
|
|
6438
7288
|
const { baseArgs, fileBatches, rootDirectory, nodeBinaryPath, project, onPartialFailure, onFileProgress, spawnTimeoutMs, outputMaxBytes } = input;
|
|
7289
|
+
const concurrency = resolveScanConcurrency(input.concurrency ?? 1);
|
|
6439
7290
|
const totalFileCount = fileBatches.reduce((sum, batch) => sum + batch.length, 0);
|
|
6440
7291
|
const allDiagnostics = [];
|
|
6441
7292
|
const droppedFiles = [];
|
|
@@ -6455,20 +7306,31 @@ const spawnLintBatches = async (input) => {
|
|
|
6455
7306
|
return [...await spawnLintBatch(batch.slice(0, splitIndex)), ...await spawnLintBatch(batch.slice(splitIndex))];
|
|
6456
7307
|
}
|
|
6457
7308
|
};
|
|
7309
|
+
let startedFileCount = 0;
|
|
6458
7310
|
let scannedFileCount = 0;
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
const
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
|
|
7311
|
+
let displayedFileCount = 0;
|
|
7312
|
+
const progressTimer = onFileProgress && totalFileCount > 1 ? setInterval(() => {
|
|
7313
|
+
const ceiling = Math.min(startedFileCount, totalFileCount - 1);
|
|
7314
|
+
if (displayedFileCount < ceiling) {
|
|
7315
|
+
displayedFileCount += 1;
|
|
7316
|
+
onFileProgress(displayedFileCount, totalFileCount);
|
|
7317
|
+
}
|
|
7318
|
+
}, 50) : null;
|
|
7319
|
+
progressTimer?.unref?.();
|
|
7320
|
+
try {
|
|
7321
|
+
const batchResults = await mapWithConcurrency(fileBatches, concurrency, async (batch) => {
|
|
7322
|
+
startedFileCount += batch.length;
|
|
7323
|
+
const batchDiagnostics = await spawnLintBatch(batch);
|
|
7324
|
+
scannedFileCount += batch.length;
|
|
7325
|
+
if (onFileProgress) {
|
|
7326
|
+
displayedFileCount = Math.min(Math.max(displayedFileCount, scannedFileCount), totalFileCount);
|
|
7327
|
+
onFileProgress(displayedFileCount, totalFileCount);
|
|
6465
7328
|
}
|
|
6466
|
-
|
|
6467
|
-
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
onFileProgress?.(scannedFileCount, totalFileCount);
|
|
7329
|
+
return batchDiagnostics;
|
|
7330
|
+
});
|
|
7331
|
+
for (const batchDiagnostics of batchResults) allDiagnostics.push(...batchDiagnostics);
|
|
7332
|
+
} finally {
|
|
7333
|
+
if (progressTimer !== null) clearInterval(progressTimer);
|
|
6472
7334
|
}
|
|
6473
7335
|
if (droppedFiles.length > 0 && onPartialFailure) {
|
|
6474
7336
|
const previewFiles = droppedFiles.slice(0, 3).join(", ");
|
|
@@ -6595,7 +7457,8 @@ const runOxlint = async (options) => {
|
|
|
6595
7457
|
onPartialFailure,
|
|
6596
7458
|
onFileProgress: options.onFileProgress,
|
|
6597
7459
|
spawnTimeoutMs,
|
|
6598
|
-
outputMaxBytes
|
|
7460
|
+
outputMaxBytes,
|
|
7461
|
+
concurrency: options.concurrency
|
|
6599
7462
|
});
|
|
6600
7463
|
writeOxlintConfig(configPath, buildConfig(extendsPaths));
|
|
6601
7464
|
try {
|
|
@@ -6663,6 +7526,7 @@ var Linter = class Linter extends Context.Service()("react-doctor/Linter") {
|
|
|
6663
7526
|
const partialFailures = yield* LintPartialFailures;
|
|
6664
7527
|
const spawnTimeoutMs = yield* OxlintSpawnTimeoutMs;
|
|
6665
7528
|
const outputMaxBytes = yield* OxlintOutputMaxBytes;
|
|
7529
|
+
const concurrency = yield* OxlintConcurrency;
|
|
6666
7530
|
const collectedFailures = [];
|
|
6667
7531
|
const diagnostics = yield* Effect.tryPromise({
|
|
6668
7532
|
try: () => runOxlint({
|
|
@@ -6681,7 +7545,8 @@ var Linter = class Linter extends Context.Service()("react-doctor/Linter") {
|
|
|
6681
7545
|
},
|
|
6682
7546
|
onFileProgress: input.onFileProgress,
|
|
6683
7547
|
spawnTimeoutMs,
|
|
6684
|
-
outputMaxBytes
|
|
7548
|
+
outputMaxBytes,
|
|
7549
|
+
concurrency
|
|
6685
7550
|
}),
|
|
6686
7551
|
catch: ensureReactDoctorError
|
|
6687
7552
|
});
|
|
@@ -6727,7 +7592,8 @@ var Progress = class Progress extends Context.Service()("react-doctor/Progress")
|
|
|
6727
7592
|
static layerNoop = Layer.succeed(Progress, Progress.of({ start: () => Effect.succeed({
|
|
6728
7593
|
update: () => Effect.void,
|
|
6729
7594
|
succeed: () => Effect.void,
|
|
6730
|
-
fail: () => Effect.void
|
|
7595
|
+
fail: () => Effect.void,
|
|
7596
|
+
stop: () => Effect.void
|
|
6731
7597
|
}) }));
|
|
6732
7598
|
static layerCapture = Layer.effect(Progress, Effect.map(ProgressCapture, (events) => Progress.of({ start: (text) => Effect.gen(function* () {
|
|
6733
7599
|
yield* Ref.update(events, (existing) => [...existing, {
|
|
@@ -6746,6 +7612,10 @@ var Progress = class Progress extends Context.Service()("react-doctor/Progress")
|
|
|
6746
7612
|
fail: (displayText) => Ref.update(events, (existing) => [...existing, {
|
|
6747
7613
|
_tag: "Failed",
|
|
6748
7614
|
text: displayText
|
|
7615
|
+
}]),
|
|
7616
|
+
stop: () => Ref.update(events, (existing) => [...existing, {
|
|
7617
|
+
_tag: "Stopped",
|
|
7618
|
+
text
|
|
6749
7619
|
}])
|
|
6750
7620
|
};
|
|
6751
7621
|
}) }))).pipe(Layer.provideMerge(ProgressCapture.layer));
|
|
@@ -6817,17 +7687,21 @@ var Reporter = class Reporter extends Context.Service()("react-doctor/Reporter")
|
|
|
6817
7687
|
});
|
|
6818
7688
|
}));
|
|
6819
7689
|
};
|
|
6820
|
-
const
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
|
|
6826
|
-
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
7690
|
+
const RulePrioritySchema = Schema.Struct({
|
|
7691
|
+
priority: Schema.NullOr(Schema.Number),
|
|
7692
|
+
tier: Schema.Literals([
|
|
7693
|
+
"P0",
|
|
7694
|
+
"P1",
|
|
7695
|
+
"P2",
|
|
7696
|
+
"P3"
|
|
7697
|
+
])
|
|
7698
|
+
});
|
|
7699
|
+
const ScoreApiResponseSchema = Schema.Struct({
|
|
7700
|
+
score: Schema.Number,
|
|
7701
|
+
label: Schema.String,
|
|
7702
|
+
rules: Schema.optional(Schema.Record(Schema.String, RulePrioritySchema))
|
|
7703
|
+
});
|
|
7704
|
+
const parseScoreResult = (value) => Option.getOrNull(Schema.decodeUnknownOption(ScoreApiResponseSchema)(value));
|
|
6831
7705
|
const stripFilePaths = (diagnostics) => diagnostics.map(({ filePath: _filePath, ...rest }) => rest);
|
|
6832
7706
|
const isAbortError = (error) => error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError");
|
|
6833
7707
|
const describeFailure = (error) => {
|
|
@@ -6991,18 +7865,25 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
6991
7865
|
repo
|
|
6992
7866
|
}).pipe(Effect.orElseSucceed(() => null)) : Effect.succeed(null));
|
|
6993
7867
|
const lintIncludePaths = computeJsxIncludePaths([...input.includePaths]) ?? resolveLintIncludePaths(scanDirectory, resolvedConfig.config);
|
|
7868
|
+
const scannedFilePaths = input.suppressScanSummary ? (lintIncludePaths ?? (yield* filesService.listSourceFiles(scanDirectory))).map((relativePath) => path.resolve(scanDirectory, relativePath)) : [];
|
|
6994
7869
|
const beforeLint = hooks.beforeLint ?? NO_HOOKS.beforeLint;
|
|
6995
7870
|
const afterLint = hooks.afterLint ?? NO_HOOKS.afterLint;
|
|
6996
7871
|
yield* beforeLint(project, lintIncludePaths ?? void 0);
|
|
6997
7872
|
const isDiffMode = input.includePaths.length > 0;
|
|
7873
|
+
const showWarnings = input.warnings ?? resolvedConfig.config?.warnings ?? true;
|
|
6998
7874
|
const transform = buildDiagnosticPipeline({
|
|
6999
7875
|
rootDirectory: scanDirectory,
|
|
7000
7876
|
userConfig: resolvedConfig.config,
|
|
7001
7877
|
readFileLinesSync: fileReader(filesService, scanDirectory),
|
|
7002
|
-
respectInlineDisables: input.respectInlineDisables
|
|
7878
|
+
respectInlineDisables: input.respectInlineDisables,
|
|
7879
|
+
showWarnings
|
|
7003
7880
|
});
|
|
7004
7881
|
const applyPerElementPipeline = (rawStream) => rawStream.pipe(Stream.filterMap(filterMapNullable(transform.apply)), Stream.tap((diagnostic) => reporterService.emit(diagnostic)));
|
|
7005
|
-
const environmentDiagnostics = isDiffMode ? [] : [
|
|
7882
|
+
const environmentDiagnostics = isDiffMode ? [] : [
|
|
7883
|
+
...checkReducedMotion(scanDirectory),
|
|
7884
|
+
...checkPnpmHardening(scanDirectory),
|
|
7885
|
+
...checkExpoProject(scanDirectory, project)
|
|
7886
|
+
];
|
|
7006
7887
|
const envCollected = yield* Stream.runCollect(applyPerElementPipeline(Stream.fromIterable(environmentDiagnostics)));
|
|
7007
7888
|
const lintFailure = yield* Ref.make({
|
|
7008
7889
|
didFail: false,
|
|
@@ -7014,6 +7895,8 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
7014
7895
|
didFail: false,
|
|
7015
7896
|
reason: null
|
|
7016
7897
|
});
|
|
7898
|
+
const scanConcurrency = yield* OxlintConcurrency;
|
|
7899
|
+
const workerCountSuffix = scanConcurrency > 1 ? ` · ${scanConcurrency} workers` : "";
|
|
7017
7900
|
const scanProgress = yield* progressService.start("Scanning...");
|
|
7018
7901
|
const scanStartTime = Date.now();
|
|
7019
7902
|
let lastReportedTotalFileCount = 0;
|
|
@@ -7030,7 +7913,7 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
7030
7913
|
configSourceDirectory: resolvedConfig.configSourceDirectory ?? void 0,
|
|
7031
7914
|
onFileProgress: (scannedFileCount, totalFileCount) => {
|
|
7032
7915
|
lastReportedTotalFileCount = totalFileCount;
|
|
7033
|
-
Effect.runSync(scanProgress.update(`Scanning files (${scannedFileCount}/${totalFileCount})...`));
|
|
7916
|
+
Effect.runSync(scanProgress.update(`Scanning files (${scannedFileCount}/${totalFileCount})${workerCountSuffix}...`));
|
|
7034
7917
|
}
|
|
7035
7918
|
}).pipe(Stream.catchTag("ReactDoctorError", (error) => Stream.unwrap(Effect.gen(function* () {
|
|
7036
7919
|
yield* Ref.set(lintFailure, {
|
|
@@ -7045,7 +7928,7 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
7045
7928
|
const lintFailureState = yield* Ref.get(lintFailure);
|
|
7046
7929
|
yield* afterLint(lintFailureState.didFail);
|
|
7047
7930
|
if (lintFailureState.didFail) yield* scanProgress.fail(formatLintFailText(lintFailureState.reasonTag, process.version));
|
|
7048
|
-
const shouldRunDeadCode = input.runDeadCode && !isDiffMode;
|
|
7931
|
+
const shouldRunDeadCode = input.runDeadCode && !isDiffMode && (showWarnings || deadCodeMaySurfaceWhenWarningsHidden(resolvedConfig.config));
|
|
7049
7932
|
const deadCodeCollected = lintFailureState.didFail || !shouldRunDeadCode ? [] : yield* scanProgress.update("Analyzing dead code...").pipe(Effect.andThen(Stream.runCollect(applyPerElementPipeline(deadCodeService.run({
|
|
7050
7933
|
rootDirectory: scanDirectory,
|
|
7051
7934
|
userConfig: resolvedConfig.config
|
|
@@ -7057,10 +7940,12 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
7057
7940
|
return Stream.empty;
|
|
7058
7941
|
}))))))));
|
|
7059
7942
|
const deadCodeFailureState = yield* Ref.get(deadCodeFailure);
|
|
7060
|
-
const
|
|
7943
|
+
const scanElapsedMilliseconds = Date.now() - scanStartTime;
|
|
7944
|
+
const scanElapsedSeconds = (scanElapsedMilliseconds / 1e3).toFixed(1);
|
|
7061
7945
|
const totalFileCount = lastReportedTotalFileCount || (lintIncludePaths?.length ?? project.sourceFileCount);
|
|
7062
7946
|
if (!lintFailureState.didFail) if (deadCodeFailureState.didFail) yield* scanProgress.fail(DEAD_CODE_FAIL_TEXT);
|
|
7063
|
-
else yield* scanProgress.
|
|
7947
|
+
else if (input.suppressScanSummary) yield* scanProgress.stop();
|
|
7948
|
+
else yield* scanProgress.succeed(`Scanned ${totalFileCount} ${totalFileCount === 1 ? "file" : "files"} in ${scanElapsedSeconds}s${workerCountSuffix}`);
|
|
7064
7949
|
yield* reporterService.finalize;
|
|
7065
7950
|
const finalDiagnostics = [
|
|
7066
7951
|
...envCollected,
|
|
@@ -7100,7 +7985,10 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
7100
7985
|
lintFailureReasonKind: lintFailureState.reasonKind,
|
|
7101
7986
|
lintPartialFailures,
|
|
7102
7987
|
didDeadCodeFail: deadCodeFailureState.didFail,
|
|
7103
|
-
deadCodeFailureReason: deadCodeFailureState.reason
|
|
7988
|
+
deadCodeFailureReason: deadCodeFailureState.reason,
|
|
7989
|
+
scannedFileCount: totalFileCount,
|
|
7990
|
+
scannedFilePaths,
|
|
7991
|
+
scanElapsedMilliseconds
|
|
7104
7992
|
};
|
|
7105
7993
|
}).pipe(Effect.withSpan("runInspect", { attributes: {
|
|
7106
7994
|
"inspect.directory": input.directory,
|
|
@@ -7109,7 +7997,6 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
7109
7997
|
"inspect.isCi": input.isCi,
|
|
7110
7998
|
"inspect.scoreSurface": input.scoreSurface ?? "score"
|
|
7111
7999
|
} }));
|
|
7112
|
-
Layer.mergeAll(Project.layerNode, Config.layerNode, DeadCode.layerNode, Files.layerNode, Git.layerNode, Linter.layerOxlint, LintPartialFailures.layerLive, Progress.layerNoop, Reporter.layerNoop, Score.layerHttp);
|
|
7113
8000
|
const parseNodeVersion = (versionString) => {
|
|
7114
8001
|
const [major = 0, minor = 0, patch = 0] = versionString.replace(/^v/, "").trim().split(".").map(Number);
|
|
7115
8002
|
return {
|
|
@@ -7226,7 +8113,7 @@ const isPathInsideDirectory = (childAbsolutePath, parentAbsolutePath) => {
|
|
|
7226
8113
|
static layerNode = Layer.effect(StagedFiles, Effect.gen(function* () {
|
|
7227
8114
|
const git = yield* Git;
|
|
7228
8115
|
return StagedFiles.of({
|
|
7229
|
-
discoverSourceFiles: (directory) => git.stagedFilePaths(directory).pipe(Effect.map((entries) => entries.filter(
|
|
8116
|
+
discoverSourceFiles: (directory) => git.stagedFilePaths(directory).pipe(Effect.map((entries) => entries.filter(isLintableSourceFile))),
|
|
7230
8117
|
materialize: ({ directory, stagedFiles, tempDirectory }) => Effect.gen(function* () {
|
|
7231
8118
|
const materializedFiles = [];
|
|
7232
8119
|
const resolvedTempDirectory = path.resolve(tempDirectory);
|
|
@@ -7408,6 +8295,26 @@ const buildJsonReport = (input) => {
|
|
|
7408
8295
|
};
|
|
7409
8296
|
};
|
|
7410
8297
|
/**
|
|
8298
|
+
* Single source of truth for the skipped-check accounting shared by the
|
|
8299
|
+
* CLI renderer (`react-doctor/src/inspect.ts → finalizeAndRender`) and the
|
|
8300
|
+
* programmatic shell (`@react-doctor/api → diagnose()`). Both surface a
|
|
8301
|
+
* failed lint / dead-code pass instead of a false "all clear", so the
|
|
8302
|
+
* branch logic lives here once.
|
|
8303
|
+
*/
|
|
8304
|
+
const buildSkippedChecks = (input) => {
|
|
8305
|
+
const skippedChecks = [];
|
|
8306
|
+
if (input.didLintFail) skippedChecks.push("lint");
|
|
8307
|
+
if (input.didDeadCodeFail) skippedChecks.push("dead-code");
|
|
8308
|
+
const skippedCheckReasons = {};
|
|
8309
|
+
if (input.didLintFail && input.lintFailureReason !== null) skippedCheckReasons.lint = input.lintFailureReason;
|
|
8310
|
+
else if (input.lintPartialFailures.length > 0) skippedCheckReasons["lint:partial"] = input.lintPartialFailures.join("; ");
|
|
8311
|
+
if (input.didDeadCodeFail && input.deadCodeFailureReason !== null) skippedCheckReasons["dead-code"] = input.deadCodeFailureReason;
|
|
8312
|
+
return {
|
|
8313
|
+
skippedChecks,
|
|
8314
|
+
skippedCheckReasons
|
|
8315
|
+
};
|
|
8316
|
+
};
|
|
8317
|
+
/**
|
|
7411
8318
|
* Programmatic façade over `Git.diffSelection`. Async because the
|
|
7412
8319
|
* Git service runs through Effect's `ChildProcess` (true subprocess
|
|
7413
8320
|
* spawn, not `spawnSync`).
|
|
@@ -7435,7 +8342,7 @@ const getDiffInfo = (directory, explicitBaseBranch) => Effect.runPromise(Effect.
|
|
|
7435
8342
|
GitBaseBranchInvalid: (reason) => Effect.die(new Error(reason.detail)),
|
|
7436
8343
|
GitBaseBranchMissing: (reason) => Effect.die(new Error(reason.message))
|
|
7437
8344
|
})));
|
|
7438
|
-
const filterSourceFiles = (filePaths) => filePaths.filter(
|
|
8345
|
+
const filterSourceFiles = (filePaths) => filePaths.filter(isLintableSourceFile);
|
|
7439
8346
|
var import_picocolors = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
7440
8347
|
let p = process || {}, argv = p.argv || [], env = p.env || {};
|
|
7441
8348
|
let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
@@ -7513,7 +8420,7 @@ import_picocolors.default.red, import_picocolors.default.yellow, import_picocolo
|
|
|
7513
8420
|
const clearAutoSuppressionCaches = () => {};
|
|
7514
8421
|
//#endregion
|
|
7515
8422
|
//#region ../api/dist/index.js
|
|
7516
|
-
const
|
|
8423
|
+
const buildDiagnoseLayer = (configLayer = Config.layerNode) => Layer.mergeAll(Project.layerNode, configLayer, DeadCode.layerNode, Files.layerNode, Git.layerNode, Linter.layerOxlint, LintPartialFailures.layerLive, Progress.layerNoop, Reporter.layerNoop, Score.layerHttp);
|
|
7517
8424
|
const buildInspectProgram = (scanTarget, options, configOverride) => {
|
|
7518
8425
|
const effectiveConfig = configOverride ?? scanTarget.userConfig;
|
|
7519
8426
|
const includePaths = options.includePaths ?? [];
|
|
@@ -7522,6 +8429,7 @@ const buildInspectProgram = (scanTarget, options, configOverride) => {
|
|
|
7522
8429
|
includePaths,
|
|
7523
8430
|
customRulesOnly: effectiveConfig?.customRulesOnly ?? false,
|
|
7524
8431
|
respectInlineDisables: options.respectInlineDisables ?? effectiveConfig?.respectInlineDisables ?? true,
|
|
8432
|
+
warnings: options.warnings ?? effectiveConfig?.warnings ?? true,
|
|
7525
8433
|
adoptExistingLintConfig: effectiveConfig?.adoptExistingLintConfig ?? true,
|
|
7526
8434
|
ignoredTags: new Set(effectiveConfig?.ignore?.tags ?? []),
|
|
7527
8435
|
runDeadCode: options.deadCode ?? effectiveConfig?.deadCode ?? true,
|
|
@@ -7531,13 +8439,7 @@ const buildInspectProgram = (scanTarget, options, configOverride) => {
|
|
|
7531
8439
|
};
|
|
7532
8440
|
const outputToDiagnoseResult = (output, elapsedMilliseconds) => {
|
|
7533
8441
|
if (output.didLintFail && output.lintFailureReason !== null) console.error("Lint failed:", output.lintFailureReason);
|
|
7534
|
-
const skippedChecks =
|
|
7535
|
-
if (output.didLintFail) skippedChecks.push("lint");
|
|
7536
|
-
if (output.didDeadCodeFail) skippedChecks.push("dead-code");
|
|
7537
|
-
const skippedCheckReasons = {};
|
|
7538
|
-
if (output.didLintFail && output.lintFailureReason !== null) skippedCheckReasons.lint = output.lintFailureReason;
|
|
7539
|
-
else if (output.lintPartialFailures.length > 0) skippedCheckReasons["lint:partial"] = output.lintPartialFailures.join("; ");
|
|
7540
|
-
if (output.didDeadCodeFail && output.deadCodeFailureReason !== null) skippedCheckReasons["dead-code"] = output.deadCodeFailureReason;
|
|
8442
|
+
const { skippedChecks, skippedCheckReasons } = buildSkippedChecks(output);
|
|
7541
8443
|
return {
|
|
7542
8444
|
diagnostics: [...output.diagnostics],
|
|
7543
8445
|
score: output.score,
|
|
@@ -7549,8 +8451,8 @@ const outputToDiagnoseResult = (output, elapsedMilliseconds) => {
|
|
|
7549
8451
|
};
|
|
7550
8452
|
const diagnose = async (directory, options = {}) => {
|
|
7551
8453
|
const startTime = globalThis.performance.now();
|
|
7552
|
-
const program = buildInspectProgram(resolveScanTarget(directory), options);
|
|
7553
|
-
return outputToDiagnoseResult(await Effect.runPromise(restoreLegacyThrow(program.pipe(Effect.provide(
|
|
8454
|
+
const program = buildInspectProgram(await resolveScanTarget(directory), options);
|
|
8455
|
+
return outputToDiagnoseResult(await Effect.runPromise(restoreLegacyThrow(program.pipe(Effect.provide(buildDiagnoseLayer()), Effect.provide(layerOtlp)))), globalThis.performance.now() - startTime);
|
|
7554
8456
|
};
|
|
7555
8457
|
//#endregion
|
|
7556
8458
|
//#region src/index.ts
|
|
@@ -7559,6 +8461,7 @@ const clearCaches = () => {
|
|
|
7559
8461
|
clearConfigCache();
|
|
7560
8462
|
clearPackageJsonCache();
|
|
7561
8463
|
clearIgnorePatternsCache();
|
|
8464
|
+
clearPackageRoleCache();
|
|
7562
8465
|
clearAutoSuppressionCaches();
|
|
7563
8466
|
};
|
|
7564
8467
|
const toJsonReport = (result, options) => buildJsonReport({
|