Update Bot (j'ai plus le repo sur GitHub)
Qui c'est la conne qui a delete le repo sur GitHub? C'EST MOIIIII
This commit is contained in:
175
node_modules/eslint/lib/rules/no-restricted-imports.js
generated
vendored
175
node_modules/eslint/lib/rules/no-restricted-imports.js
generated
vendored
@@ -41,6 +41,11 @@ const arrayOfStringsOrObjects = {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
allowTypeImports: {
|
||||
type: "boolean",
|
||||
description:
|
||||
"Whether to allow type-only imports for a path.",
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
required: ["name"],
|
||||
@@ -105,6 +110,11 @@ const arrayOfStringsOrObjectPatterns = {
|
||||
caseSensitive: {
|
||||
type: "boolean",
|
||||
},
|
||||
allowTypeImports: {
|
||||
type: "boolean",
|
||||
description:
|
||||
"Whether to allow type-only imports for a pattern.",
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
not: {
|
||||
@@ -137,6 +147,8 @@ const arrayOfStringsOrObjectPatterns = {
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
dialects: ["typescript", "javascript"],
|
||||
language: "javascript",
|
||||
|
||||
docs: {
|
||||
description: "Disallow specified modules when loaded by `import`",
|
||||
@@ -261,6 +273,7 @@ module.exports = {
|
||||
message: importSource.message,
|
||||
importNames: importSource.importNames,
|
||||
allowImportNames: importSource.allowImportNames,
|
||||
allowTypeImports: importSource.allowTypeImports,
|
||||
});
|
||||
}
|
||||
return memo;
|
||||
@@ -291,6 +304,7 @@ module.exports = {
|
||||
importNamePattern,
|
||||
allowImportNames,
|
||||
allowImportNamePattern,
|
||||
allowTypeImports,
|
||||
}) => ({
|
||||
...(group
|
||||
? {
|
||||
@@ -313,6 +327,7 @@ module.exports = {
|
||||
importNamePattern,
|
||||
allowImportNames,
|
||||
allowImportNamePattern,
|
||||
allowTypeImports,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -324,6 +339,48 @@ module.exports = {
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the node is a type-only import
|
||||
* @param {ASTNode} node The node to check
|
||||
* @returns {boolean} Whether the node is a type-only import
|
||||
*/
|
||||
function isTypeOnlyImport(node) {
|
||||
return (
|
||||
node.importKind === "type" ||
|
||||
(node.specifiers?.length > 0 &&
|
||||
node.specifiers.every(
|
||||
specifier => specifier.importKind === "type",
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a specifier is type-only
|
||||
* @param {ASTNode} specifier The specifier to check
|
||||
* @returns {boolean} Whether the specifier is type-only
|
||||
*/
|
||||
function isTypeOnlySpecifier(specifier) {
|
||||
return (
|
||||
specifier.importKind === "type" ||
|
||||
specifier.exportKind === "type"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the node is a type-only export
|
||||
* @param {ASTNode} node The node to check
|
||||
* @returns {boolean} Whether the node is a type-only export
|
||||
*/
|
||||
function isTypeOnlyExport(node) {
|
||||
return (
|
||||
node.exportKind === "type" ||
|
||||
(node.specifiers?.length > 0 &&
|
||||
node.specifiers.every(
|
||||
specifier => specifier.exportKind === "type",
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Report a restricted path.
|
||||
* @param {string} importSource path of the import
|
||||
@@ -344,6 +401,28 @@ module.exports = {
|
||||
restrictedPathEntry.importNames;
|
||||
const allowedImportNames =
|
||||
restrictedPathEntry.allowImportNames;
|
||||
const allowTypeImports =
|
||||
restrictedPathEntry.allowTypeImports;
|
||||
|
||||
// Skip if this is a type-only import and it's allowed for this specific entry
|
||||
if (
|
||||
allowTypeImports &&
|
||||
(node.type === "ImportDeclaration" ||
|
||||
node.type === "TSImportEqualsDeclaration") &&
|
||||
isTypeOnlyImport(node)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip if this is a type-only export and it's allowed for this specific entry
|
||||
if (
|
||||
allowTypeImports &&
|
||||
(node.type === "ExportNamedDeclaration" ||
|
||||
node.type === "ExportAllDeclaration") &&
|
||||
isTypeOnlyExport(node)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!restrictedImportNames && !allowedImportNames) {
|
||||
context.report({
|
||||
@@ -400,6 +479,14 @@ module.exports = {
|
||||
restrictedImportNames.includes(importName)
|
||||
) {
|
||||
specifiers.forEach(specifier => {
|
||||
// Skip if this is a type-only import specifier and type imports are allowed
|
||||
if (
|
||||
allowTypeImports &&
|
||||
isTypeOnlySpecifier(specifier.specifier)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
node,
|
||||
messageId: customMessage
|
||||
@@ -420,6 +507,14 @@ module.exports = {
|
||||
!allowedImportNames.includes(importName)
|
||||
) {
|
||||
specifiers.forEach(specifier => {
|
||||
// Skip if this is a type-only import specifier and type imports are allowed
|
||||
if (
|
||||
allowTypeImports &&
|
||||
isTypeOnlySpecifier(specifier.specifier)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
node,
|
||||
loc: specifier.loc,
|
||||
@@ -446,11 +541,30 @@ module.exports = {
|
||||
* @param {Object} group contains an Ignore instance for paths, the customMessage to show on failure,
|
||||
* and any restricted import names that have been specified in the config
|
||||
* @param {Map<string,Object[]>} importNames Map of import names that are being imported
|
||||
* @param {string} importSource the import source string
|
||||
* @returns {void}
|
||||
* @private
|
||||
*/
|
||||
function reportPathForPatterns(node, group, importNames) {
|
||||
const importSource = node.source.value.trim();
|
||||
function reportPathForPatterns(node, group, importNames, importSource) {
|
||||
// Skip if this is a type-only import and it's allowed
|
||||
if (
|
||||
group.allowTypeImports &&
|
||||
(node.type === "ImportDeclaration" ||
|
||||
node.type === "TSImportEqualsDeclaration") &&
|
||||
isTypeOnlyImport(node)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip if this is a type-only export and it's allowed
|
||||
if (
|
||||
group.allowTypeImports &&
|
||||
(node.type === "ExportNamedDeclaration" ||
|
||||
node.type === "ExportAllDeclaration") &&
|
||||
isTypeOnlyExport(node)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const customMessage = group.customMessage;
|
||||
const restrictedImportNames = group.importNames;
|
||||
@@ -553,6 +667,14 @@ module.exports = {
|
||||
restrictedImportNamePattern.test(importName))
|
||||
) {
|
||||
specifiers.forEach(specifier => {
|
||||
// Skip if this is a type-only import specifier and type imports are allowed
|
||||
if (
|
||||
group.allowTypeImports &&
|
||||
isTypeOnlySpecifier(specifier.specifier)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
node,
|
||||
messageId: customMessage
|
||||
@@ -573,6 +695,14 @@ module.exports = {
|
||||
!allowedImportNames.includes(importName)
|
||||
) {
|
||||
specifiers.forEach(specifier => {
|
||||
// Skip if this is a type-only import specifier and type imports are allowed
|
||||
if (
|
||||
group.allowTypeImports &&
|
||||
isTypeOnlySpecifier(specifier.specifier)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
node,
|
||||
messageId: customMessage
|
||||
@@ -592,6 +722,14 @@ module.exports = {
|
||||
!allowedImportNamePattern.test(importName)
|
||||
) {
|
||||
specifiers.forEach(specifier => {
|
||||
// Skip if this is a type-only import specifier and type imports are allowed
|
||||
if (
|
||||
group.allowTypeImports &&
|
||||
isTypeOnlySpecifier(specifier.specifier)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
node,
|
||||
messageId: customMessage
|
||||
@@ -640,7 +778,7 @@ module.exports = {
|
||||
} else if (node.specifiers) {
|
||||
for (const specifier of node.specifiers) {
|
||||
let name;
|
||||
const specifierData = { loc: specifier.loc };
|
||||
const specifierData = { loc: specifier.loc, specifier };
|
||||
|
||||
if (specifier.type === "ImportDefaultSpecifier") {
|
||||
name = "default";
|
||||
@@ -665,7 +803,12 @@ module.exports = {
|
||||
checkRestrictedPathAndReport(importSource, importNames, node);
|
||||
restrictedPatternGroups.forEach(group => {
|
||||
if (isRestrictedPattern(importSource, group)) {
|
||||
reportPathForPatterns(node, group, importNames);
|
||||
reportPathForPatterns(
|
||||
node,
|
||||
group,
|
||||
importNames,
|
||||
importSource,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -678,6 +821,30 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
ExportAllDeclaration: checkNode,
|
||||
// Add support for TypeScript import equals declarations
|
||||
TSImportEqualsDeclaration(node) {
|
||||
if (node.moduleReference.type === "TSExternalModuleReference") {
|
||||
const importSource = node.moduleReference.expression.value;
|
||||
const importNames = new Map();
|
||||
|
||||
// Use existing logic with the actual node
|
||||
checkRestrictedPathAndReport(
|
||||
importSource,
|
||||
importNames,
|
||||
node,
|
||||
);
|
||||
restrictedPatternGroups.forEach(group => {
|
||||
if (isRestrictedPattern(importSource, group)) {
|
||||
reportPathForPatterns(
|
||||
node,
|
||||
group,
|
||||
importNames,
|
||||
importSource,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user