react-doctor 0.9.1-dev.5d2f66d → 0.9.1-dev.7ee59d3
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 +653 -60
- package/dist/index.d.ts +2 -2
- package/dist/index.js +647 -55
- package/dist/lsp.js +649 -56
- package/package.json +2 -2
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]="5ad39650-1163-5117-aad5-472963ee3867")}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";
|
|
@@ -61448,7 +61448,8 @@ var AmbiguousProjectError = class extends Error {
|
|
|
61448
61448
|
}
|
|
61449
61449
|
};
|
|
61450
61450
|
const isProjectDiscoveryError = (value) => value instanceof ProjectNotFoundError || value instanceof NoReactDependencyError || value instanceof PackageJsonNotFoundError || value instanceof NotADirectoryError || value instanceof AmbiguousProjectError;
|
|
61451
|
-
const
|
|
61451
|
+
const HTML_FILE_PATTERN = /\.html$/i;
|
|
61452
|
+
const SOURCE_FILE_PATTERN = /\.(?:tsx?|jsx?|mts|mjs|[hH][tT][mM][lL])$/;
|
|
61452
61453
|
const GENERATED_BUNDLE_FILE_PATTERN = /\.(iife|umd|global|min)\.m?js$/i;
|
|
61453
61454
|
const GENERATED_SOURCE_DIRECTORY_PATTERN = /(?:^|\/)__generated__\//;
|
|
61454
61455
|
const MINIFIED_SNIFF_BYTES = 65536;
|
|
@@ -62288,7 +62289,7 @@ const parseConfigSourceFile = (filePath, content) => filePath.endsWith(".json")
|
|
|
62288
62289
|
const getStaticPropertyName$2 = (propertyName) => ts.isIdentifier(propertyName) || ts.isStringLiteralLike(propertyName) ? propertyName.text : ts.isComputedPropertyName(propertyName) && ts.isStringLiteralLike(propertyName.expression) ? propertyName.expression.text : null;
|
|
62289
62290
|
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
62291
|
const hasExportModifier = (node) => ts.canHaveModifiers(node) && Boolean(ts.getModifiers(node)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword));
|
|
62291
|
-
const getRequireModuleSpecifier = (expression) => {
|
|
62292
|
+
const getRequireModuleSpecifier$1 = (expression) => {
|
|
62292
62293
|
if (!ts.isCallExpression(expression) || !ts.isIdentifier(expression.expression) || expression.expression.text !== "require" || expression.arguments.length !== 1) return null;
|
|
62293
62294
|
const moduleSpecifier = expression.arguments[0];
|
|
62294
62295
|
return moduleSpecifier && ts.isStringLiteralLike(moduleSpecifier) ? moduleSpecifier.text : null;
|
|
@@ -62301,7 +62302,7 @@ const hasTopLevelValueBinding = (sourceFile, bindingName) => sourceFile.statemen
|
|
|
62301
62302
|
const namedBindings = importClause?.namedBindings;
|
|
62302
62303
|
return namedBindings ? ts.isNamespaceImport(namedBindings) ? namedBindings.name.text === bindingName : namedBindings.elements.some((element) => element.name.text === bindingName) : false;
|
|
62303
62304
|
}
|
|
62304
|
-
if (ts.isVariableStatement(statement)) return statement.declarationList.declarations.some((declaration) =>
|
|
62305
|
+
if (ts.isVariableStatement(statement)) return statement.declarationList.declarations.some((declaration) => bindingNameContainsIdentifier(declaration.name, bindingName));
|
|
62305
62306
|
return (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) && statement.name?.text === bindingName;
|
|
62306
62307
|
});
|
|
62307
62308
|
const getImportBinding = (sourceFile, bindingName) => {
|
|
@@ -62332,21 +62333,21 @@ const getImportBinding = (sourceFile, bindingName) => {
|
|
|
62332
62333
|
for (const declaration of statement.declarationList.declarations) {
|
|
62333
62334
|
if (!declaration.initializer) continue;
|
|
62334
62335
|
if (ts.isIdentifier(declaration.name) && declaration.name.text === bindingName) {
|
|
62335
|
-
const directModuleSpecifier = getRequireModuleSpecifier(declaration.initializer);
|
|
62336
|
+
const directModuleSpecifier = getRequireModuleSpecifier$1(declaration.initializer);
|
|
62336
62337
|
if (directModuleSpecifier) return {
|
|
62337
62338
|
moduleSpecifier: directModuleSpecifier,
|
|
62338
62339
|
exportName: "default",
|
|
62339
62340
|
isNamespace: true
|
|
62340
62341
|
};
|
|
62341
|
-
if (ts.isPropertyAccessExpression(declaration.initializer) && getRequireModuleSpecifier(declaration.initializer.expression) !== null) return {
|
|
62342
|
-
moduleSpecifier: getRequireModuleSpecifier(declaration.initializer.expression) ?? "",
|
|
62342
|
+
if (ts.isPropertyAccessExpression(declaration.initializer) && getRequireModuleSpecifier$1(declaration.initializer.expression) !== null) return {
|
|
62343
|
+
moduleSpecifier: getRequireModuleSpecifier$1(declaration.initializer.expression) ?? "",
|
|
62343
62344
|
exportName: declaration.initializer.name.text,
|
|
62344
62345
|
isNamespace: false
|
|
62345
62346
|
};
|
|
62346
62347
|
}
|
|
62347
62348
|
if (!ts.isObjectBindingPattern(declaration.name)) continue;
|
|
62348
62349
|
const bindingElement = declaration.name.elements.find((element) => ts.isIdentifier(element.name) && element.name.text === bindingName);
|
|
62349
|
-
const moduleSpecifier = getRequireModuleSpecifier(declaration.initializer);
|
|
62350
|
+
const moduleSpecifier = getRequireModuleSpecifier$1(declaration.initializer);
|
|
62350
62351
|
if (bindingElement && moduleSpecifier) return {
|
|
62351
62352
|
moduleSpecifier,
|
|
62352
62353
|
exportName: bindingElement.propertyName ? getStaticPropertyName$2(bindingElement.propertyName) ?? bindingElement.propertyName.getText(sourceFile) : bindingElement.name.getText(sourceFile),
|
|
@@ -62402,6 +62403,48 @@ const getScopedConfigBinding = (identifier) => {
|
|
|
62402
62403
|
};
|
|
62403
62404
|
};
|
|
62404
62405
|
const isCompilerTransformModule = (moduleSpecifier, exportName) => moduleSpecifier === "babel-plugin-react-compiler" && exportName === "default" || moduleSpecifier === "@vitejs/plugin-react" && exportName === "reactCompilerPreset";
|
|
62406
|
+
const NODE_MODULE_SPECIFIERS = new Set(["module", "node:module"]);
|
|
62407
|
+
const isConstantVariableInitializer = (node) => ts.isExpression(node) && ts.isVariableDeclaration(node.parent) && ts.isVariableDeclarationList(node.parent.parent) && Boolean(node.parent.parent.flags & ts.NodeFlags.Const);
|
|
62408
|
+
const isNodeCreateRequireCall = (node, analysis) => {
|
|
62409
|
+
if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isTypeAssertionExpression(node) || ts.isSatisfiesExpression(node) || ts.isNonNullExpression(node) || ts.isAwaitExpression(node)) return isNodeCreateRequireCall(node.expression, analysis);
|
|
62410
|
+
if (!ts.isCallExpression(node)) return false;
|
|
62411
|
+
const target = node.expression;
|
|
62412
|
+
if (ts.isIdentifier(target)) {
|
|
62413
|
+
if (analysis.localBindings.has(target.text) || getScopedConfigBinding(target).wasFound) return false;
|
|
62414
|
+
const importBinding = getImportBinding(analysis.sourceFile, target.text);
|
|
62415
|
+
return Boolean(importBinding && NODE_MODULE_SPECIFIERS.has(importBinding.moduleSpecifier) && importBinding.exportName === "createRequire");
|
|
62416
|
+
}
|
|
62417
|
+
if (!ts.isPropertyAccessExpression(target) && !ts.isElementAccessExpression(target)) return false;
|
|
62418
|
+
if ((ts.isPropertyAccessExpression(target) ? target.name.text : target.argumentExpression && ts.isStringLiteralLike(target.argumentExpression) ? target.argumentExpression.text : null) !== "createRequire") return false;
|
|
62419
|
+
const createRequireReceiver = target.expression;
|
|
62420
|
+
if (ts.isCallExpression(createRequireReceiver)) {
|
|
62421
|
+
const requiredModuleSpecifier = getRequireModuleSpecifier$1(createRequireReceiver);
|
|
62422
|
+
if (requiredModuleSpecifier === null || !NODE_MODULE_SPECIFIERS.has(requiredModuleSpecifier) || !ts.isIdentifier(createRequireReceiver.expression)) return false;
|
|
62423
|
+
const requireIdentifier = createRequireReceiver.expression;
|
|
62424
|
+
return !analysis.localBindings.has(requireIdentifier.text) && !getScopedConfigBinding(requireIdentifier).wasFound && !hasTopLevelValueBinding(analysis.sourceFile, requireIdentifier.text);
|
|
62425
|
+
}
|
|
62426
|
+
if (!ts.isIdentifier(createRequireReceiver)) return false;
|
|
62427
|
+
if (analysis.localBindings.has(createRequireReceiver.text) || getScopedConfigBinding(createRequireReceiver).wasFound) return false;
|
|
62428
|
+
const importBinding = getImportBinding(analysis.sourceFile, createRequireReceiver.text);
|
|
62429
|
+
return Boolean(importBinding?.isNamespace && NODE_MODULE_SPECIFIERS.has(importBinding.moduleSpecifier));
|
|
62430
|
+
};
|
|
62431
|
+
const getNodeRequireResolveModuleSpecifier = (callExpression, analysis) => {
|
|
62432
|
+
const [moduleSpecifierNode] = callExpression.arguments;
|
|
62433
|
+
if (!moduleSpecifierNode || !ts.isStringLiteralLike(moduleSpecifierNode)) return null;
|
|
62434
|
+
const target = callExpression.expression;
|
|
62435
|
+
if (!ts.isPropertyAccessExpression(target) && !ts.isElementAccessExpression(target)) return null;
|
|
62436
|
+
if ((ts.isPropertyAccessExpression(target) ? target.name.text : target.argumentExpression && ts.isStringLiteralLike(target.argumentExpression) ? target.argumentExpression.text : null) !== "resolve") return null;
|
|
62437
|
+
if (isNodeCreateRequireCall(target.expression, analysis)) return moduleSpecifierNode.text;
|
|
62438
|
+
if (!ts.isIdentifier(target.expression)) return null;
|
|
62439
|
+
const resolverIdentifier = target.expression;
|
|
62440
|
+
if (analysis.localBindings.has(resolverIdentifier.text)) return null;
|
|
62441
|
+
const scopedBinding = getScopedConfigBinding(resolverIdentifier);
|
|
62442
|
+
const topLevelBinding = scopedBinding.wasFound ? null : getTopLevelBinding(analysis.sourceFile, resolverIdentifier.text);
|
|
62443
|
+
const resolverInitializer = scopedBinding.wasFound ? scopedBinding.initializer : topLevelBinding;
|
|
62444
|
+
if (resolverInitializer === null && !scopedBinding.wasFound && resolverIdentifier.text === "require" && !hasTopLevelValueBinding(analysis.sourceFile, resolverIdentifier.text) && getImportBinding(analysis.sourceFile, resolverIdentifier.text) === null) return moduleSpecifierNode.text;
|
|
62445
|
+
if (!resolverInitializer || !isConstantVariableInitializer(resolverInitializer) || !isNodeCreateRequireCall(resolverInitializer, analysis)) return null;
|
|
62446
|
+
return moduleSpecifierNode.text;
|
|
62447
|
+
};
|
|
62405
62448
|
const getAssignedPropertyInitializer = (identifier, propertyName) => {
|
|
62406
62449
|
let bindingScope = null;
|
|
62407
62450
|
let currentNode = identifier;
|
|
@@ -62717,7 +62760,7 @@ const analyzeConfigCallTarget = (callExpression, analysis, allowCompilerTransfor
|
|
|
62717
62760
|
if (!ts.isPropertyAccessExpression(target) && !ts.isElementAccessExpression(target)) return null;
|
|
62718
62761
|
const propertyName = ts.isPropertyAccessExpression(target) ? target.name.text : target.argumentExpression && ts.isStringLiteralLike(target.argumentExpression) ? target.argumentExpression.text : null;
|
|
62719
62762
|
if (propertyName === null) return null;
|
|
62720
|
-
const requiredModuleSpecifier = getRequireModuleSpecifier(target.expression);
|
|
62763
|
+
const requiredModuleSpecifier = getRequireModuleSpecifier$1(target.expression);
|
|
62721
62764
|
if (requiredModuleSpecifier !== null) {
|
|
62722
62765
|
if (ts.isCallExpression(target.expression) && ts.isIdentifier(target.expression.expression) && (getScopedConfigBinding(target.expression.expression).wasFound || hasTopLevelValueBinding(analysis.sourceFile, "require"))) return false;
|
|
62723
62766
|
if (!requiredModuleSpecifier.startsWith(".")) return null;
|
|
@@ -62777,9 +62820,11 @@ const analyzeConfigNode = (node, analysis, allowCompilerTransform, isCompilerTra
|
|
|
62777
62820
|
});
|
|
62778
62821
|
}
|
|
62779
62822
|
if (ts.isCallExpression(node)) {
|
|
62823
|
+
const resolvedModuleSpecifier = getNodeRequireResolveModuleSpecifier(node, analysis);
|
|
62824
|
+
if (resolvedModuleSpecifier !== null) return allowCompilerTransform && isCompilerTransformModule(resolvedModuleSpecifier, "default");
|
|
62780
62825
|
const callTargetResult = analyzeConfigCallTarget(node, analysis, allowCompilerTransform);
|
|
62781
62826
|
if (callTargetResult !== null) return callTargetResult;
|
|
62782
|
-
const directModuleSpecifier = getRequireModuleSpecifier(node);
|
|
62827
|
+
const directModuleSpecifier = getRequireModuleSpecifier$1(node);
|
|
62783
62828
|
const isRequireShadowed = analysis.localBindings.has("require") || ts.isIdentifier(node.expression) && getScopedConfigBinding(node.expression).wasFound || hasTopLevelValueBinding(analysis.sourceFile, "require");
|
|
62784
62829
|
if (directModuleSpecifier && isRequireShadowed) return analyzeConfigNode(node.expression, analysis, allowCompilerTransform);
|
|
62785
62830
|
if (directModuleSpecifier && !isRequireShadowed) {
|
|
@@ -62801,7 +62846,7 @@ const analyzeConfigNode = (node, analysis, allowCompilerTransform, isCompilerTra
|
|
|
62801
62846
|
return analyzeConfigNode(node.expression, analysis, allowCompilerTransform) || node.arguments.some((argument) => analyzeConfigNode(argument, analysis, false));
|
|
62802
62847
|
}
|
|
62803
62848
|
if (ts.isPropertyAccessExpression(node)) {
|
|
62804
|
-
const requiredModuleSpecifier = getRequireModuleSpecifier(node.expression);
|
|
62849
|
+
const requiredModuleSpecifier = getRequireModuleSpecifier$1(node.expression);
|
|
62805
62850
|
if (requiredModuleSpecifier) {
|
|
62806
62851
|
if (ts.isCallExpression(node.expression) && ts.isIdentifier(node.expression.expression) && (getScopedConfigBinding(node.expression.expression).wasFound || hasTopLevelValueBinding(analysis.sourceFile, "require"))) return false;
|
|
62807
62852
|
if (requiredModuleSpecifier.startsWith(".")) {
|
|
@@ -66138,7 +66183,7 @@ const warn = (message) => {
|
|
|
66138
66183
|
runSync(warn$1(message));
|
|
66139
66184
|
};
|
|
66140
66185
|
const CONFIG_BASENAME = "doctor.config";
|
|
66141
|
-
const CONFIG_EXTENSIONS = [
|
|
66186
|
+
const CONFIG_EXTENSIONS$1 = [
|
|
66142
66187
|
"ts",
|
|
66143
66188
|
"mts",
|
|
66144
66189
|
"cts",
|
|
@@ -66242,7 +66287,7 @@ const loadLegacyConfig = (directory) => {
|
|
|
66242
66287
|
};
|
|
66243
66288
|
const loadConfigFromDirectory = async (directory) => {
|
|
66244
66289
|
let sawBrokenConfigFile = false;
|
|
66245
|
-
for (const extension of CONFIG_EXTENSIONS) {
|
|
66290
|
+
for (const extension of CONFIG_EXTENSIONS$1) {
|
|
66246
66291
|
const filePath = Path.join(directory, `${CONFIG_BASENAME}.${extension}`);
|
|
66247
66292
|
if (!isFile(filePath)) continue;
|
|
66248
66293
|
const isDataFile = DATA_CONFIG_EXTENSIONS.has(extension);
|
|
@@ -70049,7 +70094,11 @@ const neutralizeDisableDirectives = async (rootDirectory, includePaths) => {
|
|
|
70049
70094
|
const ROOT_DIRECTORY_PLACEHOLDER = "<root>";
|
|
70050
70095
|
const normalizeConfigForHash = (config) => {
|
|
70051
70096
|
const clone = JSON.parse(JSON.stringify(config));
|
|
70052
|
-
if (clone?.settings?.["react-doctor"])
|
|
70097
|
+
if (clone?.settings?.["react-doctor"]) {
|
|
70098
|
+
const reactDoctorSettings = clone.settings["react-doctor"];
|
|
70099
|
+
reactDoctorSettings.rootDirectory = ROOT_DIRECTORY_PLACEHOLDER;
|
|
70100
|
+
if (Array.isArray(reactDoctorSettings.unpluginAutoImportRootDirectories)) reactDoctorSettings.unpluginAutoImportRootDirectories = [ROOT_DIRECTORY_PLACEHOLDER];
|
|
70101
|
+
}
|
|
70053
70102
|
if (Array.isArray(clone?.jsPlugins)) clone.jsPlugins = clone.jsPlugins.map((_, index) => `<plugin:${index}>`);
|
|
70054
70103
|
return clone;
|
|
70055
70104
|
};
|
|
@@ -70208,13 +70257,14 @@ const buildUserPluginRules = (userPlugin, severityControls) => {
|
|
|
70208
70257
|
}
|
|
70209
70258
|
return enabled;
|
|
70210
70259
|
};
|
|
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 }) => {
|
|
70260
|
+
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
70261
|
const hasIncludedTags = includedTags.size > 0;
|
|
70213
70262
|
const reactHooksJsPlugin = disableReactHooksJsPlugin || ruleSelection === "sidecar" || hasIncludedTags ? null : resolveReactHooksJsPlugin(project.hasReactCompiler || project.hasReactCompilerLintPlugin === true, customRulesOnly);
|
|
70214
70263
|
const reactCompilerRules = reactHooksJsPlugin ? applyRuleSeverityControls(filterRulesToAvailable(REACT_COMPILER_RULES, "react-hooks-js", reactHooksJsPlugin.availableRuleNames), severityControls) : {};
|
|
70215
70264
|
const jsPlugins = [];
|
|
70216
70265
|
if (reactHooksJsPlugin) jsPlugins.push(reactHooksJsPlugin.entry);
|
|
70217
70266
|
const capabilities = getCapabilities(project);
|
|
70267
|
+
const settingsRootDirectory = resolveSettingsRootDirectory(project.rootDirectory);
|
|
70218
70268
|
const enabledReactDoctorRules = {};
|
|
70219
70269
|
for (const registryEntry of REACT_DOCTOR_RULES) {
|
|
70220
70270
|
const rule = reactDoctorPlugin.rules[registryEntry.id];
|
|
@@ -70260,8 +70310,16 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
|
|
|
70260
70310
|
jsPlugins: [...jsPlugins, pluginPath],
|
|
70261
70311
|
settings: { "react-doctor": {
|
|
70262
70312
|
framework: project.framework,
|
|
70263
|
-
rootDirectory:
|
|
70313
|
+
rootDirectory: settingsRootDirectory,
|
|
70264
70314
|
capabilities: [...capabilities].sort(),
|
|
70315
|
+
...runtimeGlobals && runtimeGlobals.length > 0 ? { runtimeGlobals: [...runtimeGlobals] } : {},
|
|
70316
|
+
...unpluginAutoImportGlobalScopes && unpluginAutoImportGlobalScopes.length > 0 ? {
|
|
70317
|
+
unpluginAutoImportRootDirectories: [...new Set([settingsRootDirectory, project.rootDirectory])],
|
|
70318
|
+
unpluginAutoImportGlobalScopes: unpluginAutoImportGlobalScopes.map((scope) => ({
|
|
70319
|
+
directory: scope.directory,
|
|
70320
|
+
names: [...scope.names]
|
|
70321
|
+
}))
|
|
70322
|
+
} : {},
|
|
70265
70323
|
...project.shopifyFlashListMajorVersion !== null ? { shopifyFlashListMajorVersion: project.shopifyFlashListMajorVersion } : {},
|
|
70266
70324
|
...serverAuthFunctionNames && serverAuthFunctionNames.length > 0 ? { serverAuthFunctionNames: [...serverAuthFunctionNames] } : {}
|
|
70267
70325
|
} },
|
|
@@ -70272,6 +70330,245 @@ const createOxlintConfig = ({ pluginPath, project, customRulesOnly = false, exte
|
|
|
70272
70330
|
}
|
|
70273
70331
|
};
|
|
70274
70332
|
};
|
|
70333
|
+
const AUTO_IMPORT_ADAPTER_PATTERN = /^unplugin-auto-import\/(?:astro|esbuild|rollup|rolldown|rspack|vite|webpack)$/;
|
|
70334
|
+
const CONFIG_BASENAMES = [
|
|
70335
|
+
"astro.config",
|
|
70336
|
+
"esbuild.config",
|
|
70337
|
+
"rollup.config",
|
|
70338
|
+
"rolldown.config",
|
|
70339
|
+
"rspack.config",
|
|
70340
|
+
"vite.config",
|
|
70341
|
+
"webpack.config"
|
|
70342
|
+
];
|
|
70343
|
+
const CONFIG_EXTENSIONS = [
|
|
70344
|
+
".cjs",
|
|
70345
|
+
".cts",
|
|
70346
|
+
".js",
|
|
70347
|
+
".mjs",
|
|
70348
|
+
".mts",
|
|
70349
|
+
".ts"
|
|
70350
|
+
];
|
|
70351
|
+
const CONFIG_FILENAMES = new Set(CONFIG_BASENAMES.flatMap((basename) => CONFIG_EXTENSIONS.map((extension) => `${basename}${extension}`)));
|
|
70352
|
+
const DEFAULT_ESLINT_GLOBALS_PATH = ".eslintrc-auto-import.json";
|
|
70353
|
+
const SUPPORTED_GLOBAL_VALUES = new Set([
|
|
70354
|
+
true,
|
|
70355
|
+
false,
|
|
70356
|
+
"readable",
|
|
70357
|
+
"readonly",
|
|
70358
|
+
"writable",
|
|
70359
|
+
"writeable"
|
|
70360
|
+
]);
|
|
70361
|
+
const getStaticProperty = (objectExpression, propertyName) => objectExpression.properties.find((property) => {
|
|
70362
|
+
if (ts.isSpreadAssignment(property)) return false;
|
|
70363
|
+
const name = ts.isComputedPropertyName(property.name) ? unwrapTypescriptExpression(property.name.expression) : property.name;
|
|
70364
|
+
return (ts.isIdentifier(name) || ts.isStringLiteralLike(name)) && name.text === propertyName;
|
|
70365
|
+
}) ?? null;
|
|
70366
|
+
const hasNonLiteralComputedProperty = (objectExpression) => objectExpression.properties.some((property) => !ts.isSpreadAssignment(property) && ts.isComputedPropertyName(property.name) && !ts.isStringLiteralLike(unwrapTypescriptExpression(property.name.expression)));
|
|
70367
|
+
const getStaticPropertyAssignment = (objectExpression, propertyName) => {
|
|
70368
|
+
const property = getStaticProperty(objectExpression, propertyName);
|
|
70369
|
+
return property && ts.isPropertyAssignment(property) ? property : null;
|
|
70370
|
+
};
|
|
70371
|
+
const getRequireModuleSpecifier = (expression) => {
|
|
70372
|
+
const unwrappedExpression = unwrapTypescriptExpression(expression);
|
|
70373
|
+
if (ts.isPropertyAccessExpression(unwrappedExpression) && unwrappedExpression.name.text === "default") return getRequireModuleSpecifier(unwrappedExpression.expression);
|
|
70374
|
+
if (!ts.isCallExpression(unwrappedExpression) || !ts.isIdentifier(unwrappedExpression.expression) || unwrappedExpression.expression.text !== "require" || unwrappedExpression.arguments.length !== 1) return null;
|
|
70375
|
+
const moduleSpecifier = unwrappedExpression.arguments[0];
|
|
70376
|
+
return moduleSpecifier && ts.isStringLiteralLike(moduleSpecifier) ? moduleSpecifier.text : null;
|
|
70377
|
+
};
|
|
70378
|
+
const getRequiredPropertyModuleSpecifier = (expression, propertyName) => {
|
|
70379
|
+
const unwrappedExpression = unwrapTypescriptExpression(expression);
|
|
70380
|
+
return ts.isPropertyAccessExpression(unwrappedExpression) && unwrappedExpression.name.text === propertyName ? getRequireModuleSpecifier(unwrappedExpression.expression) : null;
|
|
70381
|
+
};
|
|
70382
|
+
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");
|
|
70383
|
+
const isTopLevelExpression = (node) => {
|
|
70384
|
+
let ancestor = node.parent;
|
|
70385
|
+
while (ancestor && !ts.isSourceFile(ancestor)) {
|
|
70386
|
+
if (ts.isExpressionStatement(ancestor)) return ts.isSourceFile(ancestor.parent);
|
|
70387
|
+
if (!ts.isParenthesizedExpression(ancestor) && !ts.isAsExpression(ancestor) && !ts.isSatisfiesExpression(ancestor) && !ts.isNonNullExpression(ancestor) && !ts.isTypeAssertionExpression(ancestor) && !ts.isAwaitExpression(ancestor)) return false;
|
|
70388
|
+
ancestor = ancestor.parent;
|
|
70389
|
+
}
|
|
70390
|
+
return false;
|
|
70391
|
+
};
|
|
70392
|
+
const isInsideActiveConfigProperty = (node, propertyName, sourceFile, esbuildBindings, esbuildNamespaceBindings) => {
|
|
70393
|
+
let ancestor = node.parent;
|
|
70394
|
+
let didFindConfigProperty = false;
|
|
70395
|
+
while (ancestor && !ts.isSourceFile(ancestor)) {
|
|
70396
|
+
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;
|
|
70397
|
+
if (ts.isPropertyAssignment(ancestor)) {
|
|
70398
|
+
const isConfigProperty = (ts.isIdentifier(ancestor.name) || ts.isStringLiteralLike(ancestor.name)) && ancestor.name.text === propertyName;
|
|
70399
|
+
if (didFindConfigProperty || !isConfigProperty) return false;
|
|
70400
|
+
if (!ts.isObjectLiteralExpression(ancestor.parent) || ancestor.parent.properties.some(ts.isSpreadAssignment)) return false;
|
|
70401
|
+
didFindConfigProperty = true;
|
|
70402
|
+
ancestor = ancestor.parent;
|
|
70403
|
+
continue;
|
|
70404
|
+
}
|
|
70405
|
+
if (didFindConfigProperty) {
|
|
70406
|
+
if (ts.isExportAssignment(ancestor)) return true;
|
|
70407
|
+
if (isCommonJsExportAssignment(ancestor, sourceFile)) return isTopLevelExpression(ancestor);
|
|
70408
|
+
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);
|
|
70409
|
+
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;
|
|
70410
|
+
}
|
|
70411
|
+
ancestor = ancestor.parent;
|
|
70412
|
+
}
|
|
70413
|
+
return false;
|
|
70414
|
+
};
|
|
70415
|
+
const getGlobalsPathFromActiveAutoImportCall = (callExpression, packageDirectory) => {
|
|
70416
|
+
const optionsExpression = callExpression.arguments[0];
|
|
70417
|
+
if (!optionsExpression) return null;
|
|
70418
|
+
const unwrappedOptions = unwrapTypescriptExpression(optionsExpression);
|
|
70419
|
+
if (!ts.isObjectLiteralExpression(unwrappedOptions)) return null;
|
|
70420
|
+
if (unwrappedOptions.properties.some(ts.isSpreadAssignment) || hasNonLiteralComputedProperty(unwrappedOptions)) return null;
|
|
70421
|
+
if (getStaticProperty(unwrappedOptions, "include") || getStaticProperty(unwrappedOptions, "exclude")) return null;
|
|
70422
|
+
const eslintrcProperty = getStaticPropertyAssignment(unwrappedOptions, "eslintrc");
|
|
70423
|
+
if (!eslintrcProperty) return null;
|
|
70424
|
+
const eslintrcExpression = unwrapTypescriptExpression(eslintrcProperty.initializer);
|
|
70425
|
+
if (!ts.isObjectLiteralExpression(eslintrcExpression)) return null;
|
|
70426
|
+
if (eslintrcExpression.properties.some(ts.isSpreadAssignment) || hasNonLiteralComputedProperty(eslintrcExpression)) return null;
|
|
70427
|
+
const enabledProperty = getStaticPropertyAssignment(eslintrcExpression, "enabled");
|
|
70428
|
+
if (!enabledProperty || unwrapTypescriptExpression(enabledProperty.initializer).kind !== ts.SyntaxKind.TrueKeyword) return null;
|
|
70429
|
+
const filepathProperty = getStaticProperty(eslintrcExpression, "filepath");
|
|
70430
|
+
if (!filepathProperty) return Path.join(packageDirectory, DEFAULT_ESLINT_GLOBALS_PATH);
|
|
70431
|
+
if (!ts.isPropertyAssignment(filepathProperty)) return null;
|
|
70432
|
+
const filepathExpression = unwrapTypescriptExpression(filepathProperty.initializer);
|
|
70433
|
+
return ts.isStringLiteralLike(filepathExpression) ? Path.resolve(packageDirectory, filepathExpression.text) : null;
|
|
70434
|
+
};
|
|
70435
|
+
const collectGlobalsPathsFromConfig = (configPath, packageDirectory) => {
|
|
70436
|
+
let sourceText;
|
|
70437
|
+
try {
|
|
70438
|
+
sourceText = NFS.readFileSync(configPath, "utf8");
|
|
70439
|
+
} catch {
|
|
70440
|
+
return {
|
|
70441
|
+
didFindActiveAutoImport: false,
|
|
70442
|
+
globalsPaths: []
|
|
70443
|
+
};
|
|
70444
|
+
}
|
|
70445
|
+
const sourceFile = ts.createSourceFile(configPath, sourceText, ts.ScriptTarget.Latest, true);
|
|
70446
|
+
const autoImportBindings = /* @__PURE__ */ new Map();
|
|
70447
|
+
const esbuildBindings = /* @__PURE__ */ new Set();
|
|
70448
|
+
const esbuildNamespaceBindings = /* @__PURE__ */ new Set();
|
|
70449
|
+
for (const statement of sourceFile.statements) {
|
|
70450
|
+
if (ts.isImportDeclaration(statement) && ts.isStringLiteralLike(statement.moduleSpecifier)) {
|
|
70451
|
+
const moduleSpecifier = statement.moduleSpecifier.text;
|
|
70452
|
+
if (AUTO_IMPORT_ADAPTER_PATTERN.test(moduleSpecifier)) {
|
|
70453
|
+
const defaultBinding = statement.importClause?.name;
|
|
70454
|
+
if (defaultBinding) autoImportBindings.set(defaultBinding.text, moduleSpecifier);
|
|
70455
|
+
}
|
|
70456
|
+
if (moduleSpecifier === "esbuild") {
|
|
70457
|
+
const defaultBinding = statement.importClause?.name;
|
|
70458
|
+
if (defaultBinding) esbuildNamespaceBindings.add(defaultBinding.text);
|
|
70459
|
+
const namedBindings = statement.importClause?.namedBindings;
|
|
70460
|
+
if (namedBindings && ts.isNamedImports(namedBindings)) {
|
|
70461
|
+
for (const importSpecifier of namedBindings.elements) if ((importSpecifier.propertyName ?? importSpecifier.name).text === "build") esbuildBindings.add(importSpecifier.name.text);
|
|
70462
|
+
}
|
|
70463
|
+
if (namedBindings && ts.isNamespaceImport(namedBindings)) esbuildNamespaceBindings.add(namedBindings.name.text);
|
|
70464
|
+
}
|
|
70465
|
+
}
|
|
70466
|
+
if (!ts.isVariableStatement(statement)) continue;
|
|
70467
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
70468
|
+
if (!declaration.initializer) continue;
|
|
70469
|
+
const declarationName = ts.isIdentifier(declaration.name) ? declaration.name.text : null;
|
|
70470
|
+
const moduleSpecifier = getRequireModuleSpecifier(declaration.initializer);
|
|
70471
|
+
if (declarationName && moduleSpecifier && AUTO_IMPORT_ADAPTER_PATTERN.test(moduleSpecifier)) autoImportBindings.set(declarationName, moduleSpecifier);
|
|
70472
|
+
if (moduleSpecifier === "esbuild") {
|
|
70473
|
+
if (declarationName) esbuildNamespaceBindings.add(declarationName);
|
|
70474
|
+
if (ts.isObjectBindingPattern(declaration.name)) for (const bindingElement of declaration.name.elements) {
|
|
70475
|
+
const importedName = bindingElement.propertyName ?? bindingElement.name;
|
|
70476
|
+
if (ts.isIdentifier(importedName) && importedName.text === "build" && ts.isIdentifier(bindingElement.name)) esbuildBindings.add(bindingElement.name.text);
|
|
70477
|
+
}
|
|
70478
|
+
}
|
|
70479
|
+
if (declarationName && getRequiredPropertyModuleSpecifier(declaration.initializer, "build") === "esbuild") esbuildBindings.add(declarationName);
|
|
70480
|
+
}
|
|
70481
|
+
}
|
|
70482
|
+
const globalsPaths = /* @__PURE__ */ new Set();
|
|
70483
|
+
let didFindActiveAutoImport = false;
|
|
70484
|
+
let didFindUnsafeActiveAutoImport = false;
|
|
70485
|
+
const visit = (node) => {
|
|
70486
|
+
if (ts.isCallExpression(node)) {
|
|
70487
|
+
const moduleSpecifier = ts.isIdentifier(node.expression) ? autoImportBindings.get(node.expression.text) : getRequireModuleSpecifier(node.expression);
|
|
70488
|
+
if (moduleSpecifier && AUTO_IMPORT_ADAPTER_PATTERN.test(moduleSpecifier)) {
|
|
70489
|
+
if (isInsideActiveConfigProperty(node, moduleSpecifier.endsWith("/astro") ? "integrations" : "plugins", sourceFile, esbuildBindings, esbuildNamespaceBindings)) {
|
|
70490
|
+
didFindActiveAutoImport = true;
|
|
70491
|
+
const globalsPath = getGlobalsPathFromActiveAutoImportCall(node, packageDirectory);
|
|
70492
|
+
if (globalsPath) globalsPaths.add(globalsPath);
|
|
70493
|
+
else didFindUnsafeActiveAutoImport = true;
|
|
70494
|
+
}
|
|
70495
|
+
}
|
|
70496
|
+
}
|
|
70497
|
+
ts.forEachChild(node, visit);
|
|
70498
|
+
};
|
|
70499
|
+
visit(sourceFile);
|
|
70500
|
+
return {
|
|
70501
|
+
didFindActiveAutoImport,
|
|
70502
|
+
globalsPaths: didFindUnsafeActiveAutoImport ? [] : [...globalsPaths]
|
|
70503
|
+
};
|
|
70504
|
+
};
|
|
70505
|
+
const collectGeneratedGlobalNames = (globalsPath, rootDirectory) => {
|
|
70506
|
+
const relativePath = Path.relative(rootDirectory, globalsPath);
|
|
70507
|
+
if (relativePath.startsWith("..") || Path.isAbsolute(relativePath)) return [];
|
|
70508
|
+
const parsed = failOpenReadJson(globalsPath, null);
|
|
70509
|
+
if (!isPlainObject(parsed) || !isPlainObject(parsed.globals)) return [];
|
|
70510
|
+
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();
|
|
70511
|
+
};
|
|
70512
|
+
const findOwningPackageDirectory = (absoluteFilePath, rootDirectory, cache) => {
|
|
70513
|
+
let currentDirectory = Path.dirname(absoluteFilePath);
|
|
70514
|
+
const visitedDirectories = [];
|
|
70515
|
+
while (true) {
|
|
70516
|
+
const cachedDirectory = cache.get(currentDirectory);
|
|
70517
|
+
if (cachedDirectory !== void 0) {
|
|
70518
|
+
for (const visitedDirectory of visitedDirectories) cache.set(visitedDirectory, cachedDirectory);
|
|
70519
|
+
return cachedDirectory;
|
|
70520
|
+
}
|
|
70521
|
+
const relativeDirectory = Path.relative(rootDirectory, currentDirectory);
|
|
70522
|
+
if (relativeDirectory.startsWith("..") || Path.isAbsolute(relativeDirectory)) {
|
|
70523
|
+
for (const visitedDirectory of visitedDirectories) cache.set(visitedDirectory, null);
|
|
70524
|
+
return null;
|
|
70525
|
+
}
|
|
70526
|
+
visitedDirectories.push(currentDirectory);
|
|
70527
|
+
if (NFS.existsSync(Path.join(currentDirectory, "package.json"))) {
|
|
70528
|
+
for (const visitedDirectory of visitedDirectories) cache.set(visitedDirectory, currentDirectory);
|
|
70529
|
+
return currentDirectory;
|
|
70530
|
+
}
|
|
70531
|
+
if (currentDirectory === rootDirectory) {
|
|
70532
|
+
for (const visitedDirectory of visitedDirectories) cache.set(visitedDirectory, null);
|
|
70533
|
+
return null;
|
|
70534
|
+
}
|
|
70535
|
+
currentDirectory = Path.dirname(currentDirectory);
|
|
70536
|
+
}
|
|
70537
|
+
};
|
|
70538
|
+
const collectPackageGlobalNames = (packageDirectory, rootDirectory) => {
|
|
70539
|
+
let directoryEntries;
|
|
70540
|
+
try {
|
|
70541
|
+
directoryEntries = NFS.readdirSync(packageDirectory, { withFileTypes: true });
|
|
70542
|
+
} catch {
|
|
70543
|
+
return [];
|
|
70544
|
+
}
|
|
70545
|
+
const configuredGlobalsPaths = [];
|
|
70546
|
+
for (const entry of directoryEntries) {
|
|
70547
|
+
if (!entry.isFile() && !entry.isSymbolicLink() || !CONFIG_FILENAMES.has(entry.name)) continue;
|
|
70548
|
+
const configGlobalsPaths = collectGlobalsPathsFromConfig(Path.join(packageDirectory, entry.name), packageDirectory);
|
|
70549
|
+
if (configGlobalsPaths.didFindActiveAutoImport) configuredGlobalsPaths.push(configGlobalsPaths.globalsPaths.toSorted());
|
|
70550
|
+
}
|
|
70551
|
+
if (configuredGlobalsPaths.length === 0) return [];
|
|
70552
|
+
const globalsPaths = configuredGlobalsPaths[0];
|
|
70553
|
+
if (configuredGlobalsPaths.some((candidatePaths) => candidatePaths.length !== globalsPaths.length || candidatePaths.some((candidatePath, index) => candidatePath !== globalsPaths[index]))) return [];
|
|
70554
|
+
const names = /* @__PURE__ */ new Set();
|
|
70555
|
+
for (const globalsPath of globalsPaths) for (const name of collectGeneratedGlobalNames(globalsPath, rootDirectory)) names.add(name);
|
|
70556
|
+
return [...names].sort();
|
|
70557
|
+
};
|
|
70558
|
+
const collectUnpluginAutoImportGlobalScopes = ({ rootDirectory, candidateFiles }) => {
|
|
70559
|
+
const absoluteRootDirectory = Path.resolve(rootDirectory);
|
|
70560
|
+
const packageDirectoryCache = /* @__PURE__ */ new Map();
|
|
70561
|
+
const packageDirectories = /* @__PURE__ */ new Set();
|
|
70562
|
+
for (const candidateFile of candidateFiles) {
|
|
70563
|
+
const packageDirectory = findOwningPackageDirectory(Path.resolve(absoluteRootDirectory, candidateFile), absoluteRootDirectory, packageDirectoryCache);
|
|
70564
|
+
if (packageDirectory) packageDirectories.add(packageDirectory);
|
|
70565
|
+
}
|
|
70566
|
+
const scopes = [...packageDirectories].map((packageDirectory) => ({
|
|
70567
|
+
directory: Path.relative(absoluteRootDirectory, packageDirectory).replaceAll("\\", "/"),
|
|
70568
|
+
names: collectPackageGlobalNames(packageDirectory, absoluteRootDirectory)
|
|
70569
|
+
})).sort((firstScope, secondScope) => firstScope.directory.localeCompare(secondScope.directory));
|
|
70570
|
+
return scopes.some((scope) => scope.names.length > 0) ? scopes : [];
|
|
70571
|
+
};
|
|
70275
70572
|
const validateDiagnostic$1 = decodeUnknownSync(Diagnostic);
|
|
70276
70573
|
const decodeFileDiagnostics = (raw) => {
|
|
70277
70574
|
if (!Array.isArray(raw)) return null;
|
|
@@ -70594,6 +70891,12 @@ const appendReanimatedSharedValueHint = (help, rule, project) => {
|
|
|
70594
70891
|
if (!help) return REANIMATED_SHARED_VALUE_HINT;
|
|
70595
70892
|
return `${help}\n\n${REANIMATED_SHARED_VALUE_HINT}`;
|
|
70596
70893
|
};
|
|
70894
|
+
const columnOfUtf8Offset = (sourceBuffer, utf8Offset) => {
|
|
70895
|
+
const boundedOffset = Math.min(Math.max(utf8Offset, 0), sourceBuffer.length);
|
|
70896
|
+
let lineStartOffset = boundedOffset;
|
|
70897
|
+
while (lineStartOffset > 0 && sourceBuffer[lineStartOffset - 1] !== 10) lineStartOffset--;
|
|
70898
|
+
return sourceBuffer.subarray(lineStartOffset, boundedOffset).toString("utf8").length + 1;
|
|
70899
|
+
};
|
|
70597
70900
|
const REDACTED_PLACEHOLDER = "<redacted>";
|
|
70598
70901
|
const KEEP_PREFIX = `$1${REDACTED_PLACEHOLDER}`;
|
|
70599
70902
|
const KNOWN_SECRET_RULES = [
|
|
@@ -71309,7 +71612,7 @@ const resolveMatchByOccurrence = (rule, category) => OCCURRENCE_MATCHED_CATEGORI
|
|
|
71309
71612
|
* with empty text still carry a useful jump target, so they're kept
|
|
71310
71613
|
* with a neutral message.
|
|
71311
71614
|
*/
|
|
71312
|
-
const buildRelatedLocations = (labels, filePath) => {
|
|
71615
|
+
const buildRelatedLocations = (labels, filePath, sourceBuffer) => {
|
|
71313
71616
|
if (labels.length <= 1) return [];
|
|
71314
71617
|
const related = [];
|
|
71315
71618
|
for (let labelIndex = 1; labelIndex < labels.length; labelIndex++) {
|
|
@@ -71317,8 +71620,8 @@ const buildRelatedLocations = (labels, filePath) => {
|
|
|
71317
71620
|
if (!label?.span) continue;
|
|
71318
71621
|
related.push({
|
|
71319
71622
|
filePath,
|
|
71320
|
-
line: label.span.line ?? 0,
|
|
71321
|
-
column: label.span.column ?? 0,
|
|
71623
|
+
line: sourceBuffer === null ? label.span.line ?? 0 : lineOfUtf8Offset(sourceBuffer, label.span.offset),
|
|
71624
|
+
column: sourceBuffer === null ? label.span.column ?? 0 : columnOfUtf8Offset(sourceBuffer, label.span.offset),
|
|
71322
71625
|
offset: label.span.offset,
|
|
71323
71626
|
length: label.span.length,
|
|
71324
71627
|
message: label.label ?? ""
|
|
@@ -71338,7 +71641,7 @@ const isOxlintOutput = (value) => isRecord(value) && Array.isArray(value.diagnos
|
|
|
71338
71641
|
* to the first `{`. Raises `OxlintOutputUnparseable` when the
|
|
71339
71642
|
* stdout isn't valid JSON or doesn't carry a `diagnostics` array.
|
|
71340
71643
|
*/
|
|
71341
|
-
const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
71644
|
+
const parseOxlintOutput = (stdout, project, rootDirectory, sourcePathByLintPath) => {
|
|
71342
71645
|
if (!stdout) return [];
|
|
71343
71646
|
const jsonStart = stdout.indexOf("{");
|
|
71344
71647
|
const sanitizedStdout = jsonStart > 0 ? stdout.slice(jsonStart) : stdout;
|
|
@@ -71355,8 +71658,10 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
71355
71658
|
const sourceBufferCache = /* @__PURE__ */ new Map();
|
|
71356
71659
|
const sourceLinesCache = /* @__PURE__ */ new Map();
|
|
71357
71660
|
const resolveAbsolutePath = (filename) => Path.isAbsolute(filename) ? filename : Path.resolve(rootDirectory || ".", filename);
|
|
71661
|
+
const resolveMappedSourceFilename = (filename) => sourcePathByLintPath?.get(Path.normalize(resolveAbsolutePath(filename)));
|
|
71662
|
+
const resolveSourceFilename = (filename) => resolveMappedSourceFilename(filename) ?? filename;
|
|
71358
71663
|
const readSourceBuffer = (filename) => {
|
|
71359
|
-
const absolutePath = resolveAbsolutePath(filename);
|
|
71664
|
+
const absolutePath = resolveAbsolutePath(resolveSourceFilename(filename));
|
|
71360
71665
|
const cached = sourceBufferCache.get(absolutePath);
|
|
71361
71666
|
if (cached !== void 0) return cached;
|
|
71362
71667
|
let sourceBuffer;
|
|
@@ -71369,7 +71674,7 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
71369
71674
|
return sourceBuffer;
|
|
71370
71675
|
};
|
|
71371
71676
|
const readSourceLines = (filename) => {
|
|
71372
|
-
const absolutePath = resolveAbsolutePath(filename);
|
|
71677
|
+
const absolutePath = resolveAbsolutePath(resolveSourceFilename(filename));
|
|
71373
71678
|
const cached = sourceLinesCache.get(absolutePath);
|
|
71374
71679
|
if (cached !== void 0) return cached;
|
|
71375
71680
|
const sourceBuffer = readSourceBuffer(filename);
|
|
@@ -71378,27 +71683,30 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
71378
71683
|
return sourceLines;
|
|
71379
71684
|
};
|
|
71380
71685
|
const isMinifiedDiagnosticFile = (filename) => {
|
|
71381
|
-
const absolutePath = resolveAbsolutePath(filename);
|
|
71686
|
+
const absolutePath = resolveAbsolutePath(resolveSourceFilename(filename));
|
|
71382
71687
|
const cached = minifiedFileCache.get(absolutePath);
|
|
71383
71688
|
if (cached !== void 0) return cached;
|
|
71384
71689
|
const minified = isMinifiedSource(absolutePath);
|
|
71385
71690
|
minifiedFileCache.set(absolutePath, minified);
|
|
71386
71691
|
return minified;
|
|
71387
71692
|
};
|
|
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) => {
|
|
71693
|
+
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
71694
|
const { plugin, rule } = parseRuleCode(diagnostic.code);
|
|
71390
71695
|
const primaryLabel = diagnostic.labels[0];
|
|
71391
71696
|
const cleaned = cleanDiagnosticMessage(diagnostic.message, diagnostic.help, plugin, rule, project);
|
|
71392
|
-
const
|
|
71697
|
+
const mappedSourceFilename = resolveMappedSourceFilename(diagnostic.filename);
|
|
71698
|
+
const normalizedFilePath = (mappedSourceFilename ?? diagnostic.filename).replaceAll("\\", "/");
|
|
71393
71699
|
const primarySpan = primaryLabel?.span;
|
|
71394
71700
|
const sourceBuffer = primarySpan ? readSourceBuffer(diagnostic.filename) : null;
|
|
71395
|
-
const relatedLocations = buildRelatedLocations(diagnostic.labels, normalizedFilePath);
|
|
71701
|
+
const relatedLocations = buildRelatedLocations(diagnostic.labels, normalizedFilePath, mappedSourceFilename === void 0 ? null : sourceBuffer);
|
|
71396
71702
|
const category = resolveDiagnosticCategory(plugin, rule);
|
|
71397
71703
|
const matchByOccurrence = resolveMatchByOccurrence(rule, category);
|
|
71398
71704
|
const sourceLines = primarySpan ? readSourceLines(diagnostic.filename) : null;
|
|
71399
|
-
const
|
|
71705
|
+
const primaryLineNumber = primarySpan && mappedSourceFilename !== void 0 && sourceBuffer !== null ? lineOfUtf8Offset(sourceBuffer, primarySpan.offset) : primarySpan?.line ?? 0;
|
|
71706
|
+
const primaryColumnNumber = primarySpan && mappedSourceFilename !== void 0 && sourceBuffer !== null ? columnOfUtf8Offset(sourceBuffer, primarySpan.offset) : primarySpan?.column ?? 0;
|
|
71707
|
+
const primaryLineIndex = primarySpan ? primaryLineNumber - 1 : -1;
|
|
71400
71708
|
const primaryLine = sourceLines?.[primaryLineIndex];
|
|
71401
|
-
const primaryColumnIndex = primarySpan ?
|
|
71709
|
+
const primaryColumnIndex = primarySpan ? primaryColumnNumber - 1 : -1;
|
|
71402
71710
|
const isJsxTagLabel = primaryLine !== void 0 && primaryColumnIndex >= 0 && (primaryLine[primaryColumnIndex] === "<" || primaryLine[primaryColumnIndex - 1] === "<");
|
|
71403
71711
|
const jsxOpenerEndLineIndex = sourceLines && isJsxTagLabel ? findJsxOpenerSpan(sourceLines, primaryLineIndex) : null;
|
|
71404
71712
|
const primarySpanEndLine = jsxOpenerEndLineIndex !== null ? jsxOpenerEndLineIndex + 1 : primarySpan && sourceBuffer ? lineOfUtf8Offset(sourceBuffer, primarySpan.offset + Math.max(primarySpan.length - 1, 0)) : void 0;
|
|
@@ -71411,8 +71719,8 @@ const parseOxlintOutput = (stdout, project, rootDirectory) => {
|
|
|
71411
71719
|
message: cleaned.message,
|
|
71412
71720
|
help: cleaned.help,
|
|
71413
71721
|
url: diagnostic.url,
|
|
71414
|
-
line:
|
|
71415
|
-
column:
|
|
71722
|
+
line: primaryLineNumber,
|
|
71723
|
+
column: primaryColumnNumber,
|
|
71416
71724
|
...primarySpan ? {
|
|
71417
71725
|
offset: primarySpan.offset,
|
|
71418
71726
|
length: primarySpan.length,
|
|
@@ -71600,7 +71908,11 @@ const isParallelismRelatedSpawnError = (error) => {
|
|
|
71600
71908
|
* loop with a slimmer config in that case.
|
|
71601
71909
|
*/
|
|
71602
71910
|
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;
|
|
71911
|
+
const { baseArgs, fileBatches, rootDirectory, nodeBinaryPath, project, sourcePathByLintPath, onPartialFailure, onFileProgress, spawnTimeoutMs, outputMaxBytes, splitTotalBudgetMs = OXLINT_SPLIT_TOTAL_BUDGET_MS, splitMaxDepth = 8, signal, deadlineEpochMs } = input;
|
|
71912
|
+
const resolveSourcePath = (filePath) => {
|
|
71913
|
+
const absoluteFilePath = Path.isAbsolute(filePath) ? filePath : Path.resolve(rootDirectory, filePath);
|
|
71914
|
+
return sourcePathByLintPath?.get(Path.normalize(absoluteFilePath)) ?? filePath;
|
|
71915
|
+
};
|
|
71604
71916
|
const requestedConcurrency = resolveScanConcurrency(input.concurrency ?? 1);
|
|
71605
71917
|
let rescueDeadlineEpochMs;
|
|
71606
71918
|
const isPastDeadline = () => deadlineEpochMs !== void 0 && remainingDeadlineBudgetMs(deadlineEpochMs) === 0 || rescueDeadlineEpochMs !== void 0 && remainingDeadlineBudgetMs(rescueDeadlineEpochMs) === 0;
|
|
@@ -71620,7 +71932,7 @@ const spawnLintBatches = async (input) => {
|
|
|
71620
71932
|
}
|
|
71621
71933
|
const batchArgs = [...baseArgs, ...batch];
|
|
71622
71934
|
try {
|
|
71623
|
-
return parseOxlintOutput(await spawnOxlint(batchArgs, rootDirectory, nodeBinaryPath, spawnTimeoutMs, outputMaxBytes, signal), project, rootDirectory);
|
|
71935
|
+
return parseOxlintOutput(await spawnOxlint(batchArgs, rootDirectory, nodeBinaryPath, spawnTimeoutMs, outputMaxBytes, signal), project, rootDirectory, sourcePathByLintPath);
|
|
71624
71936
|
} catch (error) {
|
|
71625
71937
|
if (!isSplittableReactDoctorError(error)) throw error;
|
|
71626
71938
|
if (isPastDeadline()) {
|
|
@@ -71726,10 +72038,12 @@ const spawnLintBatches = async (input) => {
|
|
|
71726
72038
|
onPartialFailure(buildMessage(`${skippedFiles.slice(0, 3).join(", ")}${skippedFiles.length > 3 ? `, +${skippedFiles.length - 3} more` : ""}`));
|
|
71727
72039
|
};
|
|
71728
72040
|
const reasonHint = firstDropReason ? ` — first failure: ${firstDropReason}` : "";
|
|
71729
|
-
|
|
71730
|
-
|
|
72041
|
+
const droppedSourceFiles = [...new Set(droppedFiles.map(resolveSourcePath))];
|
|
72042
|
+
const deadlineSkippedSourceFiles = [...new Set(outcome.deadlineSkippedFiles.map(resolveSourcePath))];
|
|
72043
|
+
reportSkippedFiles(droppedSourceFiles, (fileListPreview) => `${droppedSourceFiles.length} file(s) failed to lint and were skipped (${fileListPreview})${reasonHint}`);
|
|
72044
|
+
reportSkippedFiles(deadlineSkippedSourceFiles, (fileListPreview) => `${deadlineSkippedSourceFiles.length} file(s) skipped — max scan duration reached before they were linted (${fileListPreview})`);
|
|
71731
72045
|
const unavailableFiles = new Set([...droppedFiles, ...outcome.deadlineSkippedFiles]);
|
|
71732
|
-
input.onAnalyzedFiles?.([...new Set(fileBatches.flat().filter((filePath) => !unavailableFiles.has(filePath)))].sort());
|
|
72046
|
+
input.onAnalyzedFiles?.([...new Set(fileBatches.flat().filter((filePath) => !unavailableFiles.has(filePath)).map(resolveSourcePath))].sort());
|
|
71733
72047
|
return dedupeDiagnostics(diagnostics);
|
|
71734
72048
|
};
|
|
71735
72049
|
let didValidate = false;
|
|
@@ -71828,6 +72142,266 @@ const planLintBatches = ({ baseArgs, files, sizeByFile }) => {
|
|
|
71828
72142
|
}
|
|
71829
72143
|
return batches.filter((batch) => batch.fileIndexes.length > 0).map((batch) => batch.fileIndexes.sort((leftIndex, rightIndex) => leftIndex - rightIndex).map((fileIndex) => files[fileIndex]));
|
|
71830
72144
|
};
|
|
72145
|
+
const THREE_MODULE_IMPORT_PATTERN = /\b(?:from\s*|import\s*(?:\(\s*)?|require\s*\(\s*)["']three(?:\/[^"']*)?["']/;
|
|
72146
|
+
const containsThreeModuleImport = (sourceText) => THREE_MODULE_IMPORT_PATTERN.test(sourceText);
|
|
72147
|
+
const COMMENT_OPEN = "<!--";
|
|
72148
|
+
const COMMENT_CLOSE = "-->";
|
|
72149
|
+
const FRONTMATTER_FENCE = "---";
|
|
72150
|
+
const SCRIPT_TAG_NAME = "script";
|
|
72151
|
+
const SCRIPT_OPEN = `<${SCRIPT_TAG_NAME}`;
|
|
72152
|
+
const SCRIPT_CLOSE = `</${SCRIPT_TAG_NAME}`;
|
|
72153
|
+
const TEMPLATE_TAG_NAME = "template";
|
|
72154
|
+
const TEMPLATE_CLOSE = `</${TEMPLATE_TAG_NAME}`;
|
|
72155
|
+
const JAVASCRIPT_MIME_TYPES = new Set([
|
|
72156
|
+
"application/ecmascript",
|
|
72157
|
+
"application/javascript",
|
|
72158
|
+
"application/x-ecmascript",
|
|
72159
|
+
"application/x-javascript",
|
|
72160
|
+
"text/ecmascript",
|
|
72161
|
+
"text/javascript",
|
|
72162
|
+
"text/javascript1.0",
|
|
72163
|
+
"text/javascript1.1",
|
|
72164
|
+
"text/javascript1.2",
|
|
72165
|
+
"text/javascript1.3",
|
|
72166
|
+
"text/javascript1.4",
|
|
72167
|
+
"text/javascript1.5",
|
|
72168
|
+
"text/jscript",
|
|
72169
|
+
"text/livescript",
|
|
72170
|
+
"text/x-ecmascript",
|
|
72171
|
+
"text/x-javascript"
|
|
72172
|
+
]);
|
|
72173
|
+
const RAW_TEXT_TAG_NAMES = new Set([
|
|
72174
|
+
"iframe",
|
|
72175
|
+
"noembed",
|
|
72176
|
+
"noframes",
|
|
72177
|
+
"noscript",
|
|
72178
|
+
"style",
|
|
72179
|
+
"textarea",
|
|
72180
|
+
"title",
|
|
72181
|
+
"xmp"
|
|
72182
|
+
]);
|
|
72183
|
+
const PLAINTEXT_TAG_NAME = "plaintext";
|
|
72184
|
+
const TAG_OPEN_UTF8_BYTE = "<".charCodeAt(0);
|
|
72185
|
+
const TAG_CLOSE_UTF8_BYTE = ">".charCodeAt(0);
|
|
72186
|
+
const SINGLE_QUOTE_UTF8_BYTE = "'".charCodeAt(0);
|
|
72187
|
+
const DOUBLE_QUOTE_UTF8_BYTE = "\"".charCodeAt(0);
|
|
72188
|
+
const ATTRIBUTE_ASSIGNMENT_UTF8_BYTE = "=".charCodeAt(0);
|
|
72189
|
+
const TAG_SELF_CLOSE_UTF8_BYTE = "/".charCodeAt(0);
|
|
72190
|
+
const TAB_UTF8_BYTE = " ".charCodeAt(0);
|
|
72191
|
+
const FORM_FEED_UTF8_BYTE = "\f".charCodeAt(0);
|
|
72192
|
+
const isHtmlWhitespace = (byte) => byte === TAB_UTF8_BYTE || byte === 10 || byte === FORM_FEED_UTF8_BYTE || byte === 13 || byte === 32;
|
|
72193
|
+
const matchesAsciiCaseInsensitive = (sourceBuffer, startByte, expected) => {
|
|
72194
|
+
if (startByte + expected.length > sourceBuffer.length) return false;
|
|
72195
|
+
for (let expectedIndex = 0; expectedIndex < expected.length; expectedIndex++) {
|
|
72196
|
+
const sourceByte = sourceBuffer[startByte + expectedIndex];
|
|
72197
|
+
if (sourceByte === void 0 || String.fromCharCode(sourceByte).toLowerCase() !== expected[expectedIndex]) return false;
|
|
72198
|
+
}
|
|
72199
|
+
return true;
|
|
72200
|
+
};
|
|
72201
|
+
const isTagBoundary = (byte) => byte === TAG_CLOSE_UTF8_BYTE || byte === TAG_SELF_CLOSE_UTF8_BYTE || isHtmlWhitespace(byte);
|
|
72202
|
+
const isPotentialTagStart = (byte) => {
|
|
72203
|
+
if (byte === void 0) return false;
|
|
72204
|
+
return /[A-Za-z!/?]/.test(String.fromCharCode(byte));
|
|
72205
|
+
};
|
|
72206
|
+
const findLineEnd = (sourceBuffer, lineStartByte) => {
|
|
72207
|
+
let byteIndex = lineStartByte;
|
|
72208
|
+
while (byteIndex < sourceBuffer.length && sourceBuffer[byteIndex] !== 10 && sourceBuffer[byteIndex] !== 13) byteIndex++;
|
|
72209
|
+
return byteIndex;
|
|
72210
|
+
};
|
|
72211
|
+
const findNextLineStart = (sourceBuffer, lineStartByte) => {
|
|
72212
|
+
const lineEndByte = findLineEnd(sourceBuffer, lineStartByte);
|
|
72213
|
+
if (sourceBuffer[lineEndByte] === 13 && sourceBuffer[lineEndByte + 1] === 10) return lineEndByte + 2;
|
|
72214
|
+
return Math.min(lineEndByte + 1, sourceBuffer.length);
|
|
72215
|
+
};
|
|
72216
|
+
const isFrontmatterFenceLine = (sourceBuffer, lineStartByte) => {
|
|
72217
|
+
if (!matchesAsciiCaseInsensitive(sourceBuffer, lineStartByte, FRONTMATTER_FENCE)) return false;
|
|
72218
|
+
const lineEndByte = findLineEnd(sourceBuffer, lineStartByte);
|
|
72219
|
+
for (let byteIndex = lineStartByte + 3; byteIndex < lineEndByte; byteIndex++) if (!isHtmlWhitespace(sourceBuffer[byteIndex])) return false;
|
|
72220
|
+
return true;
|
|
72221
|
+
};
|
|
72222
|
+
const findFrontmatterEnd = (sourceBuffer) => {
|
|
72223
|
+
if (!isFrontmatterFenceLine(sourceBuffer, 0)) return 0;
|
|
72224
|
+
const openingFenceEndByte = findLineEnd(sourceBuffer, 0);
|
|
72225
|
+
let lineStartByte = findNextLineStart(sourceBuffer, 0);
|
|
72226
|
+
while (lineStartByte < sourceBuffer.length) {
|
|
72227
|
+
if (isFrontmatterFenceLine(sourceBuffer, lineStartByte)) return findLineEnd(sourceBuffer, lineStartByte);
|
|
72228
|
+
lineStartByte = findNextLineStart(sourceBuffer, lineStartByte);
|
|
72229
|
+
}
|
|
72230
|
+
return openingFenceEndByte;
|
|
72231
|
+
};
|
|
72232
|
+
const maskByteRange = (maskedBuffer, startByte, endByte) => {
|
|
72233
|
+
for (let byteIndex = startByte; byteIndex < endByte; byteIndex++) {
|
|
72234
|
+
const byte = maskedBuffer[byteIndex];
|
|
72235
|
+
if (byte !== 10 && byte !== 13) maskedBuffer[byteIndex] = 32;
|
|
72236
|
+
}
|
|
72237
|
+
};
|
|
72238
|
+
const readStartTagName = (sourceBuffer, tagStartByte) => {
|
|
72239
|
+
const firstNameByte = sourceBuffer[tagStartByte + 1];
|
|
72240
|
+
if (firstNameByte === void 0 || !/[A-Za-z]/.test(String.fromCharCode(firstNameByte))) return null;
|
|
72241
|
+
let nameEndByte = tagStartByte + 2;
|
|
72242
|
+
while (nameEndByte < sourceBuffer.length && /[A-Za-z0-9:-]/.test(String.fromCharCode(sourceBuffer[nameEndByte] ?? 32))) nameEndByte++;
|
|
72243
|
+
return sourceBuffer.subarray(tagStartByte + 1, nameEndByte).toString("ascii").toLowerCase();
|
|
72244
|
+
};
|
|
72245
|
+
const findTagEnd = (sourceBuffer, startByte) => {
|
|
72246
|
+
let quoteByte = null;
|
|
72247
|
+
for (let byteIndex = startByte; byteIndex < sourceBuffer.length; byteIndex++) {
|
|
72248
|
+
const byte = sourceBuffer[byteIndex];
|
|
72249
|
+
if (quoteByte !== null) {
|
|
72250
|
+
if (byte === quoteByte) quoteByte = null;
|
|
72251
|
+
continue;
|
|
72252
|
+
}
|
|
72253
|
+
if (byte === SINGLE_QUOTE_UTF8_BYTE || byte === DOUBLE_QUOTE_UTF8_BYTE) {
|
|
72254
|
+
quoteByte = byte;
|
|
72255
|
+
continue;
|
|
72256
|
+
}
|
|
72257
|
+
if (byte === TAG_CLOSE_UTF8_BYTE) return byteIndex;
|
|
72258
|
+
}
|
|
72259
|
+
return sourceBuffer.length;
|
|
72260
|
+
};
|
|
72261
|
+
const parseScriptAttributes = (sourceBuffer, attributesStartByte, tagEndByte) => {
|
|
72262
|
+
let byteIndex = attributesStartByte;
|
|
72263
|
+
let hasSource = false;
|
|
72264
|
+
let language = null;
|
|
72265
|
+
let scriptType = null;
|
|
72266
|
+
while (byteIndex < tagEndByte) {
|
|
72267
|
+
while (byteIndex < tagEndByte && (isHtmlWhitespace(sourceBuffer[byteIndex]) || sourceBuffer[byteIndex] === TAG_SELF_CLOSE_UTF8_BYTE)) byteIndex++;
|
|
72268
|
+
const attributeNameStartByte = byteIndex;
|
|
72269
|
+
while (byteIndex < tagEndByte && !isHtmlWhitespace(sourceBuffer[byteIndex]) && sourceBuffer[byteIndex] !== ATTRIBUTE_ASSIGNMENT_UTF8_BYTE && sourceBuffer[byteIndex] !== TAG_SELF_CLOSE_UTF8_BYTE) byteIndex++;
|
|
72270
|
+
const attributeName = sourceBuffer.subarray(attributeNameStartByte, byteIndex).toString("ascii").toLowerCase();
|
|
72271
|
+
while (byteIndex < tagEndByte && isHtmlWhitespace(sourceBuffer[byteIndex])) byteIndex++;
|
|
72272
|
+
let attributeValue = "";
|
|
72273
|
+
if (sourceBuffer[byteIndex] === ATTRIBUTE_ASSIGNMENT_UTF8_BYTE) {
|
|
72274
|
+
byteIndex++;
|
|
72275
|
+
while (byteIndex < tagEndByte && isHtmlWhitespace(sourceBuffer[byteIndex])) byteIndex++;
|
|
72276
|
+
const quoteByte = sourceBuffer[byteIndex];
|
|
72277
|
+
if (quoteByte === SINGLE_QUOTE_UTF8_BYTE || quoteByte === DOUBLE_QUOTE_UTF8_BYTE) {
|
|
72278
|
+
const valueStartByte = byteIndex + 1;
|
|
72279
|
+
byteIndex = valueStartByte;
|
|
72280
|
+
while (byteIndex < tagEndByte && sourceBuffer[byteIndex] !== quoteByte) byteIndex++;
|
|
72281
|
+
attributeValue = sourceBuffer.subarray(valueStartByte, byteIndex).toString("utf8");
|
|
72282
|
+
if (byteIndex < tagEndByte) byteIndex++;
|
|
72283
|
+
} else {
|
|
72284
|
+
const valueStartByte = byteIndex;
|
|
72285
|
+
while (byteIndex < tagEndByte && !isHtmlWhitespace(sourceBuffer[byteIndex]) && sourceBuffer[byteIndex] !== TAG_CLOSE_UTF8_BYTE) byteIndex++;
|
|
72286
|
+
attributeValue = sourceBuffer.subarray(valueStartByte, byteIndex).toString("utf8");
|
|
72287
|
+
}
|
|
72288
|
+
}
|
|
72289
|
+
if (attributeName === "src") hasSource = true;
|
|
72290
|
+
else if (attributeName === "type" && scriptType === null) scriptType = attributeValue;
|
|
72291
|
+
else if (attributeName === "language" && language === null) language = attributeValue;
|
|
72292
|
+
}
|
|
72293
|
+
return {
|
|
72294
|
+
hasSource,
|
|
72295
|
+
language,
|
|
72296
|
+
type: scriptType
|
|
72297
|
+
};
|
|
72298
|
+
};
|
|
72299
|
+
const isExecutableScript = (attributes) => {
|
|
72300
|
+
if (attributes.hasSource) return false;
|
|
72301
|
+
const type = attributes.type?.trim().toLowerCase() ?? "";
|
|
72302
|
+
if (type !== "") {
|
|
72303
|
+
const mimeType = type.split(";")[0]?.trim() ?? "";
|
|
72304
|
+
return mimeType === "module" || JAVASCRIPT_MIME_TYPES.has(mimeType);
|
|
72305
|
+
}
|
|
72306
|
+
const language = attributes.language?.trim().toLowerCase() ?? "";
|
|
72307
|
+
return language === "" || JAVASCRIPT_MIME_TYPES.has(`text/${language}`);
|
|
72308
|
+
};
|
|
72309
|
+
const findElementClose = (sourceBuffer, startByte, tagName) => {
|
|
72310
|
+
const closeTagStart = `</${tagName}`;
|
|
72311
|
+
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;
|
|
72312
|
+
return sourceBuffer.length;
|
|
72313
|
+
};
|
|
72314
|
+
const prepareHtmlScriptSource = (sourceBuffer) => {
|
|
72315
|
+
const frontmatterEndByte = findFrontmatterEnd(sourceBuffer);
|
|
72316
|
+
let maskedBuffer = frontmatterEndByte > 0 ? Buffer.from(sourceBuffer) : null;
|
|
72317
|
+
if (maskedBuffer !== null) maskByteRange(maskedBuffer, 0, frontmatterEndByte);
|
|
72318
|
+
const executableScriptBodies = [];
|
|
72319
|
+
let byteIndex = frontmatterEndByte;
|
|
72320
|
+
let templateDepth = 0;
|
|
72321
|
+
while (byteIndex < sourceBuffer.length) {
|
|
72322
|
+
if (sourceBuffer[byteIndex] !== TAG_OPEN_UTF8_BYTE) {
|
|
72323
|
+
byteIndex++;
|
|
72324
|
+
continue;
|
|
72325
|
+
}
|
|
72326
|
+
if (matchesAsciiCaseInsensitive(sourceBuffer, byteIndex, COMMENT_OPEN)) {
|
|
72327
|
+
const commentEndByte = sourceBuffer.indexOf(COMMENT_CLOSE, byteIndex + 4);
|
|
72328
|
+
byteIndex = commentEndByte === -1 ? sourceBuffer.length : commentEndByte + 3;
|
|
72329
|
+
continue;
|
|
72330
|
+
}
|
|
72331
|
+
if (matchesAsciiCaseInsensitive(sourceBuffer, byteIndex, TEMPLATE_CLOSE) && isTagBoundary(sourceBuffer[byteIndex + TEMPLATE_CLOSE.length])) {
|
|
72332
|
+
const tagEndByte = findTagEnd(sourceBuffer, byteIndex + TEMPLATE_CLOSE.length);
|
|
72333
|
+
if (templateDepth > 0) templateDepth--;
|
|
72334
|
+
byteIndex = Math.min(tagEndByte + 1, sourceBuffer.length);
|
|
72335
|
+
continue;
|
|
72336
|
+
}
|
|
72337
|
+
if (!matchesAsciiCaseInsensitive(sourceBuffer, byteIndex, SCRIPT_OPEN) || !isTagBoundary(sourceBuffer[byteIndex + SCRIPT_OPEN.length])) {
|
|
72338
|
+
if (!isPotentialTagStart(sourceBuffer[byteIndex + 1])) {
|
|
72339
|
+
byteIndex++;
|
|
72340
|
+
continue;
|
|
72341
|
+
}
|
|
72342
|
+
const tagEndByte = findTagEnd(sourceBuffer, byteIndex + 1);
|
|
72343
|
+
const tagName = readStartTagName(sourceBuffer, byteIndex);
|
|
72344
|
+
if (tagName === PLAINTEXT_TAG_NAME) break;
|
|
72345
|
+
if (tagName === TEMPLATE_TAG_NAME) templateDepth++;
|
|
72346
|
+
if (tagName !== null && RAW_TEXT_TAG_NAMES.has(tagName)) {
|
|
72347
|
+
const closeTagStartByte = findElementClose(sourceBuffer, tagEndByte + 1, tagName);
|
|
72348
|
+
if (closeTagStartByte === sourceBuffer.length) break;
|
|
72349
|
+
const closeTagEndByte = findTagEnd(sourceBuffer, closeTagStartByte + tagName.length + 2);
|
|
72350
|
+
byteIndex = Math.min(closeTagEndByte + 1, sourceBuffer.length);
|
|
72351
|
+
continue;
|
|
72352
|
+
}
|
|
72353
|
+
byteIndex = Math.min(tagEndByte + 1, sourceBuffer.length);
|
|
72354
|
+
continue;
|
|
72355
|
+
}
|
|
72356
|
+
const tagEndByte = findTagEnd(sourceBuffer, byteIndex + SCRIPT_OPEN.length);
|
|
72357
|
+
if (tagEndByte === sourceBuffer.length) break;
|
|
72358
|
+
const bodyStartByte = tagEndByte + 1;
|
|
72359
|
+
const bodyEndByte = findElementClose(sourceBuffer, bodyStartByte, SCRIPT_TAG_NAME);
|
|
72360
|
+
const attributes = parseScriptAttributes(sourceBuffer, byteIndex + SCRIPT_OPEN.length, tagEndByte);
|
|
72361
|
+
if (attributes.hasSource || templateDepth > 0) {
|
|
72362
|
+
maskedBuffer ??= Buffer.from(sourceBuffer);
|
|
72363
|
+
maskByteRange(maskedBuffer, bodyStartByte, bodyEndByte);
|
|
72364
|
+
} else if (isExecutableScript(attributes)) executableScriptBodies.push(sourceBuffer.subarray(bodyStartByte, bodyEndByte));
|
|
72365
|
+
if (bodyEndByte === sourceBuffer.length) break;
|
|
72366
|
+
const closeTagEndByte = findTagEnd(sourceBuffer, bodyEndByte + SCRIPT_CLOSE.length);
|
|
72367
|
+
byteIndex = Math.min(closeTagEndByte + 1, sourceBuffer.length);
|
|
72368
|
+
}
|
|
72369
|
+
return {
|
|
72370
|
+
executableScriptBodies,
|
|
72371
|
+
lintBuffer: maskedBuffer ?? sourceBuffer
|
|
72372
|
+
};
|
|
72373
|
+
};
|
|
72374
|
+
const prepareHtmlLintSources = (rootDirectory, temporaryDirectory, candidateFiles) => {
|
|
72375
|
+
const lintFiles = [];
|
|
72376
|
+
const sourcePathByLintPath = /* @__PURE__ */ new Map();
|
|
72377
|
+
const sizeByLintPath = /* @__PURE__ */ new Map();
|
|
72378
|
+
const htmlSourcesDirectory = Path.join(temporaryDirectory, "html-sources");
|
|
72379
|
+
let htmlFileIndex = 0;
|
|
72380
|
+
let hasThreeModuleImport = false;
|
|
72381
|
+
for (const candidateFile of candidateFiles) {
|
|
72382
|
+
if (!HTML_FILE_PATTERN.test(candidateFile)) {
|
|
72383
|
+
lintFiles.push(candidateFile);
|
|
72384
|
+
continue;
|
|
72385
|
+
}
|
|
72386
|
+
const absoluteSourcePath = Path.isAbsolute(candidateFile) ? candidateFile : Path.resolve(rootDirectory, candidateFile);
|
|
72387
|
+
const sourceBuffer = NFS.readFileSync(absoluteSourcePath);
|
|
72388
|
+
const { executableScriptBodies, lintBuffer } = prepareHtmlScriptSource(sourceBuffer);
|
|
72389
|
+
if (htmlFileIndex === 0) NFS.mkdirSync(htmlSourcesDirectory, { recursive: true });
|
|
72390
|
+
const lintPath = Path.join(htmlSourcesDirectory, `${htmlFileIndex}.astro`);
|
|
72391
|
+
NFS.writeFileSync(lintPath, lintBuffer);
|
|
72392
|
+
lintFiles.push(lintPath);
|
|
72393
|
+
sourcePathByLintPath.set(Path.resolve(lintPath), candidateFile);
|
|
72394
|
+
sizeByLintPath.set(lintPath, sourceBuffer.length);
|
|
72395
|
+
hasThreeModuleImport ||= executableScriptBodies.some((scriptBody) => containsThreeModuleImport(scriptBody.toString("utf8")));
|
|
72396
|
+
htmlFileIndex++;
|
|
72397
|
+
}
|
|
72398
|
+
return {
|
|
72399
|
+
lintFiles,
|
|
72400
|
+
sourcePathByLintPath,
|
|
72401
|
+
sizeByLintPath,
|
|
72402
|
+
hasThreeModuleImport
|
|
72403
|
+
};
|
|
72404
|
+
};
|
|
71831
72405
|
/**
|
|
71832
72406
|
* Atomically (re)writes the generated oxlintrc.json. Used twice in
|
|
71833
72407
|
* the runner: once for the primary scan, once for the
|
|
@@ -71988,6 +72562,8 @@ const reactHooksJsPluginDropNote = (error) => {
|
|
|
71988
72562
|
const runOxlint = async (options) => {
|
|
71989
72563
|
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
72564
|
const serverAuthFunctionNames = Array.isArray(userConfig?.serverAuthFunctionNames) ? userConfig.serverAuthFunctionNames.filter((entry) => typeof entry === "string" && entry.length > 0) : void 0;
|
|
72565
|
+
const runtimeGlobals = Array.isArray(userConfig?.runtimeGlobals) ? userConfig.runtimeGlobals.filter((entry) => typeof entry === "string" && entry.length > 0) : void 0;
|
|
72566
|
+
let unpluginAutoImportGlobalScopes = [];
|
|
71991
72567
|
const severityControls = buildRuleSeverityControls(userConfig);
|
|
71992
72568
|
validateRuleRegistration();
|
|
71993
72569
|
resetManifestCaches();
|
|
@@ -72001,21 +72577,6 @@ const runOxlint = async (options) => {
|
|
|
72001
72577
|
const pluginPath = resolvePluginPath();
|
|
72002
72578
|
const extendsPaths = (adoptExistingLintConfig && !customRulesOnly ? detectUserLintConfigPaths(rootDirectory) : []).filter(canOxlintExtendConfig);
|
|
72003
72579
|
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
72580
|
const restoreDisableDirectives = respectInlineDisables ? () => {} : await neutralizeDisableDirectives(rootDirectory, includePaths);
|
|
72020
72581
|
const configDirectory = NFS.mkdtempSync(Path.join(os.tmpdir(), "react-doctor-oxlintrc-"));
|
|
72021
72582
|
const configPath = Path.join(configDirectory, "oxlintrc.json");
|
|
@@ -72051,7 +72612,36 @@ const runOxlint = async (options) => {
|
|
|
72051
72612
|
await yieldToEventLoop();
|
|
72052
72613
|
const sizedScanFiles = includePaths === void 0 ? listSourceFilesWithSize(rootDirectory) : null;
|
|
72053
72614
|
const candidateFiles = includePaths !== void 0 ? includePaths : (sizedScanFiles ?? []).map((entry) => entry.path);
|
|
72615
|
+
unpluginAutoImportGlobalScopes = collectUnpluginAutoImportGlobalScopes({
|
|
72616
|
+
rootDirectory,
|
|
72617
|
+
candidateFiles
|
|
72618
|
+
});
|
|
72619
|
+
const preparedHtmlSources = prepareHtmlLintSources(rootDirectory, configDirectory, candidateFiles);
|
|
72620
|
+
const lintFiles = preparedHtmlSources.lintFiles;
|
|
72621
|
+
const hasHtmlFiles = preparedHtmlSources.sourcePathByLintPath.size > 0;
|
|
72622
|
+
const lintProject = !project.hasThree && preparedHtmlSources.hasThreeModuleImport ? {
|
|
72623
|
+
...project,
|
|
72624
|
+
hasThree: true
|
|
72625
|
+
} : project;
|
|
72626
|
+
const buildConfig = (overrides) => createOxlintConfig({
|
|
72627
|
+
pluginPath,
|
|
72628
|
+
project: lintProject,
|
|
72629
|
+
customRulesOnly,
|
|
72630
|
+
extendsPaths: overrides.extendsPaths,
|
|
72631
|
+
ignoredTags,
|
|
72632
|
+
includedTags,
|
|
72633
|
+
includeTagDefaults,
|
|
72634
|
+
runtimeGlobals,
|
|
72635
|
+
unpluginAutoImportGlobalScopes,
|
|
72636
|
+
serverAuthFunctionNames,
|
|
72637
|
+
severityControls,
|
|
72638
|
+
userPlugins,
|
|
72639
|
+
disableReactHooksJsPlugin: overrides.disableReactHooksJsPlugin,
|
|
72640
|
+
ruleSelection: overrides.ruleSelection,
|
|
72641
|
+
sidecarRuleIdFilter: overrides.sidecarRuleIdFilter
|
|
72642
|
+
});
|
|
72054
72643
|
const sizeByFile = sizedScanFiles !== null && lintBatchOrdering === "cost" ? new Map(sizedScanFiles.map((entry) => [entry.path, entry.sizeBytes])) : null;
|
|
72644
|
+
if (sizeByFile !== null) for (const [lintPath, sizeBytes] of preparedHtmlSources.sizeByLintPath) sizeByFile.set(lintPath, sizeBytes);
|
|
72055
72645
|
const buildFileBatches = (passBaseArgs, passFiles) => sizeByFile !== null ? planLintBatches({
|
|
72056
72646
|
baseArgs: passBaseArgs,
|
|
72057
72647
|
files: passFiles,
|
|
@@ -72080,7 +72670,8 @@ const runOxlint = async (options) => {
|
|
|
72080
72670
|
fileBatches: passFileBatches,
|
|
72081
72671
|
rootDirectory,
|
|
72082
72672
|
nodeBinaryPath,
|
|
72083
|
-
project,
|
|
72673
|
+
project: lintProject,
|
|
72674
|
+
sourcePathByLintPath: preparedHtmlSources.sourcePathByLintPath,
|
|
72084
72675
|
onPartialFailure: reportPartialFailure,
|
|
72085
72676
|
onAnalyzedFiles: (filePaths) => {
|
|
72086
72677
|
analyzedFiles = filePaths;
|
|
@@ -72115,7 +72706,7 @@ const runOxlint = async (options) => {
|
|
|
72115
72706
|
};
|
|
72116
72707
|
}
|
|
72117
72708
|
};
|
|
72118
|
-
if (perFileLintCacheEnabled && !project.hasReactCompiler && project.hasReactCompilerLintPlugin !== true && extendsPaths.length === 0 && userPlugins.length === 0) {
|
|
72709
|
+
if (perFileLintCacheEnabled && !project.hasReactCompiler && project.hasReactCompilerLintPlugin !== true && extendsPaths.length === 0 && userPlugins.length === 0 && !hasHtmlFiles) {
|
|
72119
72710
|
const rulesetHash = computeRulesetHash({
|
|
72120
72711
|
config: buildConfig({
|
|
72121
72712
|
extendsPaths: [],
|
|
@@ -72273,14 +72864,15 @@ const runOxlint = async (options) => {
|
|
|
72273
72864
|
]);
|
|
72274
72865
|
}
|
|
72275
72866
|
const baseArgs = makeBaseArgs(configPath);
|
|
72276
|
-
const fileBatches = buildFileBatches(baseArgs,
|
|
72867
|
+
const fileBatches = buildFileBatches(baseArgs, lintFiles);
|
|
72277
72868
|
let analyzedFiles = [];
|
|
72278
72869
|
const runBatches = () => spawnLintBatches({
|
|
72279
72870
|
baseArgs,
|
|
72280
72871
|
fileBatches,
|
|
72281
72872
|
rootDirectory,
|
|
72282
72873
|
nodeBinaryPath,
|
|
72283
|
-
project,
|
|
72874
|
+
project: lintProject,
|
|
72875
|
+
sourcePathByLintPath: preparedHtmlSources.sourcePathByLintPath,
|
|
72284
72876
|
onPartialFailure,
|
|
72285
72877
|
onAnalyzedFiles: (filePaths) => {
|
|
72286
72878
|
analyzedFiles = filePaths;
|
|
@@ -74202,4 +74794,4 @@ const toJsonReport = (result, options) => buildJsonReport({
|
|
|
74202
74794
|
export { AmbiguousProjectError, NoReactDependencyError, NotADirectoryError, PackageJsonNotFoundError, ProjectNotFoundError, ReactDoctorError, buildJsonReport, buildJsonReportError, clearCaches, defineConfig, diagnose, filterSourceFiles, getDiffInfo, hasReactRuntime, isProjectDiscoveryError, isReactDoctorError, summarizeDiagnostics, toJsonReport };
|
|
74203
74795
|
|
|
74204
74796
|
//# sourceMappingURL=index.js.map
|
|
74205
|
-
//# debugId=
|
|
74797
|
+
//# debugId=5ad39650-1163-5117-aad5-472963ee3867
|