react-doctor 0.9.1-dev.5d2f66d → 0.9.1-dev.6904ff1
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 +2 -0
- package/dist/cli.js +790 -103
- package/dist/index.d.ts +2 -2
- package/dist/index.js +784 -98
- package/dist/lsp.js +786 -99
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="afe9afbe-4d17-5f2a-8b4f-9b49703c42be")}catch(e){}}();
|
|
3
3
|
import { i as __toESM$1, r as __require, t as __commonJSMin$1 } from "./chunk-ChKA3wi6.js";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import reactDoctorPlugin, { ALL_REACT_DOCTOR_RULE_KEYS, CROSS_FILE_DEPENDENCY_COLLECTORS, CROSS_FILE_RULE_IDS, FRAMEWORK_SPECIFIC_RULE_KEYS, FRAMEWORK_TOKENS, MOTION_LIBRARY_PACKAGES, REACT_COMPILER_RULES, REACT_DOCTOR_RULES, classifySecurityScanFile, collectCrossFileDependencyProbes, resetManifestCaches, shouldReadSecurityScanContent } from "oxlint-plugin-react-doctor";
|
|
@@ -11,6 +11,7 @@ import * as Path from "node:path";
|
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import * as NodeChildProcess from "node:child_process";
|
|
13
13
|
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
14
|
+
import { ResolverFactory } from "oxc-resolver";
|
|
14
15
|
import ts from "typescript";
|
|
15
16
|
import * as OS from "node:os";
|
|
16
17
|
import os from "node:os";
|
|
@@ -61448,7 +61449,8 @@ var AmbiguousProjectError = class extends Error {
|
|
|
61448
61449
|
}
|
|
61449
61450
|
};
|
|
61450
61451
|
const isProjectDiscoveryError = (value) => value instanceof ProjectNotFoundError || value instanceof NoReactDependencyError || value instanceof PackageJsonNotFoundError || value instanceof NotADirectoryError || value instanceof AmbiguousProjectError;
|
|
61451
|
-
const
|
|
61452
|
+
const HTML_FILE_PATTERN = /\.html$/i;
|
|
61453
|
+
const SOURCE_FILE_PATTERN = /\.(?:tsx?|jsx?|mts|mjs|[hH][tT][mM][lL])$/;
|
|
61452
61454
|
const GENERATED_BUNDLE_FILE_PATTERN = /\.(iife|umd|global|min)\.m?js$/i;
|
|
61453
61455
|
const GENERATED_SOURCE_DIRECTORY_PATTERN = /(?:^|\/)__generated__\//;
|
|
61454
61456
|
const MINIFIED_SNIFF_BYTES = 65536;
|
|
@@ -62042,7 +62044,7 @@ const findMonorepoRoot = (startDirectory) => {
|
|
|
62042
62044
|
*/
|
|
62043
62045
|
const isProjectBoundary = (directory) => NFS.existsSync(Path.join(directory, ".git")) || isMonorepoRoot(directory);
|
|
62044
62046
|
const TSCONFIG_FILENAME = "tsconfig.json";
|
|
62045
|
-
const
|
|
62047
|
+
const isLocalModuleSpecifier = (moduleSpecifier) => moduleSpecifier === "." || moduleSpecifier === ".." || moduleSpecifier.startsWith("./") || moduleSpecifier.startsWith("../") || Path.isAbsolute(moduleSpecifier);
|
|
62046
62048
|
const ensureJsonExtension = (filePath) => Path.extname(filePath) === "" ? `${filePath}.json` : filePath;
|
|
62047
62049
|
const resolvePackageExtendsPath = (extendsValue, fromConfigDirectory) => {
|
|
62048
62050
|
const requireFromConfig = createRequire(Path.join(fromConfigDirectory, "tsconfig.json"));
|
|
@@ -62059,7 +62061,12 @@ const resolvePackageExtendsPath = (extendsValue, fromConfigDirectory) => {
|
|
|
62059
62061
|
return null;
|
|
62060
62062
|
};
|
|
62061
62063
|
const resolveExtendsPath = (extendsValue, fromConfigDirectory) => {
|
|
62062
|
-
if (
|
|
62064
|
+
if (isLocalModuleSpecifier(extendsValue)) {
|
|
62065
|
+
const resolvedPath = Path.resolve(fromConfigDirectory, extendsValue);
|
|
62066
|
+
if (isFile(resolvedPath)) return resolvedPath;
|
|
62067
|
+
const directoryConfigPath = Path.join(resolvedPath, TSCONFIG_FILENAME);
|
|
62068
|
+
return isFile(directoryConfigPath) ? directoryConfigPath : ensureJsonExtension(resolvedPath);
|
|
62069
|
+
}
|
|
62063
62070
|
return resolvePackageExtendsPath(extendsValue, fromConfigDirectory);
|
|
62064
62071
|
};
|
|
62065
62072
|
const normalizeCompilerOptions = (compilerOptions) => {
|
|
@@ -62253,6 +62260,15 @@ const REACT_COMPILER_CONFIG_SOURCE_EXTENSIONS = [
|
|
|
62253
62260
|
".cts",
|
|
62254
62261
|
".json"
|
|
62255
62262
|
];
|
|
62263
|
+
const REACT_COMPILER_CONFIG_RESOLVER = new ResolverFactory({
|
|
62264
|
+
conditionNames: [
|
|
62265
|
+
"import",
|
|
62266
|
+
"require",
|
|
62267
|
+
"node",
|
|
62268
|
+
"default"
|
|
62269
|
+
],
|
|
62270
|
+
extensions: REACT_COMPILER_CONFIG_SOURCE_EXTENSIONS
|
|
62271
|
+
});
|
|
62256
62272
|
const STATIC_EXPORT_OUTPUT_PATTERN = /(?:^|[^.\w])["']?output["']?\s*:\s*["']export["']/m;
|
|
62257
62273
|
const hasCompilerPackage = (packageJson, compilerPackages) => {
|
|
62258
62274
|
const allDependencies = {
|
|
@@ -62276,6 +62292,18 @@ const hasCompilerPackageInAncestors = (directory, compilerPackages) => {
|
|
|
62276
62292
|
return false;
|
|
62277
62293
|
};
|
|
62278
62294
|
const resolveImportedConfigFile = (fromFilePath, moduleSpecifier) => {
|
|
62295
|
+
if (!isLocalModuleSpecifier(moduleSpecifier)) {
|
|
62296
|
+
try {
|
|
62297
|
+
const resolvedPath = REACT_COMPILER_CONFIG_RESOLVER.resolveFileSync(fromFilePath, moduleSpecifier).path;
|
|
62298
|
+
if (resolvedPath && isFile(resolvedPath)) return resolvedPath;
|
|
62299
|
+
} catch {}
|
|
62300
|
+
try {
|
|
62301
|
+
const resolvedPath = createRequire(fromFilePath).resolve(moduleSpecifier);
|
|
62302
|
+
return isFile(resolvedPath) ? resolvedPath : null;
|
|
62303
|
+
} catch {
|
|
62304
|
+
return null;
|
|
62305
|
+
}
|
|
62306
|
+
}
|
|
62279
62307
|
const unresolvedPath = Path.resolve(Path.dirname(fromFilePath), moduleSpecifier);
|
|
62280
62308
|
const extension = Path.extname(unresolvedPath);
|
|
62281
62309
|
return (extension ? [unresolvedPath, ...REACT_COMPILER_CONFIG_SOURCE_EXTENSIONS.map((sourceExtension) => `${unresolvedPath.slice(0, -extension.length)}${sourceExtension}`)] : [
|
|
@@ -62288,7 +62316,7 @@ const parseConfigSourceFile = (filePath, content) => filePath.endsWith(".json")
|
|
|
62288
62316
|
const getStaticPropertyName$2 = (propertyName) => ts.isIdentifier(propertyName) || ts.isStringLiteralLike(propertyName) ? propertyName.text : ts.isComputedPropertyName(propertyName) && ts.isStringLiteralLike(propertyName.expression) ? propertyName.expression.text : null;
|
|
62289
62317
|
const isCommonJsConfigExportAssignment = (node, sourceFile) => ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken && (node.left.getText(sourceFile) === "module.exports" || node.left.getText(sourceFile) === "exports.default");
|
|
62290
62318
|
const hasExportModifier = (node) => ts.canHaveModifiers(node) && Boolean(ts.getModifiers(node)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword));
|
|
62291
|
-
const getRequireModuleSpecifier = (expression) => {
|
|
62319
|
+
const getRequireModuleSpecifier$1 = (expression) => {
|
|
62292
62320
|
if (!ts.isCallExpression(expression) || !ts.isIdentifier(expression.expression) || expression.expression.text !== "require" || expression.arguments.length !== 1) return null;
|
|
62293
62321
|
const moduleSpecifier = expression.arguments[0];
|
|
62294
62322
|
return moduleSpecifier && ts.isStringLiteralLike(moduleSpecifier) ? moduleSpecifier.text : null;
|
|
@@ -62301,7 +62329,7 @@ const hasTopLevelValueBinding = (sourceFile, bindingName) => sourceFile.statemen
|
|
|
62301
62329
|
const namedBindings = importClause?.namedBindings;
|
|
62302
62330
|
return namedBindings ? ts.isNamespaceImport(namedBindings) ? namedBindings.name.text === bindingName : namedBindings.elements.some((element) => element.name.text === bindingName) : false;
|
|
62303
62331
|
}
|
|
62304
|
-
if (ts.isVariableStatement(statement)) return statement.declarationList.declarations.some((declaration) =>
|
|
62332
|
+
if (ts.isVariableStatement(statement)) return statement.declarationList.declarations.some((declaration) => bindingNameContainsIdentifier(declaration.name, bindingName));
|
|
62305
62333
|
return (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) && statement.name?.text === bindingName;
|
|
62306
62334
|
});
|
|
62307
62335
|
const getImportBinding = (sourceFile, bindingName) => {
|
|
@@ -62332,21 +62360,21 @@ const getImportBinding = (sourceFile, bindingName) => {
|
|
|
62332
62360
|
for (const declaration of statement.declarationList.declarations) {
|
|
62333
62361
|
if (!declaration.initializer) continue;
|
|
62334
62362
|
if (ts.isIdentifier(declaration.name) && declaration.name.text === bindingName) {
|
|
62335
|
-
const directModuleSpecifier = getRequireModuleSpecifier(declaration.initializer);
|
|
62363
|
+
const directModuleSpecifier = getRequireModuleSpecifier$1(declaration.initializer);
|
|
62336
62364
|
if (directModuleSpecifier) return {
|
|
62337
62365
|
moduleSpecifier: directModuleSpecifier,
|
|
62338
62366
|
exportName: "default",
|
|
62339
62367
|
isNamespace: true
|
|
62340
62368
|
};
|
|
62341
|
-
if (ts.isPropertyAccessExpression(declaration.initializer) && getRequireModuleSpecifier(declaration.initializer.expression) !== null) return {
|
|
62342
|
-
moduleSpecifier: getRequireModuleSpecifier(declaration.initializer.expression) ?? "",
|
|
62369
|
+
if (ts.isPropertyAccessExpression(declaration.initializer) && getRequireModuleSpecifier$1(declaration.initializer.expression) !== null) return {
|
|
62370
|
+
moduleSpecifier: getRequireModuleSpecifier$1(declaration.initializer.expression) ?? "",
|
|
62343
62371
|
exportName: declaration.initializer.name.text,
|
|
62344
62372
|
isNamespace: false
|
|
62345
62373
|
};
|
|
62346
62374
|
}
|
|
62347
62375
|
if (!ts.isObjectBindingPattern(declaration.name)) continue;
|
|
62348
62376
|
const bindingElement = declaration.name.elements.find((element) => ts.isIdentifier(element.name) && element.name.text === bindingName);
|
|
62349
|
-
const moduleSpecifier = getRequireModuleSpecifier(declaration.initializer);
|
|
62377
|
+
const moduleSpecifier = getRequireModuleSpecifier$1(declaration.initializer);
|
|
62350
62378
|
if (bindingElement && moduleSpecifier) return {
|
|
62351
62379
|
moduleSpecifier,
|
|
62352
62380
|
exportName: bindingElement.propertyName ? getStaticPropertyName$2(bindingElement.propertyName) ?? bindingElement.propertyName.getText(sourceFile) : bindingElement.name.getText(sourceFile),
|
|
@@ -62402,6 +62430,48 @@ const getScopedConfigBinding = (identifier) => {
|
|
|
62402
62430
|
};
|
|
62403
62431
|
};
|
|
62404
62432
|
const isCompilerTransformModule = (moduleSpecifier, exportName) => moduleSpecifier === "babel-plugin-react-compiler" && exportName === "default" || moduleSpecifier === "@vitejs/plugin-react" && exportName === "reactCompilerPreset";
|
|
62433
|
+
const NODE_MODULE_SPECIFIERS = new Set(["module", "node:module"]);
|
|
62434
|
+
const isConstantVariableInitializer = (node) => ts.isExpression(node) && ts.isVariableDeclaration(node.parent) && ts.isVariableDeclarationList(node.parent.parent) && Boolean(node.parent.parent.flags & ts.NodeFlags.Const);
|
|
62435
|
+
const isNodeCreateRequireCall = (node, analysis) => {
|
|
62436
|
+
if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isTypeAssertionExpression(node) || ts.isSatisfiesExpression(node) || ts.isNonNullExpression(node) || ts.isAwaitExpression(node)) return isNodeCreateRequireCall(node.expression, analysis);
|
|
62437
|
+
if (!ts.isCallExpression(node)) return false;
|
|
62438
|
+
const target = node.expression;
|
|
62439
|
+
if (ts.isIdentifier(target)) {
|
|
62440
|
+
if (analysis.localBindings.has(target.text) || getScopedConfigBinding(target).wasFound) return false;
|
|
62441
|
+
const importBinding = getImportBinding(analysis.sourceFile, target.text);
|
|
62442
|
+
return Boolean(importBinding && NODE_MODULE_SPECIFIERS.has(importBinding.moduleSpecifier) && importBinding.exportName === "createRequire");
|
|
62443
|
+
}
|
|
62444
|
+
if (!ts.isPropertyAccessExpression(target) && !ts.isElementAccessExpression(target)) return false;
|
|
62445
|
+
if ((ts.isPropertyAccessExpression(target) ? target.name.text : target.argumentExpression && ts.isStringLiteralLike(target.argumentExpression) ? target.argumentExpression.text : null) !== "createRequire") return false;
|
|
62446
|
+
const createRequireReceiver = target.expression;
|
|
62447
|
+
if (ts.isCallExpression(createRequireReceiver)) {
|
|
62448
|
+
const requiredModuleSpecifier = getRequireModuleSpecifier$1(createRequireReceiver);
|
|
62449
|
+
if (requiredModuleSpecifier === null || !NODE_MODULE_SPECIFIERS.has(requiredModuleSpecifier) || !ts.isIdentifier(createRequireReceiver.expression)) return false;
|
|
62450
|
+
const requireIdentifier = createRequireReceiver.expression;
|
|
62451
|
+
return !analysis.localBindings.has(requireIdentifier.text) && !getScopedConfigBinding(requireIdentifier).wasFound && !hasTopLevelValueBinding(analysis.sourceFile, requireIdentifier.text);
|
|
62452
|
+
}
|
|
62453
|
+
if (!ts.isIdentifier(createRequireReceiver)) return false;
|
|
62454
|
+
if (analysis.localBindings.has(createRequireReceiver.text) || getScopedConfigBinding(createRequireReceiver).wasFound) return false;
|
|
62455
|
+
const importBinding = getImportBinding(analysis.sourceFile, createRequireReceiver.text);
|
|
62456
|
+
return Boolean(importBinding?.isNamespace && NODE_MODULE_SPECIFIERS.has(importBinding.moduleSpecifier));
|
|
62457
|
+
};
|
|
62458
|
+
const getNodeRequireResolveModuleSpecifier = (callExpression, analysis) => {
|
|
62459
|
+
const [moduleSpecifierNode] = callExpression.arguments;
|
|
62460
|
+
if (!moduleSpecifierNode || !ts.isStringLiteralLike(moduleSpecifierNode)) return null;
|
|
62461
|
+
const target = callExpression.expression;
|
|
62462
|
+
if (!ts.isPropertyAccessExpression(target) && !ts.isElementAccessExpression(target)) return null;
|
|
62463
|
+
if ((ts.isPropertyAccessExpression(target) ? target.name.text : target.argumentExpression && ts.isStringLiteralLike(target.argumentExpression) ? target.argumentExpression.text : null) !== "resolve") return null;
|
|
62464
|
+
if (isNodeCreateRequireCall(target.expression, analysis)) return moduleSpecifierNode.text;
|
|
62465
|
+
if (!ts.isIdentifier(target.expression)) return null;
|
|
62466
|
+
const resolverIdentifier = target.expression;
|
|
62467
|
+
if (analysis.localBindings.has(resolverIdentifier.text)) return null;
|
|
62468
|
+
const scopedBinding = getScopedConfigBinding(resolverIdentifier);
|
|
62469
|
+
const topLevelBinding = scopedBinding.wasFound ? null : getTopLevelBinding(analysis.sourceFile, resolverIdentifier.text);
|
|
62470
|
+
const resolverInitializer = scopedBinding.wasFound ? scopedBinding.initializer : topLevelBinding;
|
|
62471
|
+
if (resolverInitializer === null && !scopedBinding.wasFound && resolverIdentifier.text === "require" && !hasTopLevelValueBinding(analysis.sourceFile, resolverIdentifier.text) && getImportBinding(analysis.sourceFile, resolverIdentifier.text) === null) return moduleSpecifierNode.text;
|
|
62472
|
+
if (!resolverInitializer || !isConstantVariableInitializer(resolverInitializer) || !isNodeCreateRequireCall(resolverInitializer, analysis)) return null;
|
|
62473
|
+
return moduleSpecifierNode.text;
|
|
62474
|
+
};
|
|
62405
62475
|
const getAssignedPropertyInitializer = (identifier, propertyName) => {
|
|
62406
62476
|
let bindingScope = null;
|
|
62407
62477
|
let currentNode = identifier;
|
|
@@ -62685,6 +62755,11 @@ const analyzeConfigFunction = (functionNode, analysis, allowCompilerTransform, a
|
|
|
62685
62755
|
visitReturns(functionNode.body);
|
|
62686
62756
|
return hasCompiler;
|
|
62687
62757
|
};
|
|
62758
|
+
const analyzeImportedConfig = ({ analysis, moduleSpecifier, exportName, allowCompilerTransform, argumentsList }) => {
|
|
62759
|
+
const importedFilePath = resolveImportedConfigFile(analysis.filePath, moduleSpecifier);
|
|
62760
|
+
if (!importedFilePath) return null;
|
|
62761
|
+
return analyzeConfigModuleExport(importedFilePath, exportName, allowCompilerTransform, analysis.importDepth + 1, analysis.visitedModules, argumentsList);
|
|
62762
|
+
};
|
|
62688
62763
|
const analyzeConfigIdentifier = (identifier, analysis, allowCompilerTransform, isCompilerTransformCollection, excludedPropertyNames) => {
|
|
62689
62764
|
const assignedReactCompiler = getAssignedPropertyInitializer(identifier, "reactCompiler");
|
|
62690
62765
|
if (assignedReactCompiler.initializer && !isStaticallyDisabledConfigExpression(assignedReactCompiler.initializer, analysis)) return true;
|
|
@@ -62705,30 +62780,62 @@ const analyzeConfigIdentifier = (identifier, analysis, allowCompilerTransform, i
|
|
|
62705
62780
|
const importBinding = getImportBinding(analysis.sourceFile, identifier.text);
|
|
62706
62781
|
if (importBinding) {
|
|
62707
62782
|
if (allowCompilerTransform && isCompilerTransformModule(importBinding.moduleSpecifier, importBinding.exportName)) return true;
|
|
62708
|
-
|
|
62709
|
-
|
|
62710
|
-
|
|
62783
|
+
return Boolean(analyzeImportedConfig({
|
|
62784
|
+
analysis,
|
|
62785
|
+
moduleSpecifier: importBinding.moduleSpecifier,
|
|
62786
|
+
exportName: importBinding.exportName,
|
|
62787
|
+
allowCompilerTransform
|
|
62788
|
+
}));
|
|
62711
62789
|
}
|
|
62712
62790
|
const topLevelBinding = getTopLevelBinding(analysis.sourceFile, identifier.text);
|
|
62713
62791
|
return Boolean(topLevelBinding && analyzeConfigNode(topLevelBinding, analysis, allowCompilerTransform, isCompilerTransformCollection, overriddenPropertyNames));
|
|
62714
62792
|
};
|
|
62715
62793
|
const analyzeConfigCallTarget = (callExpression, analysis, allowCompilerTransform) => {
|
|
62716
62794
|
const target = callExpression.expression;
|
|
62795
|
+
const callableRequiredModuleSpecifier = getRequireModuleSpecifier$1(target);
|
|
62796
|
+
if (callableRequiredModuleSpecifier !== null) {
|
|
62797
|
+
if (ts.isCallExpression(target) && ts.isIdentifier(target.expression) && (analysis.localBindings.has(target.expression.text) || getScopedConfigBinding(target.expression).wasFound || hasTopLevelValueBinding(analysis.sourceFile, "require"))) return false;
|
|
62798
|
+
if (allowCompilerTransform && isCompilerTransformModule(callableRequiredModuleSpecifier, "default")) return true;
|
|
62799
|
+
const hasCompilerTransform = analyzeImportedConfig({
|
|
62800
|
+
analysis,
|
|
62801
|
+
moduleSpecifier: callableRequiredModuleSpecifier,
|
|
62802
|
+
exportName: "default",
|
|
62803
|
+
allowCompilerTransform,
|
|
62804
|
+
argumentsList: callExpression.arguments
|
|
62805
|
+
});
|
|
62806
|
+
if (isLocalModuleSpecifier(callableRequiredModuleSpecifier) || hasCompilerTransform !== null) return Boolean(hasCompilerTransform);
|
|
62807
|
+
return null;
|
|
62808
|
+
}
|
|
62717
62809
|
if (!ts.isPropertyAccessExpression(target) && !ts.isElementAccessExpression(target)) return null;
|
|
62718
62810
|
const propertyName = ts.isPropertyAccessExpression(target) ? target.name.text : target.argumentExpression && ts.isStringLiteralLike(target.argumentExpression) ? target.argumentExpression.text : null;
|
|
62719
62811
|
if (propertyName === null) return null;
|
|
62720
|
-
const requiredModuleSpecifier = getRequireModuleSpecifier(target.expression);
|
|
62812
|
+
const requiredModuleSpecifier = getRequireModuleSpecifier$1(target.expression);
|
|
62721
62813
|
if (requiredModuleSpecifier !== null) {
|
|
62722
|
-
if (ts.isCallExpression(target.expression) && ts.isIdentifier(target.expression.expression) && (getScopedConfigBinding(target.expression.expression).wasFound || hasTopLevelValueBinding(analysis.sourceFile, "require"))) return false;
|
|
62723
|
-
if (
|
|
62724
|
-
const
|
|
62725
|
-
|
|
62814
|
+
if (ts.isCallExpression(target.expression) && ts.isIdentifier(target.expression.expression) && (analysis.localBindings.has(target.expression.expression.text) || getScopedConfigBinding(target.expression.expression).wasFound || hasTopLevelValueBinding(analysis.sourceFile, "require"))) return false;
|
|
62815
|
+
if (allowCompilerTransform && isCompilerTransformModule(requiredModuleSpecifier, propertyName)) return true;
|
|
62816
|
+
const hasCompilerTransform = analyzeImportedConfig({
|
|
62817
|
+
analysis,
|
|
62818
|
+
moduleSpecifier: requiredModuleSpecifier,
|
|
62819
|
+
exportName: propertyName,
|
|
62820
|
+
allowCompilerTransform,
|
|
62821
|
+
argumentsList: callExpression.arguments
|
|
62822
|
+
});
|
|
62823
|
+
if (isLocalModuleSpecifier(requiredModuleSpecifier) || hasCompilerTransform !== null) return Boolean(hasCompilerTransform);
|
|
62824
|
+
return null;
|
|
62726
62825
|
}
|
|
62727
62826
|
if (!ts.isIdentifier(target.expression)) return null;
|
|
62728
|
-
const importBinding = getImportBinding(analysis.sourceFile, target.expression.text);
|
|
62729
|
-
if (importBinding?.isNamespace
|
|
62730
|
-
|
|
62731
|
-
|
|
62827
|
+
const importBinding = analysis.localBindings.has(target.expression.text) || getScopedConfigBinding(target.expression).wasFound ? null : getImportBinding(analysis.sourceFile, target.expression.text);
|
|
62828
|
+
if (importBinding?.isNamespace) {
|
|
62829
|
+
if (allowCompilerTransform && isCompilerTransformModule(importBinding.moduleSpecifier, propertyName)) return true;
|
|
62830
|
+
const hasCompilerTransform = analyzeImportedConfig({
|
|
62831
|
+
analysis,
|
|
62832
|
+
moduleSpecifier: importBinding.moduleSpecifier,
|
|
62833
|
+
exportName: propertyName,
|
|
62834
|
+
allowCompilerTransform,
|
|
62835
|
+
argumentsList: callExpression.arguments
|
|
62836
|
+
});
|
|
62837
|
+
if (isLocalModuleSpecifier(importBinding.moduleSpecifier) || hasCompilerTransform !== null) return Boolean(hasCompilerTransform);
|
|
62838
|
+
return null;
|
|
62732
62839
|
}
|
|
62733
62840
|
const selectedProperty = getSelectedObjectProperty(target.expression, propertyName, analysis);
|
|
62734
62841
|
if (selectedProperty === null) return null;
|
|
@@ -62751,9 +62858,13 @@ const analyzeConfigNode = (node, analysis, allowCompilerTransform, isCompilerTra
|
|
|
62751
62858
|
if (propertyName === "reactCompiler") continue;
|
|
62752
62859
|
if ((propertyName === "plugins" || propertyName === "presets") && node.properties.slice(propertyIndex + 1).some((laterProperty) => ts.isSpreadAssignment(laterProperty) && configExpressionMayDefineProperty(laterProperty.expression, propertyName, analysis) || (ts.isPropertyAssignment(laterProperty) || ts.isShorthandPropertyAssignment(laterProperty)) && getStaticPropertyName$2(laterProperty.name) === propertyName)) continue;
|
|
62753
62860
|
const propertyAllowsCompilerTransform = propertyName === "plugins" || propertyName === "presets";
|
|
62754
|
-
if (propertyName === "extends" && ts.isStringLiteralLike(property.initializer)
|
|
62755
|
-
|
|
62756
|
-
|
|
62861
|
+
if (propertyName === "extends" && ts.isStringLiteralLike(property.initializer)) {
|
|
62862
|
+
if (analyzeImportedConfig({
|
|
62863
|
+
analysis,
|
|
62864
|
+
moduleSpecifier: property.initializer.text,
|
|
62865
|
+
exportName: "default",
|
|
62866
|
+
allowCompilerTransform: false
|
|
62867
|
+
})) return true;
|
|
62757
62868
|
}
|
|
62758
62869
|
if (analyzeConfigNode(property.initializer, analysis, propertyAllowsCompilerTransform, propertyAllowsCompilerTransform)) return true;
|
|
62759
62870
|
} else if (ts.isShorthandPropertyAssignment(property)) {
|
|
@@ -62777,23 +62888,36 @@ const analyzeConfigNode = (node, analysis, allowCompilerTransform, isCompilerTra
|
|
|
62777
62888
|
});
|
|
62778
62889
|
}
|
|
62779
62890
|
if (ts.isCallExpression(node)) {
|
|
62891
|
+
const resolvedModuleSpecifier = getNodeRequireResolveModuleSpecifier(node, analysis);
|
|
62892
|
+
if (resolvedModuleSpecifier !== null) return allowCompilerTransform && isCompilerTransformModule(resolvedModuleSpecifier, "default");
|
|
62780
62893
|
const callTargetResult = analyzeConfigCallTarget(node, analysis, allowCompilerTransform);
|
|
62781
62894
|
if (callTargetResult !== null) return callTargetResult;
|
|
62782
|
-
const directModuleSpecifier = getRequireModuleSpecifier(node);
|
|
62895
|
+
const directModuleSpecifier = getRequireModuleSpecifier$1(node);
|
|
62783
62896
|
const isRequireShadowed = analysis.localBindings.has("require") || ts.isIdentifier(node.expression) && getScopedConfigBinding(node.expression).wasFound || hasTopLevelValueBinding(analysis.sourceFile, "require");
|
|
62784
62897
|
if (directModuleSpecifier && isRequireShadowed) return analyzeConfigNode(node.expression, analysis, allowCompilerTransform);
|
|
62785
62898
|
if (directModuleSpecifier && !isRequireShadowed) {
|
|
62786
62899
|
if (allowCompilerTransform && isCompilerTransformModule(directModuleSpecifier, "default")) return true;
|
|
62787
|
-
if (
|
|
62788
|
-
|
|
62789
|
-
|
|
62790
|
-
|
|
62900
|
+
if (analyzeImportedConfig({
|
|
62901
|
+
analysis,
|
|
62902
|
+
moduleSpecifier: directModuleSpecifier,
|
|
62903
|
+
exportName: "default",
|
|
62904
|
+
allowCompilerTransform
|
|
62905
|
+
})) return true;
|
|
62791
62906
|
}
|
|
62792
62907
|
if (ts.isIdentifier(node.expression)) {
|
|
62793
|
-
|
|
62794
|
-
|
|
62795
|
-
|
|
62796
|
-
|
|
62908
|
+
if (!analysis.localBindings.has(node.expression.text) && !getScopedConfigBinding(node.expression).wasFound) {
|
|
62909
|
+
const importBinding = getImportBinding(analysis.sourceFile, node.expression.text);
|
|
62910
|
+
if (importBinding) {
|
|
62911
|
+
if (allowCompilerTransform && isCompilerTransformModule(importBinding.moduleSpecifier, importBinding.exportName)) return true;
|
|
62912
|
+
const hasCompilerTransform = analyzeImportedConfig({
|
|
62913
|
+
analysis,
|
|
62914
|
+
moduleSpecifier: importBinding.moduleSpecifier,
|
|
62915
|
+
exportName: importBinding.exportName,
|
|
62916
|
+
allowCompilerTransform,
|
|
62917
|
+
argumentsList: node.arguments
|
|
62918
|
+
});
|
|
62919
|
+
if (isLocalModuleSpecifier(importBinding.moduleSpecifier) || hasCompilerTransform !== null) return Boolean(hasCompilerTransform);
|
|
62920
|
+
}
|
|
62797
62921
|
}
|
|
62798
62922
|
const topLevelBinding = getTopLevelBinding(analysis.sourceFile, node.expression.text);
|
|
62799
62923
|
if (topLevelBinding && ts.isFunctionLike(topLevelBinding) && analyzeConfigFunction(topLevelBinding, analysis, allowCompilerTransform, node.arguments)) return true;
|
|
@@ -62801,27 +62925,31 @@ const analyzeConfigNode = (node, analysis, allowCompilerTransform, isCompilerTra
|
|
|
62801
62925
|
return analyzeConfigNode(node.expression, analysis, allowCompilerTransform) || node.arguments.some((argument) => analyzeConfigNode(argument, analysis, false));
|
|
62802
62926
|
}
|
|
62803
62927
|
if (ts.isPropertyAccessExpression(node)) {
|
|
62804
|
-
const requiredModuleSpecifier = getRequireModuleSpecifier(node.expression);
|
|
62928
|
+
const requiredModuleSpecifier = getRequireModuleSpecifier$1(node.expression);
|
|
62805
62929
|
if (requiredModuleSpecifier) {
|
|
62806
|
-
if (ts.isCallExpression(node.expression) && ts.isIdentifier(node.expression.expression) && (getScopedConfigBinding(node.expression.expression).wasFound || hasTopLevelValueBinding(analysis.sourceFile, "require"))) return false;
|
|
62807
|
-
if (
|
|
62808
|
-
|
|
62809
|
-
|
|
62810
|
-
|
|
62930
|
+
if (ts.isCallExpression(node.expression) && ts.isIdentifier(node.expression.expression) && (analysis.localBindings.has(node.expression.expression.text) || getScopedConfigBinding(node.expression.expression).wasFound || hasTopLevelValueBinding(analysis.sourceFile, "require"))) return false;
|
|
62931
|
+
if (analyzeImportedConfig({
|
|
62932
|
+
analysis,
|
|
62933
|
+
moduleSpecifier: requiredModuleSpecifier,
|
|
62934
|
+
exportName: node.name.text,
|
|
62935
|
+
allowCompilerTransform
|
|
62936
|
+
})) return true;
|
|
62811
62937
|
return allowCompilerTransform && isCompilerTransformModule(requiredModuleSpecifier, node.name.text);
|
|
62812
62938
|
}
|
|
62813
62939
|
if (ts.isIdentifier(node.expression)) {
|
|
62814
|
-
if (analysis.localBindings.has(node.expression.text)) {
|
|
62815
|
-
const
|
|
62816
|
-
return Boolean(
|
|
62940
|
+
if (analysis.localBindings.has(node.expression.text) || getScopedConfigBinding(node.expression).wasFound) {
|
|
62941
|
+
const selectedProperty = getSelectedObjectProperty(node.expression, node.name.text, analysis);
|
|
62942
|
+
return Boolean(selectedProperty && analyzeConfigNode(selectedProperty, analysis, allowCompilerTransform));
|
|
62817
62943
|
}
|
|
62818
62944
|
const importBinding = getImportBinding(analysis.sourceFile, node.expression.text);
|
|
62819
62945
|
if (importBinding?.isNamespace) {
|
|
62820
62946
|
if (allowCompilerTransform && isCompilerTransformModule(importBinding.moduleSpecifier, node.name.text)) return true;
|
|
62821
|
-
if (
|
|
62822
|
-
|
|
62823
|
-
|
|
62824
|
-
|
|
62947
|
+
if (analyzeImportedConfig({
|
|
62948
|
+
analysis,
|
|
62949
|
+
moduleSpecifier: importBinding.moduleSpecifier,
|
|
62950
|
+
exportName: node.name.text,
|
|
62951
|
+
allowCompilerTransform
|
|
62952
|
+
})) return true;
|
|
62825
62953
|
return false;
|
|
62826
62954
|
}
|
|
62827
62955
|
const selectedProperty = getSelectedObjectProperty(node.expression, node.name.text, analysis);
|
|
@@ -62832,13 +62960,19 @@ const analyzeConfigNode = (node, analysis, allowCompilerTransform, isCompilerTra
|
|
|
62832
62960
|
}
|
|
62833
62961
|
if (ts.isElementAccessExpression(node) && node.argumentExpression && ts.isStringLiteralLike(node.argumentExpression)) {
|
|
62834
62962
|
if (ts.isIdentifier(node.expression)) {
|
|
62963
|
+
if (analysis.localBindings.has(node.expression.text) || getScopedConfigBinding(node.expression).wasFound) {
|
|
62964
|
+
const selectedProperty = getSelectedObjectProperty(node.expression, node.argumentExpression.text, analysis);
|
|
62965
|
+
return Boolean(selectedProperty && analyzeConfigNode(selectedProperty, analysis, allowCompilerTransform));
|
|
62966
|
+
}
|
|
62835
62967
|
const importBinding = getImportBinding(analysis.sourceFile, node.expression.text);
|
|
62836
62968
|
if (importBinding?.isNamespace) {
|
|
62837
62969
|
if (allowCompilerTransform && isCompilerTransformModule(importBinding.moduleSpecifier, node.argumentExpression.text)) return true;
|
|
62838
|
-
|
|
62839
|
-
|
|
62840
|
-
|
|
62841
|
-
|
|
62970
|
+
return Boolean(analyzeImportedConfig({
|
|
62971
|
+
analysis,
|
|
62972
|
+
moduleSpecifier: importBinding.moduleSpecifier,
|
|
62973
|
+
exportName: node.argumentExpression.text,
|
|
62974
|
+
allowCompilerTransform
|
|
62975
|
+
}));
|
|
62842
62976
|
}
|
|
62843
62977
|
const selectedProperty = getSelectedObjectProperty(node.expression, node.argumentExpression.text, analysis);
|
|
62844
62978
|
if (selectedProperty) return analyzeConfigNode(selectedProperty, analysis, allowCompilerTransform);
|
|
@@ -62876,14 +63010,19 @@ const analyzeConfigNode = (node, analysis, allowCompilerTransform, isCompilerTra
|
|
|
62876
63010
|
};
|
|
62877
63011
|
const hasCompilerInConfigFile = (filePath) => analyzeConfigModuleExport(filePath, "default", false, 0, /* @__PURE__ */ new Set());
|
|
62878
63012
|
const hasCompilerInConfigFiles = (directory, filenames) => filenames.some((filename) => hasCompilerInConfigFile(Path.join(directory, filename)));
|
|
62879
|
-
const hasCompilerInPackageJsonConfig = (
|
|
62880
|
-
|
|
63013
|
+
const hasCompilerInPackageJsonConfig = (directory, packageJson) => {
|
|
63014
|
+
if (!isPlainObject(packageJson.babel)) return false;
|
|
63015
|
+
const packageJsonPath = Path.join(directory, "package.json");
|
|
63016
|
+
return analyzeConfigSourceFileExport(ts.parseJsonText(packageJsonPath, JSON.stringify(packageJson.babel)), packageJsonPath, "default", false, 0, /* @__PURE__ */ new Set());
|
|
63017
|
+
};
|
|
63018
|
+
const hasCompilerConfiguration = (directory, packageJson) => hasCompilerInPackageJsonConfig(directory, packageJson) || hasCompilerInConfigFiles(directory, REACT_COMPILER_CONFIG_FILENAMES);
|
|
62881
63019
|
const hasCompilerConfigurationInAncestors = (directory) => {
|
|
62882
63020
|
if (isProjectBoundary(directory)) return false;
|
|
62883
63021
|
let ancestorDirectory = Path.dirname(directory);
|
|
62884
63022
|
while (ancestorDirectory !== Path.dirname(ancestorDirectory)) {
|
|
62885
63023
|
const ancestorPackagePath = Path.join(ancestorDirectory, "package.json");
|
|
62886
|
-
|
|
63024
|
+
const ancestorPackageJson = isFile(ancestorPackagePath) ? readPackageJson(ancestorPackagePath) : {};
|
|
63025
|
+
if (hasCompilerInPackageJsonConfig(ancestorDirectory, ancestorPackageJson) || hasCompilerInConfigFiles(ancestorDirectory, BABEL_CONFIG_FILENAMES)) return true;
|
|
62887
63026
|
if (isProjectBoundary(ancestorDirectory)) return false;
|
|
62888
63027
|
ancestorDirectory = Path.dirname(ancestorDirectory);
|
|
62889
63028
|
}
|
|
@@ -66138,7 +66277,7 @@ const warn = (message) => {
|
|
|
66138
66277
|
runSync(warn$1(message));
|
|
66139
66278
|
};
|
|
66140
66279
|
const CONFIG_BASENAME = "doctor.config";
|
|
66141
|
-
const CONFIG_EXTENSIONS = [
|
|
66280
|
+
const CONFIG_EXTENSIONS$1 = [
|
|
66142
66281
|
"ts",
|
|
66143
66282
|
"mts",
|
|
66144
66283
|
"cts",
|
|
@@ -66242,7 +66381,7 @@ const loadLegacyConfig = (directory) => {
|
|
|
66242
66381
|
};
|
|
66243
66382
|
const loadConfigFromDirectory = async (directory) => {
|
|
66244
66383
|
let sawBrokenConfigFile = false;
|
|
66245
|
-
for (const extension of CONFIG_EXTENSIONS) {
|
|
66384
|
+
for (const extension of CONFIG_EXTENSIONS$1) {
|
|
66246
66385
|
const filePath = Path.join(directory, `${CONFIG_BASENAME}.${extension}`);
|
|
66247
66386
|
if (!isFile(filePath)) continue;
|
|
66248
66387
|
const isDataFile = DATA_CONFIG_EXTENSIONS.has(extension);
|
|
@@ -70049,7 +70188,11 @@ const neutralizeDisableDirectives = async (rootDirectory, includePaths) => {
|
|
|
70049
70188
|
const ROOT_DIRECTORY_PLACEHOLDER = "<root>";
|
|
70050
70189
|
const normalizeConfigForHash = (config) => {
|
|
70051
70190
|
const clone = JSON.parse(JSON.stringify(config));
|
|
70052
|
-
if (clone?.settings?.["react-doctor"])
|
|
70191
|
+
if (clone?.settings?.["react-doctor"]) {
|
|
70192
|
+
const reactDoctorSettings = clone.settings["react-doctor"];
|
|
70193
|
+
reactDoctorSettings.rootDirectory = ROOT_DIRECTORY_PLACEHOLDER;
|
|
70194
|
+
if (Array.isArray(reactDoctorSettings.unpluginAutoImportRootDirectories)) reactDoctorSettings.unpluginAutoImportRootDirectories = [ROOT_DIRECTORY_PLACEHOLDER];
|
|
70195
|
+
}
|
|
70053
70196
|
if (Array.isArray(clone?.jsPlugins)) clone.jsPlugins = clone.jsPlugins.map((_, index) => `<plugin:${index}>`);
|
|
70054
70197
|
return clone;
|
|
70055
70198
|
};
|
|
@@ -70208,13 +70351,14 @@ const buildUserPluginRules = (userPlugin, severityControls) => {
|
|
|
70208
70351
|
}
|
|
70209
70352
|
return enabled;
|
|
70210
70353
|
};
|
|
70211
|
-
const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, extendsPaths = [], ignoredTags = /* @__PURE__ */ new Set(), includedTags = /* @__PURE__ */ new Set(), includeTagDefaults = false, serverAuthFunctionNames, severityControls, userPlugins = [], disableReactHooksJsPlugin = false, ruleSelection, sidecarRuleIdFilter }) => {
|
|
70354
|
+
const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, extendsPaths = [], ignoredTags = /* @__PURE__ */ new Set(), includedTags = /* @__PURE__ */ new Set(), includeTagDefaults = false, runtimeGlobals, unpluginAutoImportGlobalScopes, serverAuthFunctionNames, severityControls, userPlugins = [], disableReactHooksJsPlugin = false, ruleSelection, sidecarRuleIdFilter }) => {
|
|
70212
70355
|
const hasIncludedTags = includedTags.size > 0;
|
|
70213
70356
|
const reactHooksJsPlugin = disableReactHooksJsPlugin || ruleSelection === "sidecar" || hasIncludedTags ? null : resolveReactHooksJsPlugin(project.hasReactCompiler || project.hasReactCompilerLintPlugin === true, customRulesOnly);
|
|
70214
70357
|
const reactCompilerRules = reactHooksJsPlugin ? applyRuleSeverityControls(filterRulesToAvailable(REACT_COMPILER_RULES, "react-hooks-js", reactHooksJsPlugin.availableRuleNames), severityControls) : {};
|
|
70215
70358
|
const jsPlugins = [];
|
|
70216
70359
|
if (reactHooksJsPlugin) jsPlugins.push(reactHooksJsPlugin.entry);
|
|
70217
70360
|
const capabilities = getCapabilities(project);
|
|
70361
|
+
const settingsRootDirectory = resolveSettingsRootDirectory(project.rootDirectory);
|
|
70218
70362
|
const enabledReactDoctorRules = {};
|
|
70219
70363
|
for (const registryEntry of REACT_DOCTOR_RULES) {
|
|
70220
70364
|
const rule = reactDoctorPlugin.rules[registryEntry.id];
|
|
@@ -70260,8 +70404,16 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
|
|
|
70260
70404
|
jsPlugins: [...jsPlugins, pluginPath],
|
|
70261
70405
|
settings: { "react-doctor": {
|
|
70262
70406
|
framework: project.framework,
|
|
70263
|
-
rootDirectory:
|
|
70407
|
+
rootDirectory: settingsRootDirectory,
|
|
70264
70408
|
capabilities: [...capabilities].sort(),
|
|
70409
|
+
...runtimeGlobals && runtimeGlobals.length > 0 ? { runtimeGlobals: [...runtimeGlobals] } : {},
|
|
70410
|
+
...unpluginAutoImportGlobalScopes && unpluginAutoImportGlobalScopes.length > 0 ? {
|
|
70411
|
+
unpluginAutoImportRootDirectories: [...new Set([settingsRootDirectory, project.rootDirectory])],
|
|
70412
|
+
unpluginAutoImportGlobalScopes: unpluginAutoImportGlobalScopes.map((scope) => ({
|
|
70413
|
+
directory: scope.directory,
|
|
70414
|
+
names: [...scope.names]
|
|
70415
|
+
}))
|
|
70416
|
+
} : {},
|
|
70265
70417
|
...project.shopifyFlashListMajorVersion !== null ? { shopifyFlashListMajorVersion: project.shopifyFlashListMajorVersion } : {},
|
|
70266
70418
|
...serverAuthFunctionNames && serverAuthFunctionNames.length > 0 ? { serverAuthFunctionNames: [...serverAuthFunctionNames] } : {}
|
|
70267
70419
|
} },
|
|
@@ -70272,6 +70424,245 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
|
|
|
70272
70424
|
}
|
|
70273
70425
|
};
|
|
70274
70426
|
};
|
|
70427
|
+
const AUTO_IMPORT_ADAPTER_PATTERN = /^unplugin-auto-import\/(?:astro|esbuild|rollup|rolldown|rspack|vite|webpack)$/;
|
|
70428
|
+
const CONFIG_BASENAMES = [
|
|
70429
|
+
"astro.config",
|
|
70430
|
+
"esbuild.config",
|
|
70431
|
+
"rollup.config",
|
|
70432
|
+
"rolldown.config",
|
|
70433
|
+
"rspack.config",
|
|
70434
|
+
"vite.config",
|
|
70435
|
+
"webpack.config"
|
|
70436
|
+
];
|
|
70437
|
+
const CONFIG_EXTENSIONS = [
|
|
70438
|
+
".cjs",
|
|
70439
|
+
".cts",
|
|
70440
|
+
".js",
|
|
70441
|
+
".mjs",
|
|
70442
|
+
".mts",
|
|
70443
|
+
".ts"
|
|
70444
|
+
];
|
|
70445
|
+
const CONFIG_FILENAMES = new Set(CONFIG_BASENAMES.flatMap((basename) => CONFIG_EXTENSIONS.map((extension) => `${basename}${extension}`)));
|
|
70446
|
+
const DEFAULT_ESLINT_GLOBALS_PATH = ".eslintrc-auto-import.json";
|
|
70447
|
+
const SUPPORTED_GLOBAL_VALUES = new Set([
|
|
70448
|
+
true,
|
|
70449
|
+
false,
|
|
70450
|
+
"readable",
|
|
70451
|
+
"readonly",
|
|
70452
|
+
"writable",
|
|
70453
|
+
"writeable"
|
|
70454
|
+
]);
|
|
70455
|
+
const getStaticProperty = (objectExpression, propertyName) => objectExpression.properties.find((property) => {
|
|
70456
|
+
if (ts.isSpreadAssignment(property)) return false;
|
|
70457
|
+
const name = ts.isComputedPropertyName(property.name) ? unwrapTypescriptExpression(property.name.expression) : property.name;
|
|
70458
|
+
return (ts.isIdentifier(name) || ts.isStringLiteralLike(name)) && name.text === propertyName;
|
|
70459
|
+
}) ?? null;
|
|
70460
|
+
const hasNonLiteralComputedProperty = (objectExpression) => objectExpression.properties.some((property) => !ts.isSpreadAssignment(property) && ts.isComputedPropertyName(property.name) && !ts.isStringLiteralLike(unwrapTypescriptExpression(property.name.expression)));
|
|
70461
|
+
const getStaticPropertyAssignment = (objectExpression, propertyName) => {
|
|
70462
|
+
const property = getStaticProperty(objectExpression, propertyName);
|
|
70463
|
+
return property && ts.isPropertyAssignment(property) ? property : null;
|
|
70464
|
+
};
|
|
70465
|
+
const getRequireModuleSpecifier = (expression) => {
|
|
70466
|
+
const unwrappedExpression = unwrapTypescriptExpression(expression);
|
|
70467
|
+
if (ts.isPropertyAccessExpression(unwrappedExpression) && unwrappedExpression.name.text === "default") return getRequireModuleSpecifier(unwrappedExpression.expression);
|
|
70468
|
+
if (!ts.isCallExpression(unwrappedExpression) || !ts.isIdentifier(unwrappedExpression.expression) || unwrappedExpression.expression.text !== "require" || unwrappedExpression.arguments.length !== 1) return null;
|
|
70469
|
+
const moduleSpecifier = unwrappedExpression.arguments[0];
|
|
70470
|
+
return moduleSpecifier && ts.isStringLiteralLike(moduleSpecifier) ? moduleSpecifier.text : null;
|
|
70471
|
+
};
|
|
70472
|
+
const getRequiredPropertyModuleSpecifier = (expression, propertyName) => {
|
|
70473
|
+
const unwrappedExpression = unwrapTypescriptExpression(expression);
|
|
70474
|
+
return ts.isPropertyAccessExpression(unwrappedExpression) && unwrappedExpression.name.text === propertyName ? getRequireModuleSpecifier(unwrappedExpression.expression) : null;
|
|
70475
|
+
};
|
|
70476
|
+
const isCommonJsExportAssignment = (node, sourceFile) => ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken && (node.left.getText(sourceFile) === "module.exports" || node.left.getText(sourceFile) === "exports.default");
|
|
70477
|
+
const isTopLevelExpression = (node) => {
|
|
70478
|
+
let ancestor = node.parent;
|
|
70479
|
+
while (ancestor && !ts.isSourceFile(ancestor)) {
|
|
70480
|
+
if (ts.isExpressionStatement(ancestor)) return ts.isSourceFile(ancestor.parent);
|
|
70481
|
+
if (!ts.isParenthesizedExpression(ancestor) && !ts.isAsExpression(ancestor) && !ts.isSatisfiesExpression(ancestor) && !ts.isNonNullExpression(ancestor) && !ts.isTypeAssertionExpression(ancestor) && !ts.isAwaitExpression(ancestor)) return false;
|
|
70482
|
+
ancestor = ancestor.parent;
|
|
70483
|
+
}
|
|
70484
|
+
return false;
|
|
70485
|
+
};
|
|
70486
|
+
const isInsideActiveConfigProperty = (node, propertyName, sourceFile, esbuildBindings, esbuildNamespaceBindings) => {
|
|
70487
|
+
let ancestor = node.parent;
|
|
70488
|
+
let didFindConfigProperty = false;
|
|
70489
|
+
while (ancestor && !ts.isSourceFile(ancestor)) {
|
|
70490
|
+
if (!didFindConfigProperty && !ts.isArrayLiteralExpression(ancestor) && !ts.isParenthesizedExpression(ancestor) && !ts.isAsExpression(ancestor) && !ts.isSatisfiesExpression(ancestor) && !ts.isNonNullExpression(ancestor) && !ts.isTypeAssertionExpression(ancestor) && !ts.isPropertyAssignment(ancestor)) return false;
|
|
70491
|
+
if (ts.isPropertyAssignment(ancestor)) {
|
|
70492
|
+
const isConfigProperty = (ts.isIdentifier(ancestor.name) || ts.isStringLiteralLike(ancestor.name)) && ancestor.name.text === propertyName;
|
|
70493
|
+
if (didFindConfigProperty || !isConfigProperty) return false;
|
|
70494
|
+
if (!ts.isObjectLiteralExpression(ancestor.parent) || ancestor.parent.properties.some(ts.isSpreadAssignment)) return false;
|
|
70495
|
+
didFindConfigProperty = true;
|
|
70496
|
+
ancestor = ancestor.parent;
|
|
70497
|
+
continue;
|
|
70498
|
+
}
|
|
70499
|
+
if (didFindConfigProperty) {
|
|
70500
|
+
if (ts.isExportAssignment(ancestor)) return true;
|
|
70501
|
+
if (isCommonJsExportAssignment(ancestor, sourceFile)) return isTopLevelExpression(ancestor);
|
|
70502
|
+
if (propertyName === "plugins" && ts.isCallExpression(ancestor) && (ts.isIdentifier(ancestor.expression) ? esbuildBindings.has(ancestor.expression.text) : ts.isPropertyAccessExpression(ancestor.expression) && ancestor.expression.name.text === "build" && (ts.isIdentifier(ancestor.expression.expression) && esbuildNamespaceBindings.has(ancestor.expression.expression.text) || getRequireModuleSpecifier(ancestor.expression.expression) === "esbuild"))) return isTopLevelExpression(ancestor);
|
|
70503
|
+
if (!(ts.isObjectLiteralExpression(ancestor) || ts.isParenthesizedExpression(ancestor) || ts.isAsExpression(ancestor) || ts.isSatisfiesExpression(ancestor) || ts.isNonNullExpression(ancestor) || ts.isTypeAssertionExpression(ancestor) || ts.isCallExpression(ancestor) && ts.isIdentifier(ancestor.expression) && ancestor.expression.text === "defineConfig")) return false;
|
|
70504
|
+
}
|
|
70505
|
+
ancestor = ancestor.parent;
|
|
70506
|
+
}
|
|
70507
|
+
return false;
|
|
70508
|
+
};
|
|
70509
|
+
const getGlobalsPathFromActiveAutoImportCall = (callExpression, packageDirectory) => {
|
|
70510
|
+
const optionsExpression = callExpression.arguments[0];
|
|
70511
|
+
if (!optionsExpression) return null;
|
|
70512
|
+
const unwrappedOptions = unwrapTypescriptExpression(optionsExpression);
|
|
70513
|
+
if (!ts.isObjectLiteralExpression(unwrappedOptions)) return null;
|
|
70514
|
+
if (unwrappedOptions.properties.some(ts.isSpreadAssignment) || hasNonLiteralComputedProperty(unwrappedOptions)) return null;
|
|
70515
|
+
if (getStaticProperty(unwrappedOptions, "include") || getStaticProperty(unwrappedOptions, "exclude")) return null;
|
|
70516
|
+
const eslintrcProperty = getStaticPropertyAssignment(unwrappedOptions, "eslintrc");
|
|
70517
|
+
if (!eslintrcProperty) return null;
|
|
70518
|
+
const eslintrcExpression = unwrapTypescriptExpression(eslintrcProperty.initializer);
|
|
70519
|
+
if (!ts.isObjectLiteralExpression(eslintrcExpression)) return null;
|
|
70520
|
+
if (eslintrcExpression.properties.some(ts.isSpreadAssignment) || hasNonLiteralComputedProperty(eslintrcExpression)) return null;
|
|
70521
|
+
const enabledProperty = getStaticPropertyAssignment(eslintrcExpression, "enabled");
|
|
70522
|
+
if (!enabledProperty || unwrapTypescriptExpression(enabledProperty.initializer).kind !== ts.SyntaxKind.TrueKeyword) return null;
|
|
70523
|
+
const filepathProperty = getStaticProperty(eslintrcExpression, "filepath");
|
|
70524
|
+
if (!filepathProperty) return Path.join(packageDirectory, DEFAULT_ESLINT_GLOBALS_PATH);
|
|
70525
|
+
if (!ts.isPropertyAssignment(filepathProperty)) return null;
|
|
70526
|
+
const filepathExpression = unwrapTypescriptExpression(filepathProperty.initializer);
|
|
70527
|
+
return ts.isStringLiteralLike(filepathExpression) ? Path.resolve(packageDirectory, filepathExpression.text) : null;
|
|
70528
|
+
};
|
|
70529
|
+
const collectGlobalsPathsFromConfig = (configPath, packageDirectory) => {
|
|
70530
|
+
let sourceText;
|
|
70531
|
+
try {
|
|
70532
|
+
sourceText = NFS.readFileSync(configPath, "utf8");
|
|
70533
|
+
} catch {
|
|
70534
|
+
return {
|
|
70535
|
+
didFindActiveAutoImport: false,
|
|
70536
|
+
globalsPaths: []
|
|
70537
|
+
};
|
|
70538
|
+
}
|
|
70539
|
+
const sourceFile = ts.createSourceFile(configPath, sourceText, ts.ScriptTarget.Latest, true);
|
|
70540
|
+
const autoImportBindings = /* @__PURE__ */ new Map();
|
|
70541
|
+
const esbuildBindings = /* @__PURE__ */ new Set();
|
|
70542
|
+
const esbuildNamespaceBindings = /* @__PURE__ */ new Set();
|
|
70543
|
+
for (const statement of sourceFile.statements) {
|
|
70544
|
+
if (ts.isImportDeclaration(statement) && ts.isStringLiteralLike(statement.moduleSpecifier)) {
|
|
70545
|
+
const moduleSpecifier = statement.moduleSpecifier.text;
|
|
70546
|
+
if (AUTO_IMPORT_ADAPTER_PATTERN.test(moduleSpecifier)) {
|
|
70547
|
+
const defaultBinding = statement.importClause?.name;
|
|
70548
|
+
if (defaultBinding) autoImportBindings.set(defaultBinding.text, moduleSpecifier);
|
|
70549
|
+
}
|
|
70550
|
+
if (moduleSpecifier === "esbuild") {
|
|
70551
|
+
const defaultBinding = statement.importClause?.name;
|
|
70552
|
+
if (defaultBinding) esbuildNamespaceBindings.add(defaultBinding.text);
|
|
70553
|
+
const namedBindings = statement.importClause?.namedBindings;
|
|
70554
|
+
if (namedBindings && ts.isNamedImports(namedBindings)) {
|
|
70555
|
+
for (const importSpecifier of namedBindings.elements) if ((importSpecifier.propertyName ?? importSpecifier.name).text === "build") esbuildBindings.add(importSpecifier.name.text);
|
|
70556
|
+
}
|
|
70557
|
+
if (namedBindings && ts.isNamespaceImport(namedBindings)) esbuildNamespaceBindings.add(namedBindings.name.text);
|
|
70558
|
+
}
|
|
70559
|
+
}
|
|
70560
|
+
if (!ts.isVariableStatement(statement)) continue;
|
|
70561
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
70562
|
+
if (!declaration.initializer) continue;
|
|
70563
|
+
const declarationName = ts.isIdentifier(declaration.name) ? declaration.name.text : null;
|
|
70564
|
+
const moduleSpecifier = getRequireModuleSpecifier(declaration.initializer);
|
|
70565
|
+
if (declarationName && moduleSpecifier && AUTO_IMPORT_ADAPTER_PATTERN.test(moduleSpecifier)) autoImportBindings.set(declarationName, moduleSpecifier);
|
|
70566
|
+
if (moduleSpecifier === "esbuild") {
|
|
70567
|
+
if (declarationName) esbuildNamespaceBindings.add(declarationName);
|
|
70568
|
+
if (ts.isObjectBindingPattern(declaration.name)) for (const bindingElement of declaration.name.elements) {
|
|
70569
|
+
const importedName = bindingElement.propertyName ?? bindingElement.name;
|
|
70570
|
+
if (ts.isIdentifier(importedName) && importedName.text === "build" && ts.isIdentifier(bindingElement.name)) esbuildBindings.add(bindingElement.name.text);
|
|
70571
|
+
}
|
|
70572
|
+
}
|
|
70573
|
+
if (declarationName && getRequiredPropertyModuleSpecifier(declaration.initializer, "build") === "esbuild") esbuildBindings.add(declarationName);
|
|
70574
|
+
}
|
|
70575
|
+
}
|
|
70576
|
+
const globalsPaths = /* @__PURE__ */ new Set();
|
|
70577
|
+
let didFindActiveAutoImport = false;
|
|
70578
|
+
let didFindUnsafeActiveAutoImport = false;
|
|
70579
|
+
const visit = (node) => {
|
|
70580
|
+
if (ts.isCallExpression(node)) {
|
|
70581
|
+
const moduleSpecifier = ts.isIdentifier(node.expression) ? autoImportBindings.get(node.expression.text) : getRequireModuleSpecifier(node.expression);
|
|
70582
|
+
if (moduleSpecifier && AUTO_IMPORT_ADAPTER_PATTERN.test(moduleSpecifier)) {
|
|
70583
|
+
if (isInsideActiveConfigProperty(node, moduleSpecifier.endsWith("/astro") ? "integrations" : "plugins", sourceFile, esbuildBindings, esbuildNamespaceBindings)) {
|
|
70584
|
+
didFindActiveAutoImport = true;
|
|
70585
|
+
const globalsPath = getGlobalsPathFromActiveAutoImportCall(node, packageDirectory);
|
|
70586
|
+
if (globalsPath) globalsPaths.add(globalsPath);
|
|
70587
|
+
else didFindUnsafeActiveAutoImport = true;
|
|
70588
|
+
}
|
|
70589
|
+
}
|
|
70590
|
+
}
|
|
70591
|
+
ts.forEachChild(node, visit);
|
|
70592
|
+
};
|
|
70593
|
+
visit(sourceFile);
|
|
70594
|
+
return {
|
|
70595
|
+
didFindActiveAutoImport,
|
|
70596
|
+
globalsPaths: didFindUnsafeActiveAutoImport ? [] : [...globalsPaths]
|
|
70597
|
+
};
|
|
70598
|
+
};
|
|
70599
|
+
const collectGeneratedGlobalNames = (globalsPath, rootDirectory) => {
|
|
70600
|
+
const relativePath = Path.relative(rootDirectory, globalsPath);
|
|
70601
|
+
if (relativePath.startsWith("..") || Path.isAbsolute(relativePath)) return [];
|
|
70602
|
+
const parsed = failOpenReadJson(globalsPath, null);
|
|
70603
|
+
if (!isPlainObject(parsed) || !isPlainObject(parsed.globals)) return [];
|
|
70604
|
+
return Object.entries(parsed.globals).filter((entry) => entry[0].length > 0 && (typeof entry[1] === "boolean" || typeof entry[1] === "string") && SUPPORTED_GLOBAL_VALUES.has(entry[1])).map(([name]) => name).sort();
|
|
70605
|
+
};
|
|
70606
|
+
const findOwningPackageDirectory = (absoluteFilePath, rootDirectory, cache) => {
|
|
70607
|
+
let currentDirectory = Path.dirname(absoluteFilePath);
|
|
70608
|
+
const visitedDirectories = [];
|
|
70609
|
+
while (true) {
|
|
70610
|
+
const cachedDirectory = cache.get(currentDirectory);
|
|
70611
|
+
if (cachedDirectory !== void 0) {
|
|
70612
|
+
for (const visitedDirectory of visitedDirectories) cache.set(visitedDirectory, cachedDirectory);
|
|
70613
|
+
return cachedDirectory;
|
|
70614
|
+
}
|
|
70615
|
+
const relativeDirectory = Path.relative(rootDirectory, currentDirectory);
|
|
70616
|
+
if (relativeDirectory.startsWith("..") || Path.isAbsolute(relativeDirectory)) {
|
|
70617
|
+
for (const visitedDirectory of visitedDirectories) cache.set(visitedDirectory, null);
|
|
70618
|
+
return null;
|
|
70619
|
+
}
|
|
70620
|
+
visitedDirectories.push(currentDirectory);
|
|
70621
|
+
if (NFS.existsSync(Path.join(currentDirectory, "package.json"))) {
|
|
70622
|
+
for (const visitedDirectory of visitedDirectories) cache.set(visitedDirectory, currentDirectory);
|
|
70623
|
+
return currentDirectory;
|
|
70624
|
+
}
|
|
70625
|
+
if (currentDirectory === rootDirectory) {
|
|
70626
|
+
for (const visitedDirectory of visitedDirectories) cache.set(visitedDirectory, null);
|
|
70627
|
+
return null;
|
|
70628
|
+
}
|
|
70629
|
+
currentDirectory = Path.dirname(currentDirectory);
|
|
70630
|
+
}
|
|
70631
|
+
};
|
|
70632
|
+
const collectPackageGlobalNames = (packageDirectory, rootDirectory) => {
|
|
70633
|
+
let directoryEntries;
|
|
70634
|
+
try {
|
|
70635
|
+
directoryEntries = NFS.readdirSync(packageDirectory, { withFileTypes: true });
|
|
70636
|
+
} catch {
|
|
70637
|
+
return [];
|
|
70638
|
+
}
|
|
70639
|
+
const configuredGlobalsPaths = [];
|
|
70640
|
+
for (const entry of directoryEntries) {
|
|
70641
|
+
if (!entry.isFile() && !entry.isSymbolicLink() || !CONFIG_FILENAMES.has(entry.name)) continue;
|
|
70642
|
+
const configGlobalsPaths = collectGlobalsPathsFromConfig(Path.join(packageDirectory, entry.name), packageDirectory);
|
|
70643
|
+
if (configGlobalsPaths.didFindActiveAutoImport) configuredGlobalsPaths.push(configGlobalsPaths.globalsPaths.toSorted());
|
|
70644
|
+
}
|
|
70645
|
+
if (configuredGlobalsPaths.length === 0) return [];
|
|
70646
|
+
const globalsPaths = configuredGlobalsPaths[0];
|
|
70647
|
+
if (configuredGlobalsPaths.some((candidatePaths) => candidatePaths.length !== globalsPaths.length || candidatePaths.some((candidatePath, index) => candidatePath !== globalsPaths[index]))) return [];
|
|
70648
|
+
const names = /* @__PURE__ */ new Set();
|
|
70649
|
+
for (const globalsPath of globalsPaths) for (const name of collectGeneratedGlobalNames(globalsPath, rootDirectory)) names.add(name);
|
|
70650
|
+
return [...names].sort();
|
|
70651
|
+
};
|
|
70652
|
+
const collectUnpluginAutoImportGlobalScopes = ({ rootDirectory, candidateFiles }) => {
|
|
70653
|
+
const absoluteRootDirectory = Path.resolve(rootDirectory);
|
|
70654
|
+
const packageDirectoryCache = /* @__PURE__ */ new Map();
|
|
70655
|
+
const packageDirectories = /* @__PURE__ */ new Set();
|
|
70656
|
+
for (const candidateFile of candidateFiles) {
|
|
70657
|
+
const packageDirectory = findOwningPackageDirectory(Path.resolve(absoluteRootDirectory, candidateFile), absoluteRootDirectory, packageDirectoryCache);
|
|
70658
|
+
if (packageDirectory) packageDirectories.add(packageDirectory);
|
|
70659
|
+
}
|
|
70660
|
+
const scopes = [...packageDirectories].map((packageDirectory) => ({
|
|
70661
|
+
directory: Path.relative(absoluteRootDirectory, packageDirectory).replaceAll("\\", "/"),
|
|
70662
|
+
names: collectPackageGlobalNames(packageDirectory, absoluteRootDirectory)
|
|
70663
|
+
})).sort((firstScope, secondScope) => firstScope.directory.localeCompare(secondScope.directory));
|
|
70664
|
+
return scopes.some((scope) => scope.names.length > 0) ? scopes : [];
|
|
70665
|
+
};
|
|
70275
70666
|
const validateDiagnostic$1 = decodeUnknownSync(Diagnostic);
|
|
70276
70667
|
const decodeFileDiagnostics = (raw) => {
|
|
70277
70668
|
if (!Array.isArray(raw)) return null;
|
|
@@ -70594,6 +70985,12 @@ const appendReanimatedSharedValueHint = (help, rule, project) => {
|
|
|
70594
70985
|
if (!help) return REANIMATED_SHARED_VALUE_HINT;
|
|
70595
70986
|
return `${help}\n\n${REANIMATED_SHARED_VALUE_HINT}`;
|
|
70596
70987
|
};
|
|
70988
|
+
const columnOfUtf8Offset = (sourceBuffer, utf8Offset) => {
|
|
70989
|
+
const boundedOffset = Math.min(Math.max(utf8Offset, 0), sourceBuffer.length);
|
|
70990
|
+
let lineStartOffset = boundedOffset;
|
|
70991
|
+
while (lineStartOffset > 0 && sourceBuffer[lineStartOffset - 1] !== 10) lineStartOffset--;
|
|
70992
|
+
return sourceBuffer.subarray(lineStartOffset, boundedOffset).toString("utf8").length + 1;
|
|
70993
|
+
};
|
|
70597
70994
|
const REDACTED_PLACEHOLDER = "<redacted>";
|
|
70598
70995
|
const KEEP_PREFIX = `$1${REDACTED_PLACEHOLDER}`;
|
|
70599
70996
|
const KNOWN_SECRET_RULES = [
|
|
@@ -71309,7 +71706,7 @@ const resolveMatchByOccurrence = (rule, category) => OCCURRENCE_MATCHED_CATEGORI
|
|
|
71309
71706
|
* with empty text still carry a useful jump target, so they're kept
|
|
71310
71707
|
* with a neutral message.
|
|
71311
71708
|
*/
|
|
71312
|
-
const buildRelatedLocations = (labels, filePath) => {
|
|
71709
|
+
const buildRelatedLocations = (labels, filePath, sourceBuffer) => {
|
|
71313
71710
|
if (labels.length <= 1) return [];
|
|
71314
71711
|
const related = [];
|
|
71315
71712
|
for (let labelIndex = 1; labelIndex < labels.length; labelIndex++) {
|
|
@@ -71317,8 +71714,8 @@ const buildRelatedLocations = (labels, filePath) => {
|
|
|
71317
71714
|
if (!label?.span) continue;
|
|
71318
71715
|
related.push({
|
|
71319
71716
|
filePath,
|
|
71320
|
-
line: label.span.line ?? 0,
|
|
71321
|
-
column: label.span.column ?? 0,
|
|
71717
|
+
line: sourceBuffer === null ? label.span.line ?? 0 : lineOfUtf8Offset(sourceBuffer, label.span.offset),
|
|
71718
|
+
column: sourceBuffer === null ? label.span.column ?? 0 : columnOfUtf8Offset(sourceBuffer, label.span.offset),
|
|
71322
71719
|
offset: label.span.offset,
|
|
71323
71720
|
length: label.span.length,
|
|
71324
71721
|
message: label.label ?? ""
|
|
@@ -71338,7 +71735,7 @@ const isOxlintOutput = (value) => isRecord(value) && Array.isArray(value.diagnos
|
|
|
71338
71735
|
* to the first `{`. Raises `OxlintOutputUnparseable` when the
|
|
71339
71736
|
* stdout isn't valid JSON or doesn't carry a `diagnostics` array.
|
|
71340
71737
|
*/
|
|
71341
|
-
const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
71738
|
+
const parseOxlintOutput = (stdout, project, rootDirectory, sourcePathByLintPath) => {
|
|
71342
71739
|
if (!stdout) return [];
|
|
71343
71740
|
const jsonStart = stdout.indexOf("{");
|
|
71344
71741
|
const sanitizedStdout = jsonStart > 0 ? stdout.slice(jsonStart) : stdout;
|
|
@@ -71355,8 +71752,10 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
71355
71752
|
const sourceBufferCache = /* @__PURE__ */ new Map();
|
|
71356
71753
|
const sourceLinesCache = /* @__PURE__ */ new Map();
|
|
71357
71754
|
const resolveAbsolutePath = (filename) => Path.isAbsolute(filename) ? filename : Path.resolve(rootDirectory || ".", filename);
|
|
71755
|
+
const resolveMappedSourceFilename = (filename) => sourcePathByLintPath?.get(Path.normalize(resolveAbsolutePath(filename)));
|
|
71756
|
+
const resolveSourceFilename = (filename) => resolveMappedSourceFilename(filename) ?? filename;
|
|
71358
71757
|
const readSourceBuffer = (filename) => {
|
|
71359
|
-
const absolutePath = resolveAbsolutePath(filename);
|
|
71758
|
+
const absolutePath = resolveAbsolutePath(resolveSourceFilename(filename));
|
|
71360
71759
|
const cached = sourceBufferCache.get(absolutePath);
|
|
71361
71760
|
if (cached !== void 0) return cached;
|
|
71362
71761
|
let sourceBuffer;
|
|
@@ -71369,7 +71768,7 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
71369
71768
|
return sourceBuffer;
|
|
71370
71769
|
};
|
|
71371
71770
|
const readSourceLines = (filename) => {
|
|
71372
|
-
const absolutePath = resolveAbsolutePath(filename);
|
|
71771
|
+
const absolutePath = resolveAbsolutePath(resolveSourceFilename(filename));
|
|
71373
71772
|
const cached = sourceLinesCache.get(absolutePath);
|
|
71374
71773
|
if (cached !== void 0) return cached;
|
|
71375
71774
|
const sourceBuffer = readSourceBuffer(filename);
|
|
@@ -71378,27 +71777,30 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
71378
71777
|
return sourceLines;
|
|
71379
71778
|
};
|
|
71380
71779
|
const isMinifiedDiagnosticFile = (filename) => {
|
|
71381
|
-
const absolutePath = resolveAbsolutePath(filename);
|
|
71780
|
+
const absolutePath = resolveAbsolutePath(resolveSourceFilename(filename));
|
|
71382
71781
|
const cached = minifiedFileCache.get(absolutePath);
|
|
71383
71782
|
if (cached !== void 0) return cached;
|
|
71384
71783
|
const minified = isMinifiedSource(absolutePath);
|
|
71385
71784
|
minifiedFileCache.set(absolutePath, minified);
|
|
71386
71785
|
return minified;
|
|
71387
71786
|
};
|
|
71388
|
-
return suppressMemoizationInBailedOutFunctions(parsed.diagnostics.filter((diagnostic) => isMappableOxlintDiagnostic(diagnostic) && isLintableSourceFile(diagnostic.filename) && !(TYPESCRIPT_DECLARATION_FILE_PATTERN.test(diagnostic.filename) && OXLINT_IGNORED_DECLARATION_DIAGNOSTIC_CODES.has(diagnostic.code)) && !isMinifiedDiagnosticFile(diagnostic.filename) && !shouldSuppressLocalUseHookDiagnostic(diagnostic, rootDirectory) && !shouldSuppressCompilerFindingInWorklet(diagnostic, project, rootDirectory)).map((diagnostic) => {
|
|
71787
|
+
return suppressMemoizationInBailedOutFunctions(parsed.diagnostics.filter((diagnostic) => isMappableOxlintDiagnostic(diagnostic) && isLintableSourceFile(resolveSourceFilename(diagnostic.filename)) && !(TYPESCRIPT_DECLARATION_FILE_PATTERN.test(diagnostic.filename) && OXLINT_IGNORED_DECLARATION_DIAGNOSTIC_CODES.has(diagnostic.code)) && !isMinifiedDiagnosticFile(diagnostic.filename) && !shouldSuppressLocalUseHookDiagnostic(diagnostic, rootDirectory) && !shouldSuppressCompilerFindingInWorklet(diagnostic, project, rootDirectory)).map((diagnostic) => {
|
|
71389
71788
|
const { plugin, rule } = parseRuleCode(diagnostic.code);
|
|
71390
71789
|
const primaryLabel = diagnostic.labels[0];
|
|
71391
71790
|
const cleaned = cleanDiagnosticMessage(diagnostic.message, diagnostic.help, plugin, rule, project);
|
|
71392
|
-
const
|
|
71791
|
+
const mappedSourceFilename = resolveMappedSourceFilename(diagnostic.filename);
|
|
71792
|
+
const normalizedFilePath = (mappedSourceFilename ?? diagnostic.filename).replaceAll("\\", "/");
|
|
71393
71793
|
const primarySpan = primaryLabel?.span;
|
|
71394
71794
|
const sourceBuffer = primarySpan ? readSourceBuffer(diagnostic.filename) : null;
|
|
71395
|
-
const relatedLocations = buildRelatedLocations(diagnostic.labels, normalizedFilePath);
|
|
71795
|
+
const relatedLocations = buildRelatedLocations(diagnostic.labels, normalizedFilePath, mappedSourceFilename === void 0 ? null : sourceBuffer);
|
|
71396
71796
|
const category = resolveDiagnosticCategory(plugin, rule);
|
|
71397
71797
|
const matchByOccurrence = resolveMatchByOccurrence(rule, category);
|
|
71398
71798
|
const sourceLines = primarySpan ? readSourceLines(diagnostic.filename) : null;
|
|
71399
|
-
const
|
|
71799
|
+
const primaryLineNumber = primarySpan && mappedSourceFilename !== void 0 && sourceBuffer !== null ? lineOfUtf8Offset(sourceBuffer, primarySpan.offset) : primarySpan?.line ?? 0;
|
|
71800
|
+
const primaryColumnNumber = primarySpan && mappedSourceFilename !== void 0 && sourceBuffer !== null ? columnOfUtf8Offset(sourceBuffer, primarySpan.offset) : primarySpan?.column ?? 0;
|
|
71801
|
+
const primaryLineIndex = primarySpan ? primaryLineNumber - 1 : -1;
|
|
71400
71802
|
const primaryLine = sourceLines?.[primaryLineIndex];
|
|
71401
|
-
const primaryColumnIndex = primarySpan ?
|
|
71803
|
+
const primaryColumnIndex = primarySpan ? primaryColumnNumber - 1 : -1;
|
|
71402
71804
|
const isJsxTagLabel = primaryLine !== void 0 && primaryColumnIndex >= 0 && (primaryLine[primaryColumnIndex] === "<" || primaryLine[primaryColumnIndex - 1] === "<");
|
|
71403
71805
|
const jsxOpenerEndLineIndex = sourceLines && isJsxTagLabel ? findJsxOpenerSpan(sourceLines, primaryLineIndex) : null;
|
|
71404
71806
|
const primarySpanEndLine = jsxOpenerEndLineIndex !== null ? jsxOpenerEndLineIndex + 1 : primarySpan && sourceBuffer ? lineOfUtf8Offset(sourceBuffer, primarySpan.offset + Math.max(primarySpan.length - 1, 0)) : void 0;
|
|
@@ -71411,8 +71813,8 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
71411
71813
|
message: cleaned.message,
|
|
71412
71814
|
help: cleaned.help,
|
|
71413
71815
|
url: diagnostic.url,
|
|
71414
|
-
line:
|
|
71415
|
-
column:
|
|
71816
|
+
line: primaryLineNumber,
|
|
71817
|
+
column: primaryColumnNumber,
|
|
71416
71818
|
...primarySpan ? {
|
|
71417
71819
|
offset: primarySpan.offset,
|
|
71418
71820
|
length: primarySpan.length,
|
|
@@ -71600,7 +72002,11 @@ const isParallelismRelatedSpawnError = (error) => {
|
|
|
71600
72002
|
* loop with a slimmer config in that case.
|
|
71601
72003
|
*/
|
|
71602
72004
|
const spawnLintBatches = async (input) => {
|
|
71603
|
-
const { baseArgs, fileBatches, rootDirectory, nodeBinaryPath, project, onPartialFailure, onFileProgress, spawnTimeoutMs, outputMaxBytes, splitTotalBudgetMs = OXLINT_SPLIT_TOTAL_BUDGET_MS, splitMaxDepth = 8, signal, deadlineEpochMs } = input;
|
|
72005
|
+
const { baseArgs, fileBatches, rootDirectory, nodeBinaryPath, project, sourcePathByLintPath, onPartialFailure, onFileProgress, spawnTimeoutMs, outputMaxBytes, splitTotalBudgetMs = OXLINT_SPLIT_TOTAL_BUDGET_MS, splitMaxDepth = 8, signal, deadlineEpochMs } = input;
|
|
72006
|
+
const resolveSourcePath = (filePath) => {
|
|
72007
|
+
const absoluteFilePath = Path.isAbsolute(filePath) ? filePath : Path.resolve(rootDirectory, filePath);
|
|
72008
|
+
return sourcePathByLintPath?.get(Path.normalize(absoluteFilePath)) ?? filePath;
|
|
72009
|
+
};
|
|
71604
72010
|
const requestedConcurrency = resolveScanConcurrency(input.concurrency ?? 1);
|
|
71605
72011
|
let rescueDeadlineEpochMs;
|
|
71606
72012
|
const isPastDeadline = () => deadlineEpochMs !== void 0 && remainingDeadlineBudgetMs(deadlineEpochMs) === 0 || rescueDeadlineEpochMs !== void 0 && remainingDeadlineBudgetMs(rescueDeadlineEpochMs) === 0;
|
|
@@ -71620,7 +72026,7 @@ const spawnLintBatches = async (input) => {
|
|
|
71620
72026
|
}
|
|
71621
72027
|
const batchArgs = [...baseArgs, ...batch];
|
|
71622
72028
|
try {
|
|
71623
|
-
return parseOxlintOutput(await spawnOxlint(batchArgs, rootDirectory, nodeBinaryPath, spawnTimeoutMs, outputMaxBytes, signal), project, rootDirectory);
|
|
72029
|
+
return parseOxlintOutput(await spawnOxlint(batchArgs, rootDirectory, nodeBinaryPath, spawnTimeoutMs, outputMaxBytes, signal), project, rootDirectory, sourcePathByLintPath);
|
|
71624
72030
|
} catch (error) {
|
|
71625
72031
|
if (!isSplittableReactDoctorError(error)) throw error;
|
|
71626
72032
|
if (isPastDeadline()) {
|
|
@@ -71726,10 +72132,12 @@ const spawnLintBatches = async (input) => {
|
|
|
71726
72132
|
onPartialFailure(buildMessage(`${skippedFiles.slice(0, 3).join(", ")}${skippedFiles.length > 3 ? `, +${skippedFiles.length - 3} more` : ""}`));
|
|
71727
72133
|
};
|
|
71728
72134
|
const reasonHint = firstDropReason ? ` — first failure: ${firstDropReason}` : "";
|
|
71729
|
-
|
|
71730
|
-
|
|
72135
|
+
const droppedSourceFiles = [...new Set(droppedFiles.map(resolveSourcePath))];
|
|
72136
|
+
const deadlineSkippedSourceFiles = [...new Set(outcome.deadlineSkippedFiles.map(resolveSourcePath))];
|
|
72137
|
+
reportSkippedFiles(droppedSourceFiles, (fileListPreview) => `${droppedSourceFiles.length} file(s) failed to lint and were skipped (${fileListPreview})${reasonHint}`);
|
|
72138
|
+
reportSkippedFiles(deadlineSkippedSourceFiles, (fileListPreview) => `${deadlineSkippedSourceFiles.length} file(s) skipped — max scan duration reached before they were linted (${fileListPreview})`);
|
|
71731
72139
|
const unavailableFiles = new Set([...droppedFiles, ...outcome.deadlineSkippedFiles]);
|
|
71732
|
-
input.onAnalyzedFiles?.([...new Set(fileBatches.flat().filter((filePath) => !unavailableFiles.has(filePath)))].sort());
|
|
72140
|
+
input.onAnalyzedFiles?.([...new Set(fileBatches.flat().filter((filePath) => !unavailableFiles.has(filePath)).map(resolveSourcePath))].sort());
|
|
71733
72141
|
return dedupeDiagnostics(diagnostics);
|
|
71734
72142
|
};
|
|
71735
72143
|
let didValidate = false;
|
|
@@ -71828,6 +72236,266 @@ const planLintBatches = ({ baseArgs, files, sizeByFile }) => {
|
|
|
71828
72236
|
}
|
|
71829
72237
|
return batches.filter((batch) => batch.fileIndexes.length > 0).map((batch) => batch.fileIndexes.sort((leftIndex, rightIndex) => leftIndex - rightIndex).map((fileIndex) => files[fileIndex]));
|
|
71830
72238
|
};
|
|
72239
|
+
const THREE_MODULE_IMPORT_PATTERN = /\b(?:from\s*|import\s*(?:\(\s*)?|require\s*\(\s*)["']three(?:\/[^"']*)?["']/;
|
|
72240
|
+
const containsThreeModuleImport = (sourceText) => THREE_MODULE_IMPORT_PATTERN.test(sourceText);
|
|
72241
|
+
const COMMENT_OPEN = "<!--";
|
|
72242
|
+
const COMMENT_CLOSE = "-->";
|
|
72243
|
+
const FRONTMATTER_FENCE = "---";
|
|
72244
|
+
const SCRIPT_TAG_NAME = "script";
|
|
72245
|
+
const SCRIPT_OPEN = `<${SCRIPT_TAG_NAME}`;
|
|
72246
|
+
const SCRIPT_CLOSE = `</${SCRIPT_TAG_NAME}`;
|
|
72247
|
+
const TEMPLATE_TAG_NAME = "template";
|
|
72248
|
+
const TEMPLATE_CLOSE = `</${TEMPLATE_TAG_NAME}`;
|
|
72249
|
+
const JAVASCRIPT_MIME_TYPES = new Set([
|
|
72250
|
+
"application/ecmascript",
|
|
72251
|
+
"application/javascript",
|
|
72252
|
+
"application/x-ecmascript",
|
|
72253
|
+
"application/x-javascript",
|
|
72254
|
+
"text/ecmascript",
|
|
72255
|
+
"text/javascript",
|
|
72256
|
+
"text/javascript1.0",
|
|
72257
|
+
"text/javascript1.1",
|
|
72258
|
+
"text/javascript1.2",
|
|
72259
|
+
"text/javascript1.3",
|
|
72260
|
+
"text/javascript1.4",
|
|
72261
|
+
"text/javascript1.5",
|
|
72262
|
+
"text/jscript",
|
|
72263
|
+
"text/livescript",
|
|
72264
|
+
"text/x-ecmascript",
|
|
72265
|
+
"text/x-javascript"
|
|
72266
|
+
]);
|
|
72267
|
+
const RAW_TEXT_TAG_NAMES = new Set([
|
|
72268
|
+
"iframe",
|
|
72269
|
+
"noembed",
|
|
72270
|
+
"noframes",
|
|
72271
|
+
"noscript",
|
|
72272
|
+
"style",
|
|
72273
|
+
"textarea",
|
|
72274
|
+
"title",
|
|
72275
|
+
"xmp"
|
|
72276
|
+
]);
|
|
72277
|
+
const PLAINTEXT_TAG_NAME = "plaintext";
|
|
72278
|
+
const TAG_OPEN_UTF8_BYTE = "<".charCodeAt(0);
|
|
72279
|
+
const TAG_CLOSE_UTF8_BYTE = ">".charCodeAt(0);
|
|
72280
|
+
const SINGLE_QUOTE_UTF8_BYTE = "'".charCodeAt(0);
|
|
72281
|
+
const DOUBLE_QUOTE_UTF8_BYTE = "\"".charCodeAt(0);
|
|
72282
|
+
const ATTRIBUTE_ASSIGNMENT_UTF8_BYTE = "=".charCodeAt(0);
|
|
72283
|
+
const TAG_SELF_CLOSE_UTF8_BYTE = "/".charCodeAt(0);
|
|
72284
|
+
const TAB_UTF8_BYTE = " ".charCodeAt(0);
|
|
72285
|
+
const FORM_FEED_UTF8_BYTE = "\f".charCodeAt(0);
|
|
72286
|
+
const isHtmlWhitespace = (byte) => byte === TAB_UTF8_BYTE || byte === 10 || byte === FORM_FEED_UTF8_BYTE || byte === 13 || byte === 32;
|
|
72287
|
+
const matchesAsciiCaseInsensitive = (sourceBuffer, startByte, expected) => {
|
|
72288
|
+
if (startByte + expected.length > sourceBuffer.length) return false;
|
|
72289
|
+
for (let expectedIndex = 0; expectedIndex < expected.length; expectedIndex++) {
|
|
72290
|
+
const sourceByte = sourceBuffer[startByte + expectedIndex];
|
|
72291
|
+
if (sourceByte === void 0 || String.fromCharCode(sourceByte).toLowerCase() !== expected[expectedIndex]) return false;
|
|
72292
|
+
}
|
|
72293
|
+
return true;
|
|
72294
|
+
};
|
|
72295
|
+
const isTagBoundary = (byte) => byte === TAG_CLOSE_UTF8_BYTE || byte === TAG_SELF_CLOSE_UTF8_BYTE || isHtmlWhitespace(byte);
|
|
72296
|
+
const isPotentialTagStart = (byte) => {
|
|
72297
|
+
if (byte === void 0) return false;
|
|
72298
|
+
return /[A-Za-z!/?]/.test(String.fromCharCode(byte));
|
|
72299
|
+
};
|
|
72300
|
+
const findLineEnd = (sourceBuffer, lineStartByte) => {
|
|
72301
|
+
let byteIndex = lineStartByte;
|
|
72302
|
+
while (byteIndex < sourceBuffer.length && sourceBuffer[byteIndex] !== 10 && sourceBuffer[byteIndex] !== 13) byteIndex++;
|
|
72303
|
+
return byteIndex;
|
|
72304
|
+
};
|
|
72305
|
+
const findNextLineStart = (sourceBuffer, lineStartByte) => {
|
|
72306
|
+
const lineEndByte = findLineEnd(sourceBuffer, lineStartByte);
|
|
72307
|
+
if (sourceBuffer[lineEndByte] === 13 && sourceBuffer[lineEndByte + 1] === 10) return lineEndByte + 2;
|
|
72308
|
+
return Math.min(lineEndByte + 1, sourceBuffer.length);
|
|
72309
|
+
};
|
|
72310
|
+
const isFrontmatterFenceLine = (sourceBuffer, lineStartByte) => {
|
|
72311
|
+
if (!matchesAsciiCaseInsensitive(sourceBuffer, lineStartByte, FRONTMATTER_FENCE)) return false;
|
|
72312
|
+
const lineEndByte = findLineEnd(sourceBuffer, lineStartByte);
|
|
72313
|
+
for (let byteIndex = lineStartByte + 3; byteIndex < lineEndByte; byteIndex++) if (!isHtmlWhitespace(sourceBuffer[byteIndex])) return false;
|
|
72314
|
+
return true;
|
|
72315
|
+
};
|
|
72316
|
+
const findFrontmatterEnd = (sourceBuffer) => {
|
|
72317
|
+
if (!isFrontmatterFenceLine(sourceBuffer, 0)) return 0;
|
|
72318
|
+
const openingFenceEndByte = findLineEnd(sourceBuffer, 0);
|
|
72319
|
+
let lineStartByte = findNextLineStart(sourceBuffer, 0);
|
|
72320
|
+
while (lineStartByte < sourceBuffer.length) {
|
|
72321
|
+
if (isFrontmatterFenceLine(sourceBuffer, lineStartByte)) return findLineEnd(sourceBuffer, lineStartByte);
|
|
72322
|
+
lineStartByte = findNextLineStart(sourceBuffer, lineStartByte);
|
|
72323
|
+
}
|
|
72324
|
+
return openingFenceEndByte;
|
|
72325
|
+
};
|
|
72326
|
+
const maskByteRange = (maskedBuffer, startByte, endByte) => {
|
|
72327
|
+
for (let byteIndex = startByte; byteIndex < endByte; byteIndex++) {
|
|
72328
|
+
const byte = maskedBuffer[byteIndex];
|
|
72329
|
+
if (byte !== 10 && byte !== 13) maskedBuffer[byteIndex] = 32;
|
|
72330
|
+
}
|
|
72331
|
+
};
|
|
72332
|
+
const readStartTagName = (sourceBuffer, tagStartByte) => {
|
|
72333
|
+
const firstNameByte = sourceBuffer[tagStartByte + 1];
|
|
72334
|
+
if (firstNameByte === void 0 || !/[A-Za-z]/.test(String.fromCharCode(firstNameByte))) return null;
|
|
72335
|
+
let nameEndByte = tagStartByte + 2;
|
|
72336
|
+
while (nameEndByte < sourceBuffer.length && /[A-Za-z0-9:-]/.test(String.fromCharCode(sourceBuffer[nameEndByte] ?? 32))) nameEndByte++;
|
|
72337
|
+
return sourceBuffer.subarray(tagStartByte + 1, nameEndByte).toString("ascii").toLowerCase();
|
|
72338
|
+
};
|
|
72339
|
+
const findTagEnd = (sourceBuffer, startByte) => {
|
|
72340
|
+
let quoteByte = null;
|
|
72341
|
+
for (let byteIndex = startByte; byteIndex < sourceBuffer.length; byteIndex++) {
|
|
72342
|
+
const byte = sourceBuffer[byteIndex];
|
|
72343
|
+
if (quoteByte !== null) {
|
|
72344
|
+
if (byte === quoteByte) quoteByte = null;
|
|
72345
|
+
continue;
|
|
72346
|
+
}
|
|
72347
|
+
if (byte === SINGLE_QUOTE_UTF8_BYTE || byte === DOUBLE_QUOTE_UTF8_BYTE) {
|
|
72348
|
+
quoteByte = byte;
|
|
72349
|
+
continue;
|
|
72350
|
+
}
|
|
72351
|
+
if (byte === TAG_CLOSE_UTF8_BYTE) return byteIndex;
|
|
72352
|
+
}
|
|
72353
|
+
return sourceBuffer.length;
|
|
72354
|
+
};
|
|
72355
|
+
const parseScriptAttributes = (sourceBuffer, attributesStartByte, tagEndByte) => {
|
|
72356
|
+
let byteIndex = attributesStartByte;
|
|
72357
|
+
let hasSource = false;
|
|
72358
|
+
let language = null;
|
|
72359
|
+
let scriptType = null;
|
|
72360
|
+
while (byteIndex < tagEndByte) {
|
|
72361
|
+
while (byteIndex < tagEndByte && (isHtmlWhitespace(sourceBuffer[byteIndex]) || sourceBuffer[byteIndex] === TAG_SELF_CLOSE_UTF8_BYTE)) byteIndex++;
|
|
72362
|
+
const attributeNameStartByte = byteIndex;
|
|
72363
|
+
while (byteIndex < tagEndByte && !isHtmlWhitespace(sourceBuffer[byteIndex]) && sourceBuffer[byteIndex] !== ATTRIBUTE_ASSIGNMENT_UTF8_BYTE && sourceBuffer[byteIndex] !== TAG_SELF_CLOSE_UTF8_BYTE) byteIndex++;
|
|
72364
|
+
const attributeName = sourceBuffer.subarray(attributeNameStartByte, byteIndex).toString("ascii").toLowerCase();
|
|
72365
|
+
while (byteIndex < tagEndByte && isHtmlWhitespace(sourceBuffer[byteIndex])) byteIndex++;
|
|
72366
|
+
let attributeValue = "";
|
|
72367
|
+
if (sourceBuffer[byteIndex] === ATTRIBUTE_ASSIGNMENT_UTF8_BYTE) {
|
|
72368
|
+
byteIndex++;
|
|
72369
|
+
while (byteIndex < tagEndByte && isHtmlWhitespace(sourceBuffer[byteIndex])) byteIndex++;
|
|
72370
|
+
const quoteByte = sourceBuffer[byteIndex];
|
|
72371
|
+
if (quoteByte === SINGLE_QUOTE_UTF8_BYTE || quoteByte === DOUBLE_QUOTE_UTF8_BYTE) {
|
|
72372
|
+
const valueStartByte = byteIndex + 1;
|
|
72373
|
+
byteIndex = valueStartByte;
|
|
72374
|
+
while (byteIndex < tagEndByte && sourceBuffer[byteIndex] !== quoteByte) byteIndex++;
|
|
72375
|
+
attributeValue = sourceBuffer.subarray(valueStartByte, byteIndex).toString("utf8");
|
|
72376
|
+
if (byteIndex < tagEndByte) byteIndex++;
|
|
72377
|
+
} else {
|
|
72378
|
+
const valueStartByte = byteIndex;
|
|
72379
|
+
while (byteIndex < tagEndByte && !isHtmlWhitespace(sourceBuffer[byteIndex]) && sourceBuffer[byteIndex] !== TAG_CLOSE_UTF8_BYTE) byteIndex++;
|
|
72380
|
+
attributeValue = sourceBuffer.subarray(valueStartByte, byteIndex).toString("utf8");
|
|
72381
|
+
}
|
|
72382
|
+
}
|
|
72383
|
+
if (attributeName === "src") hasSource = true;
|
|
72384
|
+
else if (attributeName === "type" && scriptType === null) scriptType = attributeValue;
|
|
72385
|
+
else if (attributeName === "language" && language === null) language = attributeValue;
|
|
72386
|
+
}
|
|
72387
|
+
return {
|
|
72388
|
+
hasSource,
|
|
72389
|
+
language,
|
|
72390
|
+
type: scriptType
|
|
72391
|
+
};
|
|
72392
|
+
};
|
|
72393
|
+
const isExecutableScript = (attributes) => {
|
|
72394
|
+
if (attributes.hasSource) return false;
|
|
72395
|
+
const type = attributes.type?.trim().toLowerCase() ?? "";
|
|
72396
|
+
if (type !== "") {
|
|
72397
|
+
const mimeType = type.split(";")[0]?.trim() ?? "";
|
|
72398
|
+
return mimeType === "module" || JAVASCRIPT_MIME_TYPES.has(mimeType);
|
|
72399
|
+
}
|
|
72400
|
+
const language = attributes.language?.trim().toLowerCase() ?? "";
|
|
72401
|
+
return language === "" || JAVASCRIPT_MIME_TYPES.has(`text/${language}`);
|
|
72402
|
+
};
|
|
72403
|
+
const findElementClose = (sourceBuffer, startByte, tagName) => {
|
|
72404
|
+
const closeTagStart = `</${tagName}`;
|
|
72405
|
+
for (let byteIndex = startByte; byteIndex < sourceBuffer.length; byteIndex++) if (sourceBuffer[byteIndex] === TAG_OPEN_UTF8_BYTE && matchesAsciiCaseInsensitive(sourceBuffer, byteIndex, closeTagStart) && isTagBoundary(sourceBuffer[byteIndex + closeTagStart.length])) return byteIndex;
|
|
72406
|
+
return sourceBuffer.length;
|
|
72407
|
+
};
|
|
72408
|
+
const prepareHtmlScriptSource = (sourceBuffer) => {
|
|
72409
|
+
const frontmatterEndByte = findFrontmatterEnd(sourceBuffer);
|
|
72410
|
+
let maskedBuffer = frontmatterEndByte > 0 ? Buffer.from(sourceBuffer) : null;
|
|
72411
|
+
if (maskedBuffer !== null) maskByteRange(maskedBuffer, 0, frontmatterEndByte);
|
|
72412
|
+
const executableScriptBodies = [];
|
|
72413
|
+
let byteIndex = frontmatterEndByte;
|
|
72414
|
+
let templateDepth = 0;
|
|
72415
|
+
while (byteIndex < sourceBuffer.length) {
|
|
72416
|
+
if (sourceBuffer[byteIndex] !== TAG_OPEN_UTF8_BYTE) {
|
|
72417
|
+
byteIndex++;
|
|
72418
|
+
continue;
|
|
72419
|
+
}
|
|
72420
|
+
if (matchesAsciiCaseInsensitive(sourceBuffer, byteIndex, COMMENT_OPEN)) {
|
|
72421
|
+
const commentEndByte = sourceBuffer.indexOf(COMMENT_CLOSE, byteIndex + 4);
|
|
72422
|
+
byteIndex = commentEndByte === -1 ? sourceBuffer.length : commentEndByte + 3;
|
|
72423
|
+
continue;
|
|
72424
|
+
}
|
|
72425
|
+
if (matchesAsciiCaseInsensitive(sourceBuffer, byteIndex, TEMPLATE_CLOSE) && isTagBoundary(sourceBuffer[byteIndex + TEMPLATE_CLOSE.length])) {
|
|
72426
|
+
const tagEndByte = findTagEnd(sourceBuffer, byteIndex + TEMPLATE_CLOSE.length);
|
|
72427
|
+
if (templateDepth > 0) templateDepth--;
|
|
72428
|
+
byteIndex = Math.min(tagEndByte + 1, sourceBuffer.length);
|
|
72429
|
+
continue;
|
|
72430
|
+
}
|
|
72431
|
+
if (!matchesAsciiCaseInsensitive(sourceBuffer, byteIndex, SCRIPT_OPEN) || !isTagBoundary(sourceBuffer[byteIndex + SCRIPT_OPEN.length])) {
|
|
72432
|
+
if (!isPotentialTagStart(sourceBuffer[byteIndex + 1])) {
|
|
72433
|
+
byteIndex++;
|
|
72434
|
+
continue;
|
|
72435
|
+
}
|
|
72436
|
+
const tagEndByte = findTagEnd(sourceBuffer, byteIndex + 1);
|
|
72437
|
+
const tagName = readStartTagName(sourceBuffer, byteIndex);
|
|
72438
|
+
if (tagName === PLAINTEXT_TAG_NAME) break;
|
|
72439
|
+
if (tagName === TEMPLATE_TAG_NAME) templateDepth++;
|
|
72440
|
+
if (tagName !== null && RAW_TEXT_TAG_NAMES.has(tagName)) {
|
|
72441
|
+
const closeTagStartByte = findElementClose(sourceBuffer, tagEndByte + 1, tagName);
|
|
72442
|
+
if (closeTagStartByte === sourceBuffer.length) break;
|
|
72443
|
+
const closeTagEndByte = findTagEnd(sourceBuffer, closeTagStartByte + tagName.length + 2);
|
|
72444
|
+
byteIndex = Math.min(closeTagEndByte + 1, sourceBuffer.length);
|
|
72445
|
+
continue;
|
|
72446
|
+
}
|
|
72447
|
+
byteIndex = Math.min(tagEndByte + 1, sourceBuffer.length);
|
|
72448
|
+
continue;
|
|
72449
|
+
}
|
|
72450
|
+
const tagEndByte = findTagEnd(sourceBuffer, byteIndex + SCRIPT_OPEN.length);
|
|
72451
|
+
if (tagEndByte === sourceBuffer.length) break;
|
|
72452
|
+
const bodyStartByte = tagEndByte + 1;
|
|
72453
|
+
const bodyEndByte = findElementClose(sourceBuffer, bodyStartByte, SCRIPT_TAG_NAME);
|
|
72454
|
+
const attributes = parseScriptAttributes(sourceBuffer, byteIndex + SCRIPT_OPEN.length, tagEndByte);
|
|
72455
|
+
if (attributes.hasSource || templateDepth > 0) {
|
|
72456
|
+
maskedBuffer ??= Buffer.from(sourceBuffer);
|
|
72457
|
+
maskByteRange(maskedBuffer, bodyStartByte, bodyEndByte);
|
|
72458
|
+
} else if (isExecutableScript(attributes)) executableScriptBodies.push(sourceBuffer.subarray(bodyStartByte, bodyEndByte));
|
|
72459
|
+
if (bodyEndByte === sourceBuffer.length) break;
|
|
72460
|
+
const closeTagEndByte = findTagEnd(sourceBuffer, bodyEndByte + SCRIPT_CLOSE.length);
|
|
72461
|
+
byteIndex = Math.min(closeTagEndByte + 1, sourceBuffer.length);
|
|
72462
|
+
}
|
|
72463
|
+
return {
|
|
72464
|
+
executableScriptBodies,
|
|
72465
|
+
lintBuffer: maskedBuffer ?? sourceBuffer
|
|
72466
|
+
};
|
|
72467
|
+
};
|
|
72468
|
+
const prepareHtmlLintSources = (rootDirectory, temporaryDirectory, candidateFiles) => {
|
|
72469
|
+
const lintFiles = [];
|
|
72470
|
+
const sourcePathByLintPath = /* @__PURE__ */ new Map();
|
|
72471
|
+
const sizeByLintPath = /* @__PURE__ */ new Map();
|
|
72472
|
+
const htmlSourcesDirectory = Path.join(temporaryDirectory, "html-sources");
|
|
72473
|
+
let htmlFileIndex = 0;
|
|
72474
|
+
let hasThreeModuleImport = false;
|
|
72475
|
+
for (const candidateFile of candidateFiles) {
|
|
72476
|
+
if (!HTML_FILE_PATTERN.test(candidateFile)) {
|
|
72477
|
+
lintFiles.push(candidateFile);
|
|
72478
|
+
continue;
|
|
72479
|
+
}
|
|
72480
|
+
const absoluteSourcePath = Path.isAbsolute(candidateFile) ? candidateFile : Path.resolve(rootDirectory, candidateFile);
|
|
72481
|
+
const sourceBuffer = NFS.readFileSync(absoluteSourcePath);
|
|
72482
|
+
const { executableScriptBodies, lintBuffer } = prepareHtmlScriptSource(sourceBuffer);
|
|
72483
|
+
if (htmlFileIndex === 0) NFS.mkdirSync(htmlSourcesDirectory, { recursive: true });
|
|
72484
|
+
const lintPath = Path.join(htmlSourcesDirectory, `${htmlFileIndex}.astro`);
|
|
72485
|
+
NFS.writeFileSync(lintPath, lintBuffer);
|
|
72486
|
+
lintFiles.push(lintPath);
|
|
72487
|
+
sourcePathByLintPath.set(Path.resolve(lintPath), candidateFile);
|
|
72488
|
+
sizeByLintPath.set(lintPath, sourceBuffer.length);
|
|
72489
|
+
hasThreeModuleImport ||= executableScriptBodies.some((scriptBody) => containsThreeModuleImport(scriptBody.toString("utf8")));
|
|
72490
|
+
htmlFileIndex++;
|
|
72491
|
+
}
|
|
72492
|
+
return {
|
|
72493
|
+
lintFiles,
|
|
72494
|
+
sourcePathByLintPath,
|
|
72495
|
+
sizeByLintPath,
|
|
72496
|
+
hasThreeModuleImport
|
|
72497
|
+
};
|
|
72498
|
+
};
|
|
71831
72499
|
/**
|
|
71832
72500
|
* Atomically (re)writes the generated oxlintrc.json. Used twice in
|
|
71833
72501
|
* the runner: once for the primary scan, once for the
|
|
@@ -71988,6 +72656,8 @@ const reactHooksJsPluginDropNote = (error) => {
|
|
|
71988
72656
|
const runOxlint = async (options) => {
|
|
71989
72657
|
const { rootDirectory, project, includePaths, nodeBinaryPath = process.execPath, customRulesOnly = false, respectInlineDisables = true, adoptExistingLintConfig = true, ignoredTags = /* @__PURE__ */ new Set(), includedTags = /* @__PURE__ */ new Set(), includeTagDefaults = false, userConfig, configSourceDirectory = rootDirectory, onPartialFailure, onFileCoverage, perFileLintCacheEnabled = false, sidecarLintCacheEnabled = false, onCacheStats, onSidecarStats, spawnTimeoutMs, outputMaxBytes, lintBatchOrdering = "cost" } = options;
|
|
71990
72658
|
const serverAuthFunctionNames = Array.isArray(userConfig?.serverAuthFunctionNames) ? userConfig.serverAuthFunctionNames.filter((entry) => typeof entry === "string" && entry.length > 0) : void 0;
|
|
72659
|
+
const runtimeGlobals = Array.isArray(userConfig?.runtimeGlobals) ? userConfig.runtimeGlobals.filter((entry) => typeof entry === "string" && entry.length > 0) : void 0;
|
|
72660
|
+
let unpluginAutoImportGlobalScopes = [];
|
|
71991
72661
|
const severityControls = buildRuleSeverityControls(userConfig);
|
|
71992
72662
|
validateRuleRegistration();
|
|
71993
72663
|
resetManifestCaches();
|
|
@@ -72001,21 +72671,6 @@ const runOxlint = async (options) => {
|
|
|
72001
72671
|
const pluginPath = resolvePluginPath();
|
|
72002
72672
|
const extendsPaths = (adoptExistingLintConfig && !customRulesOnly ? detectUserLintConfigPaths(rootDirectory) : []).filter(canOxlintExtendConfig);
|
|
72003
72673
|
const userPlugins = includedTags.size > 0 ? [] : resolveUserPlugins(userConfig?.plugins, configSourceDirectory);
|
|
72004
|
-
const buildConfig = (overrides) => createOxlintConfig({
|
|
72005
|
-
pluginPath,
|
|
72006
|
-
project,
|
|
72007
|
-
customRulesOnly,
|
|
72008
|
-
extendsPaths: overrides.extendsPaths,
|
|
72009
|
-
ignoredTags,
|
|
72010
|
-
includedTags,
|
|
72011
|
-
includeTagDefaults,
|
|
72012
|
-
serverAuthFunctionNames,
|
|
72013
|
-
severityControls,
|
|
72014
|
-
userPlugins,
|
|
72015
|
-
disableReactHooksJsPlugin: overrides.disableReactHooksJsPlugin,
|
|
72016
|
-
ruleSelection: overrides.ruleSelection,
|
|
72017
|
-
sidecarRuleIdFilter: overrides.sidecarRuleIdFilter
|
|
72018
|
-
});
|
|
72019
72674
|
const restoreDisableDirectives = respectInlineDisables ? () => {} : await neutralizeDisableDirectives(rootDirectory, includePaths);
|
|
72020
72675
|
const configDirectory = NFS.mkdtempSync(Path.join(os.tmpdir(), "react-doctor-oxlintrc-"));
|
|
72021
72676
|
const configPath = Path.join(configDirectory, "oxlintrc.json");
|
|
@@ -72051,7 +72706,36 @@ const runOxlint = async (options) => {
|
|
|
72051
72706
|
await yieldToEventLoop();
|
|
72052
72707
|
const sizedScanFiles = includePaths === void 0 ? listSourceFilesWithSize(rootDirectory) : null;
|
|
72053
72708
|
const candidateFiles = includePaths !== void 0 ? includePaths : (sizedScanFiles ?? []).map((entry) => entry.path);
|
|
72709
|
+
unpluginAutoImportGlobalScopes = collectUnpluginAutoImportGlobalScopes({
|
|
72710
|
+
rootDirectory,
|
|
72711
|
+
candidateFiles
|
|
72712
|
+
});
|
|
72713
|
+
const preparedHtmlSources = prepareHtmlLintSources(rootDirectory, configDirectory, candidateFiles);
|
|
72714
|
+
const lintFiles = preparedHtmlSources.lintFiles;
|
|
72715
|
+
const hasHtmlFiles = preparedHtmlSources.sourcePathByLintPath.size > 0;
|
|
72716
|
+
const lintProject = !project.hasThree && preparedHtmlSources.hasThreeModuleImport ? {
|
|
72717
|
+
...project,
|
|
72718
|
+
hasThree: true
|
|
72719
|
+
} : project;
|
|
72720
|
+
const buildConfig = (overrides) => createOxlintConfig({
|
|
72721
|
+
pluginPath,
|
|
72722
|
+
project: lintProject,
|
|
72723
|
+
customRulesOnly,
|
|
72724
|
+
extendsPaths: overrides.extendsPaths,
|
|
72725
|
+
ignoredTags,
|
|
72726
|
+
includedTags,
|
|
72727
|
+
includeTagDefaults,
|
|
72728
|
+
runtimeGlobals,
|
|
72729
|
+
unpluginAutoImportGlobalScopes,
|
|
72730
|
+
serverAuthFunctionNames,
|
|
72731
|
+
severityControls,
|
|
72732
|
+
userPlugins,
|
|
72733
|
+
disableReactHooksJsPlugin: overrides.disableReactHooksJsPlugin,
|
|
72734
|
+
ruleSelection: overrides.ruleSelection,
|
|
72735
|
+
sidecarRuleIdFilter: overrides.sidecarRuleIdFilter
|
|
72736
|
+
});
|
|
72054
72737
|
const sizeByFile = sizedScanFiles !== null && lintBatchOrdering === "cost" ? new Map(sizedScanFiles.map((entry) => [entry.path, entry.sizeBytes])) : null;
|
|
72738
|
+
if (sizeByFile !== null) for (const [lintPath, sizeBytes] of preparedHtmlSources.sizeByLintPath) sizeByFile.set(lintPath, sizeBytes);
|
|
72055
72739
|
const buildFileBatches = (passBaseArgs, passFiles) => sizeByFile !== null ? planLintBatches({
|
|
72056
72740
|
baseArgs: passBaseArgs,
|
|
72057
72741
|
files: passFiles,
|
|
@@ -72080,7 +72764,8 @@ const runOxlint = async (options) => {
|
|
|
72080
72764
|
fileBatches: passFileBatches,
|
|
72081
72765
|
rootDirectory,
|
|
72082
72766
|
nodeBinaryPath,
|
|
72083
|
-
project,
|
|
72767
|
+
project: lintProject,
|
|
72768
|
+
sourcePathByLintPath: preparedHtmlSources.sourcePathByLintPath,
|
|
72084
72769
|
onPartialFailure: reportPartialFailure,
|
|
72085
72770
|
onAnalyzedFiles: (filePaths) => {
|
|
72086
72771
|
analyzedFiles = filePaths;
|
|
@@ -72115,7 +72800,7 @@ const runOxlint = async (options) => {
|
|
|
72115
72800
|
};
|
|
72116
72801
|
}
|
|
72117
72802
|
};
|
|
72118
|
-
if (perFileLintCacheEnabled && !project.hasReactCompiler && project.hasReactCompilerLintPlugin !== true && extendsPaths.length === 0 && userPlugins.length === 0) {
|
|
72803
|
+
if (perFileLintCacheEnabled && !project.hasReactCompiler && project.hasReactCompilerLintPlugin !== true && extendsPaths.length === 0 && userPlugins.length === 0 && !hasHtmlFiles) {
|
|
72119
72804
|
const rulesetHash = computeRulesetHash({
|
|
72120
72805
|
config: buildConfig({
|
|
72121
72806
|
extendsPaths: [],
|
|
@@ -72273,14 +72958,15 @@ const runOxlint = async (options) => {
|
|
|
72273
72958
|
]);
|
|
72274
72959
|
}
|
|
72275
72960
|
const baseArgs = makeBaseArgs(configPath);
|
|
72276
|
-
const fileBatches = buildFileBatches(baseArgs,
|
|
72961
|
+
const fileBatches = buildFileBatches(baseArgs, lintFiles);
|
|
72277
72962
|
let analyzedFiles = [];
|
|
72278
72963
|
const runBatches = () => spawnLintBatches({
|
|
72279
72964
|
baseArgs,
|
|
72280
72965
|
fileBatches,
|
|
72281
72966
|
rootDirectory,
|
|
72282
72967
|
nodeBinaryPath,
|
|
72283
|
-
project,
|
|
72968
|
+
project: lintProject,
|
|
72969
|
+
sourcePathByLintPath: preparedHtmlSources.sourcePathByLintPath,
|
|
72284
72970
|
onPartialFailure,
|
|
72285
72971
|
onAnalyzedFiles: (filePaths) => {
|
|
72286
72972
|
analyzedFiles = filePaths;
|
|
@@ -74202,4 +74888,4 @@ const toJsonReport = (result, options) => buildJsonReport({
|
|
|
74202
74888
|
export { AmbiguousProjectError, NoReactDependencyError, NotADirectoryError, PackageJsonNotFoundError, ProjectNotFoundError, ReactDoctorError, buildJsonReport, buildJsonReportError, clearCaches, defineConfig, diagnose, filterSourceFiles, getDiffInfo, hasReactRuntime, isProjectDiscoveryError, isReactDoctorError, summarizeDiagnostics, toJsonReport };
|
|
74203
74889
|
|
|
74204
74890
|
//# sourceMappingURL=index.js.map
|
|
74205
|
-
//# debugId=
|
|
74891
|
+
//# debugId=afe9afbe-4d17-5f2a-8b4f-9b49703c42be
|