react-doctor 0.2.14-dev.7b4ddf7 → 0.2.14-dev.8b313ba
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 +13 -0
- package/dist/cli.js +13835 -5738
- package/dist/index.d.ts +56 -13
- package/dist/index.js +443 -162
- package/package.json +8 -5
- package/dist/cli-logger-CSZagq1E.js +0 -7564
- package/dist/rolldown-runtime-uZX_iqCz.js +0 -35
package/dist/index.js
CHANGED
|
@@ -59,6 +59,7 @@ var Diagnostic = class extends Schema.Class("Diagnostic")({
|
|
|
59
59
|
plugin: Schema.String,
|
|
60
60
|
rule: Schema.String,
|
|
61
61
|
severity: Severity,
|
|
62
|
+
title: Schema.optional(Schema.String),
|
|
62
63
|
message: Schema.String,
|
|
63
64
|
help: Schema.String,
|
|
64
65
|
url: Schema.optional(Schema.String),
|
|
@@ -2094,6 +2095,8 @@ const isFile = (filePath) => {
|
|
|
2094
2095
|
}
|
|
2095
2096
|
};
|
|
2096
2097
|
const SOURCE_FILE_PATTERN = /\.(tsx?|jsx?)$/;
|
|
2098
|
+
const GENERATED_BUNDLE_FILE_PATTERN = /\.(iife|umd|global|min)\.js$/i;
|
|
2099
|
+
const MINIFIED_SNIFF_BYTES = 65536;
|
|
2097
2100
|
const GIT_LS_FILES_MAX_BUFFER_BYTES = 50 * 1024 * 1024;
|
|
2098
2101
|
const IGNORED_DIRECTORIES = new Set([
|
|
2099
2102
|
".git",
|
|
@@ -2109,6 +2112,34 @@ const IGNORED_DIRECTORIES = new Set([
|
|
|
2109
2112
|
"out",
|
|
2110
2113
|
"storybook-static"
|
|
2111
2114
|
]);
|
|
2115
|
+
const isLintableSourceFile = (filePath) => SOURCE_FILE_PATTERN.test(filePath) && !GENERATED_BUNDLE_FILE_PATTERN.test(filePath);
|
|
2116
|
+
const isMinifiedSource = (absolutePath) => {
|
|
2117
|
+
let fileDescriptor;
|
|
2118
|
+
try {
|
|
2119
|
+
fileDescriptor = fs.openSync(absolutePath, "r");
|
|
2120
|
+
const buffer = Buffer.alloc(MINIFIED_SNIFF_BYTES);
|
|
2121
|
+
const bytesRead = fs.readSync(fileDescriptor, buffer, 0, MINIFIED_SNIFF_BYTES, 0);
|
|
2122
|
+
const prefix = buffer.toString("utf8", 0, bytesRead);
|
|
2123
|
+
const lines = prefix.split("\n");
|
|
2124
|
+
const longestLineLength = lines.reduce((longest, line) => Math.max(longest, line.length), 0);
|
|
2125
|
+
const averageLineLength = prefix.length / lines.length;
|
|
2126
|
+
return longestLineLength > 1e3 && averageLineLength > 500;
|
|
2127
|
+
} catch {
|
|
2128
|
+
return false;
|
|
2129
|
+
} finally {
|
|
2130
|
+
if (fileDescriptor !== void 0) fs.closeSync(fileDescriptor);
|
|
2131
|
+
}
|
|
2132
|
+
};
|
|
2133
|
+
const isLargeMinifiedFile = (absolutePath) => {
|
|
2134
|
+
let sizeBytes;
|
|
2135
|
+
try {
|
|
2136
|
+
sizeBytes = fs.statSync(absolutePath).size;
|
|
2137
|
+
} catch {
|
|
2138
|
+
return false;
|
|
2139
|
+
}
|
|
2140
|
+
if (sizeBytes < 2e4) return false;
|
|
2141
|
+
return isMinifiedSource(absolutePath);
|
|
2142
|
+
};
|
|
2112
2143
|
const IGNORABLE_READDIR_ERROR_CODES = new Set([
|
|
2113
2144
|
"EACCES",
|
|
2114
2145
|
"EPERM",
|
|
@@ -2139,7 +2170,7 @@ const countSourceFilesViaFilesystem = (rootDirectory) => {
|
|
|
2139
2170
|
if (!entry.name.startsWith(".") && !IGNORED_DIRECTORIES.has(entry.name)) stack.push(path.join(currentDirectory, entry.name));
|
|
2140
2171
|
continue;
|
|
2141
2172
|
}
|
|
2142
|
-
if (entry.isFile() &&
|
|
2173
|
+
if (entry.isFile() && isLintableSourceFile(entry.name) && !isLargeMinifiedFile(path.join(currentDirectory, entry.name))) count++;
|
|
2143
2174
|
}
|
|
2144
2175
|
}
|
|
2145
2176
|
return count;
|
|
@@ -2157,7 +2188,7 @@ const countSourceFilesViaGit = (rootDirectory) => {
|
|
|
2157
2188
|
maxBuffer: GIT_LS_FILES_MAX_BUFFER_BYTES
|
|
2158
2189
|
});
|
|
2159
2190
|
if (result.error || result.status !== 0) return null;
|
|
2160
|
-
return result.stdout.split("\0").filter((filePath) => filePath.length > 0 &&
|
|
2191
|
+
return result.stdout.split("\0").filter((filePath) => filePath.length > 0 && isLintableSourceFile(filePath) && !isLargeMinifiedFile(path.resolve(rootDirectory, filePath))).length;
|
|
2161
2192
|
};
|
|
2162
2193
|
const countSourceFiles = (rootDirectory) => countSourceFilesViaGit(rootDirectory) ?? countSourceFilesViaFilesystem(rootDirectory);
|
|
2163
2194
|
const cachedPackageJsons = /* @__PURE__ */ new Map();
|
|
@@ -3240,7 +3271,15 @@ const STAGED_FILES_PROJECT_CONFIG_FILENAMES = [
|
|
|
3240
3271
|
];
|
|
3241
3272
|
const OXLINT_OUTPUT_MAX_BYTES = 50 * 1024 * 1024;
|
|
3242
3273
|
const OXLINT_SPAWN_TIMEOUT_MS = 6e4;
|
|
3274
|
+
const DEAD_CODE_WORKER_MAX_OLD_SPACE_MB = 8192;
|
|
3243
3275
|
const RECOMMENDED_PNPM_MINIMUM_RELEASE_AGE_MINUTES = 10080;
|
|
3276
|
+
const DIAGNOSTIC_CATEGORY_BUCKETS = [
|
|
3277
|
+
"Security",
|
|
3278
|
+
"Bugs",
|
|
3279
|
+
"Performance",
|
|
3280
|
+
"Accessibility",
|
|
3281
|
+
"Maintainability"
|
|
3282
|
+
];
|
|
3244
3283
|
const MAX_GLOB_PATTERN_LENGTH_CHARS = 1024;
|
|
3245
3284
|
const CONFIG_CACHE_TTL_MS = 300 * 1e3;
|
|
3246
3285
|
var InvalidGlobPatternError = class extends Error {
|
|
@@ -3862,10 +3901,13 @@ const collectStringSet = (values) => {
|
|
|
3862
3901
|
* wins over `test-noise`)
|
|
3863
3902
|
* 2. severity overrides (top-level `rules` / `categories`, with
|
|
3864
3903
|
* `"off"` dropping)
|
|
3865
|
-
* 3.
|
|
3866
|
-
*
|
|
3904
|
+
* 3. warning suppression (only when `showWarnings` is false: drops every
|
|
3905
|
+
* `"warning"`-severity diagnostic unless a severity override opts a
|
|
3906
|
+
* specific rule / category back in)
|
|
3907
|
+
* 4. ignore filters (rules / file patterns / per-file overrides)
|
|
3908
|
+
* 5. `rn-no-raw-text` suppression via configured `textComponents` and
|
|
3867
3909
|
* `rawTextWrapperComponents` (config-driven JSX enclosure checks)
|
|
3868
|
-
*
|
|
3910
|
+
* 6. inline suppressions (`// react-doctor-disable-next-line ...`)
|
|
3869
3911
|
*
|
|
3870
3912
|
* Returns `null` when the diagnostic is dropped, the (possibly
|
|
3871
3913
|
* severity-restamped) diagnostic otherwise.
|
|
@@ -3875,7 +3917,7 @@ const collectStringSet = (values) => {
|
|
|
3875
3917
|
* `mergeAndFilterDiagnostics` wrapper apply this closure per element.
|
|
3876
3918
|
*/
|
|
3877
3919
|
const buildDiagnosticPipeline = (input) => {
|
|
3878
|
-
const { rootDirectory, userConfig, readFileLinesSync, respectInlineDisables } = input;
|
|
3920
|
+
const { rootDirectory, userConfig, readFileLinesSync, respectInlineDisables, showWarnings } = input;
|
|
3879
3921
|
const severityControls = buildRuleSeverityControls(userConfig);
|
|
3880
3922
|
const ignoredRules = new Set(Array.isArray(userConfig?.ignore?.rules) ? userConfig.ignore.rules.filter((rule) => typeof rule === "string") : []);
|
|
3881
3923
|
const ignoredFilePatterns = compileIgnoredFilePatterns(userConfig);
|
|
@@ -3925,15 +3967,17 @@ const buildDiagnosticPipeline = (input) => {
|
|
|
3925
3967
|
return { apply: (diagnostic) => {
|
|
3926
3968
|
if (shouldAutoSuppress(diagnostic)) return null;
|
|
3927
3969
|
let current = diagnostic;
|
|
3970
|
+
let explicitSeverityOverride;
|
|
3928
3971
|
if (severityControls) {
|
|
3929
3972
|
const { ruleKey, category } = getDiagnosticRuleIdentity(current);
|
|
3930
|
-
|
|
3973
|
+
explicitSeverityOverride = resolveRuleSeverityOverride({
|
|
3931
3974
|
ruleKey,
|
|
3932
3975
|
category
|
|
3933
3976
|
}, severityControls);
|
|
3934
|
-
if (
|
|
3935
|
-
if (
|
|
3977
|
+
if (explicitSeverityOverride === "off") return null;
|
|
3978
|
+
if (explicitSeverityOverride !== void 0) current = restampSeverity(current, explicitSeverityOverride);
|
|
3936
3979
|
}
|
|
3980
|
+
if (!showWarnings && current.severity === "warning" && explicitSeverityOverride !== "warn") return null;
|
|
3937
3981
|
if (userConfig) {
|
|
3938
3982
|
if (isRuleIgnored(`${current.plugin}/${current.rule}`)) return null;
|
|
3939
3983
|
if (isFileIgnoredByPatterns(current.filePath, rootDirectory, ignoredFilePatterns)) return null;
|
|
@@ -4165,10 +4209,18 @@ const VALID_RULE_SEVERITIES = [
|
|
|
4165
4209
|
"warn",
|
|
4166
4210
|
"off"
|
|
4167
4211
|
];
|
|
4212
|
+
const KNOWN_CATEGORY_LABEL = DIAGNOSTIC_CATEGORY_BUCKETS.join(", ");
|
|
4213
|
+
const isDiagnosticCategoryBucket = (value) => DIAGNOSTIC_CATEGORY_BUCKETS.includes(value);
|
|
4214
|
+
const filterKnownCategories = (fieldName, categories) => categories.filter((category) => {
|
|
4215
|
+
if (isDiagnosticCategoryBucket(category)) return true;
|
|
4216
|
+
warnConfigIssue(`config field "${fieldName}" lists "${category}", which is not a known category (expected one of: ${KNOWN_CATEGORY_LABEL}); ignoring the entry.`);
|
|
4217
|
+
return false;
|
|
4218
|
+
});
|
|
4168
4219
|
const BOOLEAN_FIELD_NAMES = [
|
|
4169
4220
|
"lint",
|
|
4170
4221
|
"deadCode",
|
|
4171
4222
|
"verbose",
|
|
4223
|
+
"warnings",
|
|
4172
4224
|
"customRulesOnly",
|
|
4173
4225
|
"share",
|
|
4174
4226
|
"noScore",
|
|
@@ -4217,13 +4269,15 @@ const validateSurfaceControls = (surface, rawControls) => {
|
|
|
4217
4269
|
warnConfigIssue(`config field "surfaces.${surface}" must be an object (got ${typeof rawControls}); ignoring this surface.`);
|
|
4218
4270
|
return;
|
|
4219
4271
|
}
|
|
4220
|
-
const
|
|
4272
|
+
const validatedSurfaceControls = {};
|
|
4221
4273
|
for (const fieldName of SURFACE_CONTROL_FIELD_NAMES) {
|
|
4222
4274
|
if (rawControls[fieldName] === void 0) continue;
|
|
4223
|
-
const
|
|
4224
|
-
|
|
4275
|
+
const qualifiedName = `surfaces.${surface}.${fieldName}`;
|
|
4276
|
+
const result = validateStringArrayField(qualifiedName, rawControls[fieldName]);
|
|
4277
|
+
if (result === void 0) continue;
|
|
4278
|
+
validatedSurfaceControls[fieldName] = fieldName === "includeCategories" || fieldName === "excludeCategories" ? filterKnownCategories(qualifiedName, result) : result;
|
|
4225
4279
|
}
|
|
4226
|
-
return
|
|
4280
|
+
return validatedSurfaceControls;
|
|
4227
4281
|
};
|
|
4228
4282
|
const validateSurfacesField = (rawSurfaces) => {
|
|
4229
4283
|
if (!isPlainObject$1(rawSurfaces)) {
|
|
@@ -4241,7 +4295,7 @@ const validateSurfacesField = (rawSurfaces) => {
|
|
|
4241
4295
|
}
|
|
4242
4296
|
return validated;
|
|
4243
4297
|
};
|
|
4244
|
-
const validateSeverityMap = (fieldName, rawMap) => {
|
|
4298
|
+
const validateSeverityMap = (fieldName, rawMap, keysAreCategories = false) => {
|
|
4245
4299
|
if (!isPlainObject$1(rawMap)) {
|
|
4246
4300
|
warnConfigIssue(`config field "${fieldName}" must be an object (got ${typeof rawMap}); ignoring this field.`);
|
|
4247
4301
|
return;
|
|
@@ -4252,6 +4306,10 @@ const validateSeverityMap = (fieldName, rawMap) => {
|
|
|
4252
4306
|
warnConfigIssue(`config field "${fieldName}" has an empty key; ignoring the entry.`);
|
|
4253
4307
|
continue;
|
|
4254
4308
|
}
|
|
4309
|
+
if (keysAreCategories && !isDiagnosticCategoryBucket(key)) {
|
|
4310
|
+
warnConfigIssue(`config field "${fieldName}.${key}" is not a known category (expected one of: ${KNOWN_CATEGORY_LABEL}); ignoring the entry.`);
|
|
4311
|
+
continue;
|
|
4312
|
+
}
|
|
4255
4313
|
if (!isRuleSeverity(value)) {
|
|
4256
4314
|
warnConfigIssue(`config field "${fieldName}.${key}" must be one of: ${VALID_RULE_SEVERITIES.join(", ")} (got ${formatType(value)}); ignoring the entry.`);
|
|
4257
4315
|
continue;
|
|
@@ -4272,7 +4330,7 @@ const validateConfigTypes = (config) => {
|
|
|
4272
4330
|
for (const fieldName of BOOLEAN_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => coerceMaybeBooleanString(fieldName, value));
|
|
4273
4331
|
for (const fieldName of STRING_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => validateString(fieldName, value));
|
|
4274
4332
|
applyFieldValidator(config, validated, "surfaces", validateSurfacesField);
|
|
4275
|
-
for (const fieldName of SEVERITY_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => validateSeverityMap(fieldName, value));
|
|
4333
|
+
for (const fieldName of SEVERITY_FIELD_NAMES) applyFieldValidator(config, validated, fieldName, (value) => validateSeverityMap(fieldName, value, fieldName === "categories"));
|
|
4276
4334
|
applyFieldValidator(config, validated, "plugins", (value) => validateStringArrayField("plugins", value));
|
|
4277
4335
|
return validated;
|
|
4278
4336
|
};
|
|
@@ -4572,99 +4630,6 @@ const checkReducedMotion = (rootDirectory) => {
|
|
|
4572
4630
|
return [MISSING_REDUCED_MOTION_DIAGNOSTIC];
|
|
4573
4631
|
};
|
|
4574
4632
|
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
4633
|
const LINGUIST_ATTRIBUTE_PATTERN = /^linguist-(?:vendored|generated)(?:=([a-zA-Z0-9]+))?$/i;
|
|
4669
4634
|
const FALSY_VALUES = new Set([
|
|
4670
4635
|
"false",
|
|
@@ -4746,6 +4711,30 @@ const collectIgnorePatterns = (rootDirectory) => {
|
|
|
4746
4711
|
cachedPatternsByRoot.set(rootDirectory, patterns);
|
|
4747
4712
|
return patterns;
|
|
4748
4713
|
};
|
|
4714
|
+
/**
|
|
4715
|
+
* Resolves a path to its canonical, symlink-free form, falling back to
|
|
4716
|
+
* the input when it cannot be realpath'd (broken symlink, permission
|
|
4717
|
+
* error) so a best-effort normalization never throws.
|
|
4718
|
+
*
|
|
4719
|
+
* deslop's dead-code module graph is collected with `fast-glob` (which
|
|
4720
|
+
* keeps the scan root's symlinks intact) while imports are resolved
|
|
4721
|
+
* through `oxc-resolver` (which returns realpath'd targets). When the
|
|
4722
|
+
* project root sits behind a symlink — e.g. macOS iCloud-synced
|
|
4723
|
+
* `~/Documents` / `~/Desktop`, or a symlinked checkout — those two path
|
|
4724
|
+
* spaces diverge: every resolved import misses the graph and the files
|
|
4725
|
+
* they point at (commonly every `@/…` alias target) are mis-reported as
|
|
4726
|
+
* unreachable. Canonicalizing the root before the scan keeps both path
|
|
4727
|
+
* spaces in agreement.
|
|
4728
|
+
*/
|
|
4729
|
+
const toCanonicalPath = (filePath) => {
|
|
4730
|
+
try {
|
|
4731
|
+
return fs.realpathSync(filePath);
|
|
4732
|
+
} catch {
|
|
4733
|
+
return filePath;
|
|
4734
|
+
}
|
|
4735
|
+
};
|
|
4736
|
+
const DEAD_CODE_PLUGIN = "deslop";
|
|
4737
|
+
const DEAD_CODE_CATEGORY = "Maintainability";
|
|
4749
4738
|
const TSCONFIG_FILENAMES$1 = ["tsconfig.json", "tsconfig.base.json"];
|
|
4750
4739
|
const DEAD_CODE_WORKER_SCRIPT = `
|
|
4751
4740
|
const inputChunks = [];
|
|
@@ -4921,7 +4910,11 @@ const buildDeadCodeWorkerError = (workerError) => {
|
|
|
4921
4910
|
return error;
|
|
4922
4911
|
};
|
|
4923
4912
|
const createDeadCodeWorker = (input) => {
|
|
4924
|
-
const child = spawn(process.execPath, [
|
|
4913
|
+
const child = spawn(process.execPath, [
|
|
4914
|
+
`--max-old-space-size=${DEAD_CODE_WORKER_MAX_OLD_SPACE_MB}`,
|
|
4915
|
+
"-e",
|
|
4916
|
+
DEAD_CODE_WORKER_SCRIPT
|
|
4917
|
+
], {
|
|
4925
4918
|
stdio: [
|
|
4926
4919
|
"pipe",
|
|
4927
4920
|
"pipe",
|
|
@@ -4996,7 +4989,8 @@ const runDeadCodeWorkerWithTimeout = (handle, timeoutMs) => new Promise((resolve
|
|
|
4996
4989
|
});
|
|
4997
4990
|
});
|
|
4998
4991
|
const checkDeadCode = async (options) => {
|
|
4999
|
-
const {
|
|
4992
|
+
const { userConfig } = options;
|
|
4993
|
+
const rootDirectory = toCanonicalPath(options.rootDirectory);
|
|
5000
4994
|
if (!fs.existsSync(path.join(rootDirectory, "package.json"))) return [];
|
|
5001
4995
|
const ignorePatterns = collectDeadCodeIgnorePatterns(rootDirectory, userConfig);
|
|
5002
4996
|
const result = parseDeadCodeWorkerResult(await runDeadCodeWorkerWithTimeout((options.createWorker ?? createDeadCodeWorker)({
|
|
@@ -5009,59 +5003,162 @@ const checkDeadCode = async (options) => {
|
|
|
5009
5003
|
const diagnostics = [];
|
|
5010
5004
|
for (const unusedFile of result.unusedFiles) diagnostics.push({
|
|
5011
5005
|
filePath: toRelative(unusedFile.path),
|
|
5012
|
-
plugin:
|
|
5006
|
+
plugin: DEAD_CODE_PLUGIN,
|
|
5013
5007
|
rule: "unused-file",
|
|
5014
5008
|
severity: "warning",
|
|
5015
5009
|
message: "Unused file — not reachable from any entry point",
|
|
5016
5010
|
help: "Delete the file if it is truly unreachable, or import it from an entry point.",
|
|
5017
5011
|
line: 0,
|
|
5018
5012
|
column: 0,
|
|
5019
|
-
category:
|
|
5013
|
+
category: DEAD_CODE_CATEGORY
|
|
5020
5014
|
});
|
|
5021
5015
|
for (const unusedExport of result.unusedExports) {
|
|
5022
5016
|
const label = unusedExport.isTypeOnly ? "type export" : "export";
|
|
5023
5017
|
diagnostics.push({
|
|
5024
5018
|
filePath: toRelative(unusedExport.path),
|
|
5025
|
-
plugin:
|
|
5019
|
+
plugin: DEAD_CODE_PLUGIN,
|
|
5026
5020
|
rule: unusedExport.isTypeOnly ? "unused-type" : "unused-export",
|
|
5027
5021
|
severity: "warning",
|
|
5028
5022
|
message: `Unused ${label}: \`${unusedExport.name}\``,
|
|
5029
5023
|
help: "Drop the `export` keyword (or remove the declaration) if no other module uses this symbol.",
|
|
5030
5024
|
line: unusedExport.line,
|
|
5031
5025
|
column: unusedExport.column,
|
|
5032
|
-
category:
|
|
5026
|
+
category: DEAD_CODE_CATEGORY
|
|
5033
5027
|
});
|
|
5034
5028
|
}
|
|
5035
5029
|
for (const unusedDependency of result.unusedDependencies) {
|
|
5036
5030
|
const label = unusedDependency.isDevDependency ? "devDependency" : "dependency";
|
|
5037
5031
|
diagnostics.push({
|
|
5038
5032
|
filePath: "package.json",
|
|
5039
|
-
plugin:
|
|
5033
|
+
plugin: DEAD_CODE_PLUGIN,
|
|
5040
5034
|
rule: unusedDependency.isDevDependency ? "unused-dev-dependency" : "unused-dependency",
|
|
5041
5035
|
severity: "warning",
|
|
5042
5036
|
message: `Unused ${label}: \`${unusedDependency.name}\``,
|
|
5043
5037
|
help: "Remove the dependency from package.json if it is genuinely unused.",
|
|
5044
5038
|
line: 0,
|
|
5045
5039
|
column: 0,
|
|
5046
|
-
category:
|
|
5040
|
+
category: DEAD_CODE_CATEGORY
|
|
5047
5041
|
});
|
|
5048
5042
|
}
|
|
5049
5043
|
for (const cycle of result.circularDependencies) {
|
|
5050
5044
|
if (cycle.files.length === 0) continue;
|
|
5051
5045
|
diagnostics.push({
|
|
5052
5046
|
filePath: toRelative(cycle.files[0]),
|
|
5053
|
-
plugin:
|
|
5047
|
+
plugin: DEAD_CODE_PLUGIN,
|
|
5054
5048
|
rule: "circular-dependency",
|
|
5055
5049
|
severity: "warning",
|
|
5056
5050
|
message: `Circular import cycle: ${cycle.files.map(toRelative).join(" → ")}`,
|
|
5057
5051
|
help: "Break the cycle by extracting the shared code into a third module that both files import.",
|
|
5058
5052
|
line: 0,
|
|
5059
5053
|
column: 0,
|
|
5060
|
-
category:
|
|
5054
|
+
category: DEAD_CODE_CATEGORY
|
|
5061
5055
|
});
|
|
5062
5056
|
}
|
|
5063
5057
|
return diagnostics;
|
|
5064
5058
|
};
|
|
5059
|
+
const DEAD_CODE_RULE_KEY_PREFIX = `${DEAD_CODE_PLUGIN}/`;
|
|
5060
|
+
const isSurfacingOverride = (override) => override === "warn" || override === "error";
|
|
5061
|
+
const deadCodeMaySurfaceWhenWarningsHidden = (userConfig) => {
|
|
5062
|
+
const severityControls = buildRuleSeverityControls(userConfig);
|
|
5063
|
+
if (!severityControls) return false;
|
|
5064
|
+
if (isSurfacingOverride(severityControls.categories?.["Maintainability"])) return true;
|
|
5065
|
+
for (const [ruleKey, override] of Object.entries(severityControls.rules ?? {})) if (ruleKey.startsWith(DEAD_CODE_RULE_KEY_PREFIX) && isSurfacingOverride(override)) return true;
|
|
5066
|
+
return false;
|
|
5067
|
+
};
|
|
5068
|
+
const toStringSet = (values) => {
|
|
5069
|
+
if (!values || values.length === 0) return /* @__PURE__ */ new Set();
|
|
5070
|
+
return new Set(values.filter((value) => typeof value === "string" && value.length > 0));
|
|
5071
|
+
};
|
|
5072
|
+
const buildResolvedControls = (surface, userControls) => {
|
|
5073
|
+
const excludeTags = new Set(DEFAULT_SURFACE_EXCLUDED_TAGS[surface]);
|
|
5074
|
+
const includeTags = toStringSet(userControls?.includeTags);
|
|
5075
|
+
for (const tag of includeTags) excludeTags.delete(tag);
|
|
5076
|
+
for (const tag of toStringSet(userControls?.excludeTags)) excludeTags.add(tag);
|
|
5077
|
+
return {
|
|
5078
|
+
includeTags,
|
|
5079
|
+
excludeTags,
|
|
5080
|
+
includeCategories: toStringSet(userControls?.includeCategories),
|
|
5081
|
+
excludeCategories: toStringSet(userControls?.excludeCategories),
|
|
5082
|
+
includeRuleKeys: toStringSet(userControls?.includeRules),
|
|
5083
|
+
excludeRuleKeys: toStringSet(userControls?.excludeRules)
|
|
5084
|
+
};
|
|
5085
|
+
};
|
|
5086
|
+
const intersects = (values, candidates) => values.some((value) => candidates.has(value));
|
|
5087
|
+
const isDiagnosticOnSurface = (diagnostic, surface, config) => {
|
|
5088
|
+
const resolved = buildResolvedControls(surface, config?.surfaces?.[surface]);
|
|
5089
|
+
const { ruleKey, category, tags } = getDiagnosticRuleIdentity(diagnostic);
|
|
5090
|
+
if (resolved.includeRuleKeys.has(ruleKey)) return true;
|
|
5091
|
+
if (resolved.includeCategories.has(category)) return true;
|
|
5092
|
+
if (intersects(tags, resolved.includeTags)) return true;
|
|
5093
|
+
if (resolved.excludeRuleKeys.has(ruleKey)) return false;
|
|
5094
|
+
if (resolved.excludeCategories.has(category)) return false;
|
|
5095
|
+
if (intersects(tags, resolved.excludeTags)) return false;
|
|
5096
|
+
return true;
|
|
5097
|
+
};
|
|
5098
|
+
const filterDiagnosticsForSurface = (diagnostics, surface, config) => diagnostics.filter((diagnostic) => isDiagnosticOnSurface(diagnostic, surface, config));
|
|
5099
|
+
const excludeMinifiedFiles = (rootDirectory, relativePaths) => relativePaths.filter((relativePath) => !isLargeMinifiedFile(path.resolve(rootDirectory, relativePath)));
|
|
5100
|
+
const listSourceFilesViaGit = (rootDirectory) => {
|
|
5101
|
+
const result = spawnSync("git", [
|
|
5102
|
+
"ls-files",
|
|
5103
|
+
"-z",
|
|
5104
|
+
"--cached",
|
|
5105
|
+
"--others",
|
|
5106
|
+
"--exclude-standard"
|
|
5107
|
+
], {
|
|
5108
|
+
cwd: rootDirectory,
|
|
5109
|
+
encoding: "utf-8",
|
|
5110
|
+
maxBuffer: GIT_LS_FILES_MAX_BUFFER_BYTES
|
|
5111
|
+
});
|
|
5112
|
+
if (result.error || result.status !== 0) return null;
|
|
5113
|
+
return result.stdout.split("\0").filter((filePath) => filePath.length > 0 && isLintableSourceFile(filePath));
|
|
5114
|
+
};
|
|
5115
|
+
const listSourceFilesViaFilesystem = (rootDirectory) => {
|
|
5116
|
+
const filePaths = [];
|
|
5117
|
+
const stack = [rootDirectory];
|
|
5118
|
+
while (stack.length > 0) {
|
|
5119
|
+
const currentDirectory = stack.pop();
|
|
5120
|
+
const entries = readDirectoryEntries(currentDirectory);
|
|
5121
|
+
for (const entry of entries) {
|
|
5122
|
+
const absolutePath = path.join(currentDirectory, entry.name);
|
|
5123
|
+
if (entry.isDirectory()) {
|
|
5124
|
+
if (!entry.name.startsWith(".") && !IGNORED_DIRECTORIES.has(entry.name)) stack.push(absolutePath);
|
|
5125
|
+
continue;
|
|
5126
|
+
}
|
|
5127
|
+
if (entry.isFile() && isLintableSourceFile(entry.name)) filePaths.push(path.relative(rootDirectory, absolutePath).replace(/\\/g, "/"));
|
|
5128
|
+
}
|
|
5129
|
+
}
|
|
5130
|
+
return filePaths;
|
|
5131
|
+
};
|
|
5132
|
+
const listSourceFiles = (rootDirectory) => excludeMinifiedFiles(rootDirectory, listSourceFilesViaGit(rootDirectory) ?? listSourceFilesViaFilesystem(rootDirectory));
|
|
5133
|
+
const resolveLintIncludePaths = (rootDirectory, userConfig) => {
|
|
5134
|
+
if (!Array.isArray(userConfig?.ignore?.files) || userConfig.ignore.files.length === 0) return;
|
|
5135
|
+
const ignoredPatterns = compileIgnoredFilePatterns(userConfig);
|
|
5136
|
+
return listSourceFiles(rootDirectory).filter((filePath) => {
|
|
5137
|
+
if (!JSX_FILE_PATTERN.test(filePath)) return false;
|
|
5138
|
+
return !isFileIgnoredByPatterns(filePath, rootDirectory, ignoredPatterns);
|
|
5139
|
+
});
|
|
5140
|
+
};
|
|
5141
|
+
var Config = class Config extends Context.Service()("react-doctor/Config") {
|
|
5142
|
+
static layerNode = Layer.effect(Config, Effect.gen(function* () {
|
|
5143
|
+
const cache = yield* Cache.make({
|
|
5144
|
+
capacity: 16,
|
|
5145
|
+
timeToLive: CONFIG_CACHE_TTL_MS,
|
|
5146
|
+
lookup: (directory) => Effect.sync(() => {
|
|
5147
|
+
const loaded = loadConfigWithSource(directory);
|
|
5148
|
+
const redirected = resolveConfigRootDir(loaded?.config ?? null, loaded?.sourceDirectory ?? null);
|
|
5149
|
+
return {
|
|
5150
|
+
config: loaded?.config ?? null,
|
|
5151
|
+
resolvedDirectory: redirected ?? directory,
|
|
5152
|
+
configSourceDirectory: loaded?.sourceDirectory ?? null
|
|
5153
|
+
};
|
|
5154
|
+
})
|
|
5155
|
+
});
|
|
5156
|
+
return Config.of({ resolve: Effect.fn("Config.resolve")(function* (directory) {
|
|
5157
|
+
return yield* Cache.get(cache, directory);
|
|
5158
|
+
}) });
|
|
5159
|
+
}));
|
|
5160
|
+
static layerOf = (resolved) => Layer.succeed(Config, Config.of({ resolve: () => Effect.succeed(resolved) }));
|
|
5161
|
+
};
|
|
5065
5162
|
/**
|
|
5066
5163
|
* `DeadCode` runs whole-project reachability analysis and streams
|
|
5067
5164
|
* diagnostics. Reachability is a whole-project property — the
|
|
@@ -5567,12 +5664,12 @@ const findFilesWithDisableDirectivesViaGit = async (rootDirectory, includePaths)
|
|
|
5567
5664
|
return null;
|
|
5568
5665
|
}
|
|
5569
5666
|
if (grepResult === null) return null;
|
|
5570
|
-
return grepResult.stdout.split("\n").filter((filePath) => filePath.length > 0 &&
|
|
5667
|
+
return grepResult.stdout.split("\n").filter((filePath) => filePath.length > 0 && isLintableSourceFile(filePath));
|
|
5571
5668
|
};
|
|
5572
5669
|
const findFilesWithDisableDirectivesViaFilesystem = (rootDirectory, includePaths) => {
|
|
5573
5670
|
const matches = [];
|
|
5574
5671
|
const checkFile = (relativePath) => {
|
|
5575
|
-
if (!
|
|
5672
|
+
if (!isLintableSourceFile(relativePath)) return;
|
|
5576
5673
|
const absolutePath = path.join(rootDirectory, relativePath);
|
|
5577
5674
|
let content;
|
|
5578
5675
|
try {
|
|
@@ -5939,6 +6036,149 @@ const appendReanimatedSharedValueHint = (help, rule, project) => {
|
|
|
5939
6036
|
if (!help) return REANIMATED_SHARED_VALUE_HINT;
|
|
5940
6037
|
return `${help}\n\n${REANIMATED_SHARED_VALUE_HINT}`;
|
|
5941
6038
|
};
|
|
6039
|
+
const REDACTED_PLACEHOLDER = "<redacted>";
|
|
6040
|
+
const KEEP_PREFIX = `$1${REDACTED_PLACEHOLDER}`;
|
|
6041
|
+
const KNOWN_SECRET_RULES = [
|
|
6042
|
+
{
|
|
6043
|
+
pattern: /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g,
|
|
6044
|
+
replacement: REDACTED_PLACEHOLDER
|
|
6045
|
+
},
|
|
6046
|
+
{
|
|
6047
|
+
pattern: /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g,
|
|
6048
|
+
replacement: REDACTED_PLACEHOLDER
|
|
6049
|
+
},
|
|
6050
|
+
{
|
|
6051
|
+
pattern: /(?<=:\/\/)[^\s/:@]+:[^\s/@]+(?=@)/g,
|
|
6052
|
+
replacement: REDACTED_PLACEHOLDER
|
|
6053
|
+
},
|
|
6054
|
+
{
|
|
6055
|
+
pattern: /\b(AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA|A3T[A-Z0-9])[0-9A-Z]{16,}/g,
|
|
6056
|
+
replacement: KEEP_PREFIX
|
|
6057
|
+
},
|
|
6058
|
+
{
|
|
6059
|
+
pattern: /\b(gh[pousr]_)[A-Za-z0-9]{36,}/g,
|
|
6060
|
+
replacement: KEEP_PREFIX
|
|
6061
|
+
},
|
|
6062
|
+
{
|
|
6063
|
+
pattern: /\b(github_pat_)[A-Za-z0-9_]{22,}/g,
|
|
6064
|
+
replacement: KEEP_PREFIX
|
|
6065
|
+
},
|
|
6066
|
+
{
|
|
6067
|
+
pattern: /\b(glpat-)[A-Za-z0-9_-]{20,}/g,
|
|
6068
|
+
replacement: KEEP_PREFIX
|
|
6069
|
+
},
|
|
6070
|
+
{
|
|
6071
|
+
pattern: /\b(xox[baprs]-)[A-Za-z0-9-]{10,}/g,
|
|
6072
|
+
replacement: KEEP_PREFIX
|
|
6073
|
+
},
|
|
6074
|
+
{
|
|
6075
|
+
pattern: /(?<=hooks\.slack\.com\/services\/)[A-Za-z0-9/+_-]{20,}/g,
|
|
6076
|
+
replacement: REDACTED_PLACEHOLDER
|
|
6077
|
+
},
|
|
6078
|
+
{
|
|
6079
|
+
pattern: /\b((?:sk|rk)_(?:live|test)_)[0-9A-Za-z]{10,}/g,
|
|
6080
|
+
replacement: KEEP_PREFIX
|
|
6081
|
+
},
|
|
6082
|
+
{
|
|
6083
|
+
pattern: /\b(sk-(?:proj-|ant-)?)[A-Za-z0-9_-]{20,}/g,
|
|
6084
|
+
replacement: KEEP_PREFIX
|
|
6085
|
+
},
|
|
6086
|
+
{
|
|
6087
|
+
pattern: /\b(AIza)[0-9A-Za-z_-]{35,}/g,
|
|
6088
|
+
replacement: KEEP_PREFIX
|
|
6089
|
+
},
|
|
6090
|
+
{
|
|
6091
|
+
pattern: /\b(ya29\.)[0-9A-Za-z_-]{20,}/g,
|
|
6092
|
+
replacement: KEEP_PREFIX
|
|
6093
|
+
},
|
|
6094
|
+
{
|
|
6095
|
+
pattern: /\b(npm_)[A-Za-z0-9]{36,}/g,
|
|
6096
|
+
replacement: KEEP_PREFIX
|
|
6097
|
+
},
|
|
6098
|
+
{
|
|
6099
|
+
pattern: /\b(SG\.)[A-Za-z0-9_-]{22,}\.[A-Za-z0-9_-]{43,}/g,
|
|
6100
|
+
replacement: KEEP_PREFIX
|
|
6101
|
+
},
|
|
6102
|
+
{
|
|
6103
|
+
pattern: /\b(SK)[0-9a-fA-F]{32,}/g,
|
|
6104
|
+
replacement: KEEP_PREFIX
|
|
6105
|
+
},
|
|
6106
|
+
{
|
|
6107
|
+
pattern: /\b(dop_v1_)[a-f0-9]{64,}/g,
|
|
6108
|
+
replacement: KEEP_PREFIX
|
|
6109
|
+
},
|
|
6110
|
+
{
|
|
6111
|
+
pattern: /\b(shp(?:at|ca|pa|ss)_)[a-fA-F0-9]{32,}/g,
|
|
6112
|
+
replacement: KEEP_PREFIX
|
|
6113
|
+
},
|
|
6114
|
+
{
|
|
6115
|
+
pattern: /\b(sq0[a-z]{3}-)[0-9A-Za-z_-]{22,}/g,
|
|
6116
|
+
replacement: KEEP_PREFIX
|
|
6117
|
+
},
|
|
6118
|
+
{
|
|
6119
|
+
pattern: /\b([0-9]{8,10}:AA)[0-9A-Za-z_-]{32,}/g,
|
|
6120
|
+
replacement: KEEP_PREFIX
|
|
6121
|
+
},
|
|
6122
|
+
{
|
|
6123
|
+
pattern: /(?<=\bBearer\s)[A-Za-z0-9._~+/=-]{16,}/g,
|
|
6124
|
+
replacement: REDACTED_PLACEHOLDER
|
|
6125
|
+
},
|
|
6126
|
+
{
|
|
6127
|
+
pattern: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g,
|
|
6128
|
+
replacement: REDACTED_PLACEHOLDER
|
|
6129
|
+
}
|
|
6130
|
+
];
|
|
6131
|
+
const CANDIDATE_TOKEN_PATTERN = /[A-Za-z0-9_][A-Za-z0-9_-]*/g;
|
|
6132
|
+
const HEX_DIGEST_PATTERN = /^(?:[0-9a-f]{32}|[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
6133
|
+
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
6134
|
+
const HAS_LETTER_PATTERN = /[A-Za-z]/;
|
|
6135
|
+
const HAS_DIGIT_PATTERN = /[0-9]/;
|
|
6136
|
+
const shannonEntropyBits = (value) => {
|
|
6137
|
+
const counts = /* @__PURE__ */ new Map();
|
|
6138
|
+
for (const char of value) counts.set(char, (counts.get(char) ?? 0) + 1);
|
|
6139
|
+
let bits = 0;
|
|
6140
|
+
for (const count of counts.values()) {
|
|
6141
|
+
const probability = count / value.length;
|
|
6142
|
+
bits -= probability * Math.log2(probability);
|
|
6143
|
+
}
|
|
6144
|
+
return bits;
|
|
6145
|
+
};
|
|
6146
|
+
const looksLikeHighEntropySecret = (token) => {
|
|
6147
|
+
if (token.length < 32) return false;
|
|
6148
|
+
if (!HAS_LETTER_PATTERN.test(token) || !HAS_DIGIT_PATTERN.test(token)) return false;
|
|
6149
|
+
if (HEX_DIGEST_PATTERN.test(token) || UUID_PATTERN.test(token)) return false;
|
|
6150
|
+
return shannonEntropyBits(token) >= 3;
|
|
6151
|
+
};
|
|
6152
|
+
const redactHighEntropyTokens = (text) => text.replace(CANDIDATE_TOKEN_PATTERN, (token) => looksLikeHighEntropySecret(token) ? REDACTED_PLACEHOLDER : token);
|
|
6153
|
+
/**
|
|
6154
|
+
* Masks API keys, tokens, private keys, credentialed URLs, and emails
|
|
6155
|
+
* found anywhere inside a free-text string, returning the scrubbed text.
|
|
6156
|
+
* Applied to every diagnostic's `message` / `help` at construction time
|
|
6157
|
+
* so secrets never reach the terminal, the JSON report, or the score
|
|
6158
|
+
* API — react-doctor must never echo or transmit a user's secrets.
|
|
6159
|
+
*
|
|
6160
|
+
* Provider tokens keep their non-secret, type-identifying prefix (e.g.
|
|
6161
|
+
* `sk_live_<redacted>`, `ghp_<redacted>`, `AKIA<redacted>`) so the leaked
|
|
6162
|
+
* credential's type stays visible; structural or unknown-format secrets
|
|
6163
|
+
* with no meaningful prefix are masked whole.
|
|
6164
|
+
*
|
|
6165
|
+
* Runs the high-precision known-shape detectors first, then a generic
|
|
6166
|
+
* entropy-gated sweep for unknown-format secrets. Idempotent: the inert
|
|
6167
|
+
* `<redacted>` placeholder matches none of the detectors and is too
|
|
6168
|
+
* short for the generic sweep, so re-running leaves the text unchanged.
|
|
6169
|
+
*
|
|
6170
|
+
* Accepts `unknown` on purpose: callers feed it diagnostic `message` /
|
|
6171
|
+
* `help` that originate from oxlint JSON, which is only shape-checked at
|
|
6172
|
+
* the top level (the per-field `string` types are assumed, not validated).
|
|
6173
|
+
* A malformed non-string value returns `""` instead of throwing on
|
|
6174
|
+
* `.replace`, so one bad diagnostic can't abort parsing the whole batch.
|
|
6175
|
+
*/
|
|
6176
|
+
const redactSensitiveText = (text) => {
|
|
6177
|
+
if (typeof text !== "string" || text === "") return "";
|
|
6178
|
+
let redacted = text;
|
|
6179
|
+
for (const rule of KNOWN_SECRET_RULES) redacted = redacted.replace(rule.pattern, rule.replacement);
|
|
6180
|
+
return redactHighEntropyTokens(redacted);
|
|
6181
|
+
};
|
|
5942
6182
|
const REACT_MODULE_SOURCE = "react";
|
|
5943
6183
|
const REQUIRE_IDENTIFIER = "require";
|
|
5944
6184
|
const USE_IDENTIFIER = "use";
|
|
@@ -6233,25 +6473,26 @@ const shouldSuppressLocalUseHookDiagnostic = (diagnostic, rootDirectory) => {
|
|
|
6233
6473
|
return bindingResolution !== null && !bindingResolution.isReactUseBinding;
|
|
6234
6474
|
};
|
|
6235
6475
|
const FILEPATH_WITH_LOCATION_PATTERN = /\S+\.\w+:\d+:\d+[\s\S]*$/;
|
|
6236
|
-
const
|
|
6476
|
+
const REACT_COMPILER_TITLE = "React Compiler can't optimize this";
|
|
6477
|
+
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
6478
|
const PLUGIN_CATEGORY_MAP = {
|
|
6238
|
-
react: "
|
|
6239
|
-
"react-hooks": "
|
|
6240
|
-
"react-hooks-js": "
|
|
6241
|
-
"react-doctor": "
|
|
6479
|
+
react: "Bugs",
|
|
6480
|
+
"react-hooks": "Bugs",
|
|
6481
|
+
"react-hooks-js": "Performance",
|
|
6482
|
+
"react-doctor": "Bugs",
|
|
6242
6483
|
"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: "
|
|
6484
|
+
effect: "Bugs",
|
|
6485
|
+
eslint: "Bugs",
|
|
6486
|
+
oxc: "Bugs",
|
|
6487
|
+
typescript: "Bugs",
|
|
6488
|
+
unicorn: "Bugs",
|
|
6489
|
+
import: "Performance",
|
|
6490
|
+
promise: "Bugs",
|
|
6491
|
+
n: "Bugs",
|
|
6492
|
+
node: "Bugs",
|
|
6493
|
+
vitest: "Bugs",
|
|
6494
|
+
jest: "Bugs",
|
|
6495
|
+
nextjs: "Bugs"
|
|
6255
6496
|
};
|
|
6256
6497
|
const lookupOwnString = (record, key) => Object.hasOwn(record, key) ? record[key] : void 0;
|
|
6257
6498
|
const getRuleRecommendation = (ruleName, project) => {
|
|
@@ -6259,7 +6500,16 @@ const getRuleRecommendation = (ruleName, project) => {
|
|
|
6259
6500
|
return reactDoctorPlugin.rules[ruleName]?.recommendation;
|
|
6260
6501
|
};
|
|
6261
6502
|
const getRuleCategory = (ruleName) => reactDoctorPlugin.rules[ruleName]?.category;
|
|
6503
|
+
const getRuleTitle = (ruleName) => reactDoctorPlugin.rules[ruleName]?.title;
|
|
6504
|
+
const resolveDiagnosticTitle = (plugin, rule) => plugin === "react-hooks-js" ? REACT_COMPILER_TITLE : getRuleTitle(rule);
|
|
6262
6505
|
const cleanDiagnosticMessage = (message, help, plugin, rule, project) => {
|
|
6506
|
+
const cleaned = resolveCleanedDiagnostic(typeof message === "string" ? message : "", typeof help === "string" ? help : "", plugin, rule, project);
|
|
6507
|
+
return {
|
|
6508
|
+
message: redactSensitiveText(cleaned.message),
|
|
6509
|
+
help: redactSensitiveText(cleaned.help)
|
|
6510
|
+
};
|
|
6511
|
+
};
|
|
6512
|
+
const resolveCleanedDiagnostic = (message, help, plugin, rule, project) => {
|
|
6263
6513
|
if (plugin === "react-hooks-js") return {
|
|
6264
6514
|
message: REACT_COMPILER_MESSAGE,
|
|
6265
6515
|
help: appendReanimatedSharedValueHint(message.replace(FILEPATH_WITH_LOCATION_PATTERN, "").trim() || help, rule, project)
|
|
@@ -6280,7 +6530,7 @@ const parseRuleCode = (code) => {
|
|
|
6280
6530
|
rule: match[2]
|
|
6281
6531
|
};
|
|
6282
6532
|
};
|
|
6283
|
-
const resolveDiagnosticCategory = (plugin, rule) => getRuleCategory(rule) ?? lookupOwnString(PLUGIN_CATEGORY_MAP, plugin) ?? "
|
|
6533
|
+
const resolveDiagnosticCategory = (plugin, rule) => getRuleCategory(rule) ?? lookupOwnString(PLUGIN_CATEGORY_MAP, plugin) ?? "Bugs";
|
|
6284
6534
|
const isOxlintOutput = (value) => {
|
|
6285
6535
|
if (typeof value !== "object" || value === null) return false;
|
|
6286
6536
|
const candidate = value;
|
|
@@ -6304,7 +6554,16 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
6304
6554
|
throw new ReactDoctorError({ reason: new OxlintOutputUnparseable({ preview: stdout.slice(0, 200) }) });
|
|
6305
6555
|
}
|
|
6306
6556
|
if (!isOxlintOutput(parsed)) throw new ReactDoctorError({ reason: new OxlintOutputUnparseable({ preview: stdout.slice(0, 200) }) });
|
|
6307
|
-
|
|
6557
|
+
const minifiedFileCache = /* @__PURE__ */ new Map();
|
|
6558
|
+
const isMinifiedDiagnosticFile = (filename) => {
|
|
6559
|
+
const absolutePath = path.isAbsolute(filename) ? filename : path.resolve(rootDirectory || ".", filename);
|
|
6560
|
+
const cached = minifiedFileCache.get(absolutePath);
|
|
6561
|
+
if (cached !== void 0) return cached;
|
|
6562
|
+
const minified = isMinifiedSource(absolutePath);
|
|
6563
|
+
minifiedFileCache.set(absolutePath, minified);
|
|
6564
|
+
return minified;
|
|
6565
|
+
};
|
|
6566
|
+
return parsed.diagnostics.filter((diagnostic) => diagnostic.code && isLintableSourceFile(diagnostic.filename) && !isMinifiedDiagnosticFile(diagnostic.filename) && !shouldSuppressLocalUseHookDiagnostic(diagnostic, rootDirectory)).map((diagnostic) => {
|
|
6308
6567
|
const { plugin, rule } = parseRuleCode(diagnostic.code);
|
|
6309
6568
|
const primaryLabel = diagnostic.labels[0];
|
|
6310
6569
|
const cleaned = cleanDiagnosticMessage(diagnostic.message, diagnostic.help, plugin, rule, project);
|
|
@@ -6313,6 +6572,7 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
6313
6572
|
plugin,
|
|
6314
6573
|
rule,
|
|
6315
6574
|
severity: diagnostic.severity,
|
|
6575
|
+
title: resolveDiagnosticTitle(plugin, rule),
|
|
6316
6576
|
message: cleaned.message,
|
|
6317
6577
|
help: cleaned.help,
|
|
6318
6578
|
url: diagnostic.url,
|
|
@@ -6464,11 +6724,14 @@ const spawnLintBatches = async (input) => {
|
|
|
6464
6724
|
onFileProgress(scannedFileCount + batchFileIndex, totalFileCount);
|
|
6465
6725
|
}
|
|
6466
6726
|
}, 50) : null;
|
|
6467
|
-
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6727
|
+
try {
|
|
6728
|
+
const batchDiagnostics = await spawnLintBatch(batch);
|
|
6729
|
+
allDiagnostics.push(...batchDiagnostics);
|
|
6730
|
+
scannedFileCount += batch.length;
|
|
6731
|
+
onFileProgress?.(scannedFileCount, totalFileCount);
|
|
6732
|
+
} finally {
|
|
6733
|
+
if (progressInterval !== null) clearInterval(progressInterval);
|
|
6734
|
+
}
|
|
6472
6735
|
}
|
|
6473
6736
|
if (droppedFiles.length > 0 && onPartialFailure) {
|
|
6474
6737
|
const previewFiles = droppedFiles.slice(0, 3).join(", ");
|
|
@@ -6727,7 +6990,8 @@ var Progress = class Progress extends Context.Service()("react-doctor/Progress")
|
|
|
6727
6990
|
static layerNoop = Layer.succeed(Progress, Progress.of({ start: () => Effect.succeed({
|
|
6728
6991
|
update: () => Effect.void,
|
|
6729
6992
|
succeed: () => Effect.void,
|
|
6730
|
-
fail: () => Effect.void
|
|
6993
|
+
fail: () => Effect.void,
|
|
6994
|
+
stop: () => Effect.void
|
|
6731
6995
|
}) }));
|
|
6732
6996
|
static layerCapture = Layer.effect(Progress, Effect.map(ProgressCapture, (events) => Progress.of({ start: (text) => Effect.gen(function* () {
|
|
6733
6997
|
yield* Ref.update(events, (existing) => [...existing, {
|
|
@@ -6746,6 +7010,10 @@ var Progress = class Progress extends Context.Service()("react-doctor/Progress")
|
|
|
6746
7010
|
fail: (displayText) => Ref.update(events, (existing) => [...existing, {
|
|
6747
7011
|
_tag: "Failed",
|
|
6748
7012
|
text: displayText
|
|
7013
|
+
}]),
|
|
7014
|
+
stop: () => Ref.update(events, (existing) => [...existing, {
|
|
7015
|
+
_tag: "Stopped",
|
|
7016
|
+
text
|
|
6749
7017
|
}])
|
|
6750
7018
|
};
|
|
6751
7019
|
}) }))).pipe(Layer.provideMerge(ProgressCapture.layer));
|
|
@@ -6817,17 +7085,21 @@ var Reporter = class Reporter extends Context.Service()("react-doctor/Reporter")
|
|
|
6817
7085
|
});
|
|
6818
7086
|
}));
|
|
6819
7087
|
};
|
|
6820
|
-
const
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
|
|
6826
|
-
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
7088
|
+
const RulePrioritySchema = Schema.Struct({
|
|
7089
|
+
priority: Schema.NullOr(Schema.Number),
|
|
7090
|
+
tier: Schema.Literals([
|
|
7091
|
+
"P0",
|
|
7092
|
+
"P1",
|
|
7093
|
+
"P2",
|
|
7094
|
+
"P3"
|
|
7095
|
+
])
|
|
7096
|
+
});
|
|
7097
|
+
const ScoreApiResponseSchema = Schema.Struct({
|
|
7098
|
+
score: Schema.Number,
|
|
7099
|
+
label: Schema.String,
|
|
7100
|
+
rules: Schema.optional(Schema.Record(Schema.String, RulePrioritySchema))
|
|
7101
|
+
});
|
|
7102
|
+
const parseScoreResult = (value) => Option.getOrNull(Schema.decodeUnknownOption(ScoreApiResponseSchema)(value));
|
|
6831
7103
|
const stripFilePaths = (diagnostics) => diagnostics.map(({ filePath: _filePath, ...rest }) => rest);
|
|
6832
7104
|
const isAbortError = (error) => error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError");
|
|
6833
7105
|
const describeFailure = (error) => {
|
|
@@ -6991,15 +7263,18 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
6991
7263
|
repo
|
|
6992
7264
|
}).pipe(Effect.orElseSucceed(() => null)) : Effect.succeed(null));
|
|
6993
7265
|
const lintIncludePaths = computeJsxIncludePaths([...input.includePaths]) ?? resolveLintIncludePaths(scanDirectory, resolvedConfig.config);
|
|
7266
|
+
const scannedFilePaths = input.suppressScanSummary ? (lintIncludePaths ?? (yield* filesService.listSourceFiles(scanDirectory))).map((relativePath) => path.resolve(scanDirectory, relativePath)) : [];
|
|
6994
7267
|
const beforeLint = hooks.beforeLint ?? NO_HOOKS.beforeLint;
|
|
6995
7268
|
const afterLint = hooks.afterLint ?? NO_HOOKS.afterLint;
|
|
6996
7269
|
yield* beforeLint(project, lintIncludePaths ?? void 0);
|
|
6997
7270
|
const isDiffMode = input.includePaths.length > 0;
|
|
7271
|
+
const showWarnings = input.warnings ?? resolvedConfig.config?.warnings ?? false;
|
|
6998
7272
|
const transform = buildDiagnosticPipeline({
|
|
6999
7273
|
rootDirectory: scanDirectory,
|
|
7000
7274
|
userConfig: resolvedConfig.config,
|
|
7001
7275
|
readFileLinesSync: fileReader(filesService, scanDirectory),
|
|
7002
|
-
respectInlineDisables: input.respectInlineDisables
|
|
7276
|
+
respectInlineDisables: input.respectInlineDisables,
|
|
7277
|
+
showWarnings
|
|
7003
7278
|
});
|
|
7004
7279
|
const applyPerElementPipeline = (rawStream) => rawStream.pipe(Stream.filterMap(filterMapNullable(transform.apply)), Stream.tap((diagnostic) => reporterService.emit(diagnostic)));
|
|
7005
7280
|
const environmentDiagnostics = isDiffMode ? [] : [...checkReducedMotion(scanDirectory), ...checkPnpmHardening(scanDirectory)];
|
|
@@ -7045,7 +7320,7 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
7045
7320
|
const lintFailureState = yield* Ref.get(lintFailure);
|
|
7046
7321
|
yield* afterLint(lintFailureState.didFail);
|
|
7047
7322
|
if (lintFailureState.didFail) yield* scanProgress.fail(formatLintFailText(lintFailureState.reasonTag, process.version));
|
|
7048
|
-
const shouldRunDeadCode = input.runDeadCode && !isDiffMode;
|
|
7323
|
+
const shouldRunDeadCode = input.runDeadCode && !isDiffMode && (showWarnings || deadCodeMaySurfaceWhenWarningsHidden(resolvedConfig.config));
|
|
7049
7324
|
const deadCodeCollected = lintFailureState.didFail || !shouldRunDeadCode ? [] : yield* scanProgress.update("Analyzing dead code...").pipe(Effect.andThen(Stream.runCollect(applyPerElementPipeline(deadCodeService.run({
|
|
7050
7325
|
rootDirectory: scanDirectory,
|
|
7051
7326
|
userConfig: resolvedConfig.config
|
|
@@ -7057,9 +7332,11 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
7057
7332
|
return Stream.empty;
|
|
7058
7333
|
}))))))));
|
|
7059
7334
|
const deadCodeFailureState = yield* Ref.get(deadCodeFailure);
|
|
7060
|
-
const
|
|
7335
|
+
const scanElapsedMilliseconds = Date.now() - scanStartTime;
|
|
7336
|
+
const scanElapsedSeconds = (scanElapsedMilliseconds / 1e3).toFixed(1);
|
|
7061
7337
|
const totalFileCount = lastReportedTotalFileCount || (lintIncludePaths?.length ?? project.sourceFileCount);
|
|
7062
7338
|
if (!lintFailureState.didFail) if (deadCodeFailureState.didFail) yield* scanProgress.fail(DEAD_CODE_FAIL_TEXT);
|
|
7339
|
+
else if (input.suppressScanSummary) yield* scanProgress.stop();
|
|
7063
7340
|
else yield* scanProgress.succeed(`Scanned ${totalFileCount} ${totalFileCount === 1 ? "file" : "files"} in ${scanElapsedSeconds}s`);
|
|
7064
7341
|
yield* reporterService.finalize;
|
|
7065
7342
|
const finalDiagnostics = [
|
|
@@ -7100,7 +7377,10 @@ const runInspect = (input, hooks = {}) => Effect.gen(function* () {
|
|
|
7100
7377
|
lintFailureReasonKind: lintFailureState.reasonKind,
|
|
7101
7378
|
lintPartialFailures,
|
|
7102
7379
|
didDeadCodeFail: deadCodeFailureState.didFail,
|
|
7103
|
-
deadCodeFailureReason: deadCodeFailureState.reason
|
|
7380
|
+
deadCodeFailureReason: deadCodeFailureState.reason,
|
|
7381
|
+
scannedFileCount: totalFileCount,
|
|
7382
|
+
scannedFilePaths,
|
|
7383
|
+
scanElapsedMilliseconds
|
|
7104
7384
|
};
|
|
7105
7385
|
}).pipe(Effect.withSpan("runInspect", { attributes: {
|
|
7106
7386
|
"inspect.directory": input.directory,
|
|
@@ -7226,7 +7506,7 @@ const isPathInsideDirectory = (childAbsolutePath, parentAbsolutePath) => {
|
|
|
7226
7506
|
static layerNode = Layer.effect(StagedFiles, Effect.gen(function* () {
|
|
7227
7507
|
const git = yield* Git;
|
|
7228
7508
|
return StagedFiles.of({
|
|
7229
|
-
discoverSourceFiles: (directory) => git.stagedFilePaths(directory).pipe(Effect.map((entries) => entries.filter(
|
|
7509
|
+
discoverSourceFiles: (directory) => git.stagedFilePaths(directory).pipe(Effect.map((entries) => entries.filter(isLintableSourceFile))),
|
|
7230
7510
|
materialize: ({ directory, stagedFiles, tempDirectory }) => Effect.gen(function* () {
|
|
7231
7511
|
const materializedFiles = [];
|
|
7232
7512
|
const resolvedTempDirectory = path.resolve(tempDirectory);
|
|
@@ -7435,7 +7715,7 @@ const getDiffInfo = (directory, explicitBaseBranch) => Effect.runPromise(Effect.
|
|
|
7435
7715
|
GitBaseBranchInvalid: (reason) => Effect.die(new Error(reason.detail)),
|
|
7436
7716
|
GitBaseBranchMissing: (reason) => Effect.die(new Error(reason.message))
|
|
7437
7717
|
})));
|
|
7438
|
-
const filterSourceFiles = (filePaths) => filePaths.filter(
|
|
7718
|
+
const filterSourceFiles = (filePaths) => filePaths.filter(isLintableSourceFile);
|
|
7439
7719
|
var import_picocolors = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
7440
7720
|
let p = process || {}, argv = p.argv || [], env = p.env || {};
|
|
7441
7721
|
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);
|
|
@@ -7522,6 +7802,7 @@ const buildInspectProgram = (scanTarget, options, configOverride) => {
|
|
|
7522
7802
|
includePaths,
|
|
7523
7803
|
customRulesOnly: effectiveConfig?.customRulesOnly ?? false,
|
|
7524
7804
|
respectInlineDisables: options.respectInlineDisables ?? effectiveConfig?.respectInlineDisables ?? true,
|
|
7805
|
+
warnings: options.warnings ?? effectiveConfig?.warnings ?? false,
|
|
7525
7806
|
adoptExistingLintConfig: effectiveConfig?.adoptExistingLintConfig ?? true,
|
|
7526
7807
|
ignoredTags: new Set(effectiveConfig?.ignore?.tags ?? []),
|
|
7527
7808
|
runDeadCode: options.deadCode ?? effectiveConfig?.deadCode ?? true,
|