eslint-plugin-restrict-replace-import 1.5.0 → 2.0.0
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 +35 -4
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +354 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +372 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +36 -22
- package/docs/rules/restrict-import.md +0 -166
- package/eslint.config.mjs +0 -43
- package/lib/index.js +0 -18
- package/lib/rules/restrict-import.js +0 -548
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __esm = (fn, res) => function __init() {
|
|
3
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
4
|
+
};
|
|
5
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
6
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/rules/restrict-import.ts
|
|
10
|
+
var getImportedName, createRestrictedPackagesMap, checkIsRestrictedImport, getPatternDisplayName, getQuoteStyle, formatSpecifiers, createImportText, updateExistingImport, createStringReplacer, createPatternReplacer, createModuleReplacer, createMultiNamedImportReplacer, rule, restrict_import_default;
|
|
11
|
+
var init_restrict_import = __esm({
|
|
12
|
+
"src/rules/restrict-import.ts"() {
|
|
13
|
+
"use strict";
|
|
14
|
+
getImportedName = (imported) => {
|
|
15
|
+
if (imported.type === "Identifier") {
|
|
16
|
+
return imported.name;
|
|
17
|
+
}
|
|
18
|
+
return String(imported.value);
|
|
19
|
+
};
|
|
20
|
+
createRestrictedPackagesMap = (options) => {
|
|
21
|
+
const map = /* @__PURE__ */ new Map();
|
|
22
|
+
options.forEach((config) => {
|
|
23
|
+
if (typeof config === "string") {
|
|
24
|
+
map.set(new RegExp(`^${config}$`), {
|
|
25
|
+
replacement: null,
|
|
26
|
+
namedImports: null
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
map.set(new RegExp(`^${config.target}$`), {
|
|
30
|
+
replacement: config.replacement ?? null,
|
|
31
|
+
namedImports: config.namedImports ?? null
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return map;
|
|
36
|
+
};
|
|
37
|
+
checkIsRestrictedImport = (importSource, namedImports, restrictedPackages) => {
|
|
38
|
+
for (const [pattern, restrictedPackageOptions] of restrictedPackages) {
|
|
39
|
+
if (pattern.test(importSource)) {
|
|
40
|
+
if (!restrictedPackageOptions.namedImports?.length) {
|
|
41
|
+
return {
|
|
42
|
+
type: "module",
|
|
43
|
+
pattern
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const restrictedImportedName = restrictedPackageOptions.namedImports.find(
|
|
47
|
+
(namedImport) => namedImports.includes(namedImport)
|
|
48
|
+
);
|
|
49
|
+
if (restrictedImportedName) {
|
|
50
|
+
return {
|
|
51
|
+
type: "importedName",
|
|
52
|
+
pattern,
|
|
53
|
+
restrictedImportedName
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
60
|
+
getPatternDisplayName = (regExpPatternSource) => regExpPatternSource.slice(1, -1);
|
|
61
|
+
getQuoteStyle = (target) => target?.includes("'") ? "'" : '"';
|
|
62
|
+
formatSpecifiers = (specifiers) => {
|
|
63
|
+
return specifiers.map((s) => s.imported === s.local ? s.imported : `${s.imported} as ${s.local}`).join(", ");
|
|
64
|
+
};
|
|
65
|
+
createImportText = ({ specifiers, source, quote, semicolon = "" }) => {
|
|
66
|
+
const defaultSpecifier = specifiers.find((s) => s.type === "ImportDefaultSpecifier");
|
|
67
|
+
const namespaceSpecifier = specifiers.find((s) => s.type === "ImportNamespaceSpecifier");
|
|
68
|
+
const namedSpecifiers = specifiers.filter((s) => s.type === "ImportSpecifier");
|
|
69
|
+
if (namespaceSpecifier) {
|
|
70
|
+
return `import * as ${namespaceSpecifier.local.name} from ${quote}${source}${quote}${semicolon}`;
|
|
71
|
+
}
|
|
72
|
+
if (defaultSpecifier) {
|
|
73
|
+
if (namedSpecifiers.length === 0) {
|
|
74
|
+
return `import ${defaultSpecifier.local.name} from ${quote}${source}${quote}${semicolon}`;
|
|
75
|
+
}
|
|
76
|
+
const namedText = namedSpecifiers.map((s) => {
|
|
77
|
+
const importedName = getImportedName(s.imported);
|
|
78
|
+
return importedName === s.local.name ? importedName : `${importedName} as ${s.local.name}`;
|
|
79
|
+
}).join(", ");
|
|
80
|
+
return `import ${defaultSpecifier.local.name}, { ${namedText} } from ${quote}${source}${quote}${semicolon}`;
|
|
81
|
+
}
|
|
82
|
+
if (namedSpecifiers.length > 0) {
|
|
83
|
+
const namedText = namedSpecifiers.map((s) => {
|
|
84
|
+
const importedName = getImportedName(s.imported);
|
|
85
|
+
return importedName === s.local.name ? importedName : `${importedName} as ${s.local.name}`;
|
|
86
|
+
}).join(", ");
|
|
87
|
+
return `import { ${namedText} } from ${quote}${source}${quote}${semicolon}`;
|
|
88
|
+
}
|
|
89
|
+
return `import ${quote}${source}${quote}${semicolon}`;
|
|
90
|
+
};
|
|
91
|
+
updateExistingImport = (fixer, sourceCode, existingImport, specifiersToAdd, quote, semicolon, replacement) => {
|
|
92
|
+
const fixes = [];
|
|
93
|
+
const existingNamedSpecifiers = existingImport.specifiers.filter((s) => s.type === "ImportSpecifier").map((s) => getImportedName(s.imported));
|
|
94
|
+
const newSpecifiersToAdd = specifiersToAdd.filter((s) => !existingNamedSpecifiers.includes(s.imported));
|
|
95
|
+
if (newSpecifiersToAdd.length === 0) {
|
|
96
|
+
return fixes;
|
|
97
|
+
}
|
|
98
|
+
const existingText = sourceCode.getText(existingImport);
|
|
99
|
+
const namedSpecifiers = existingImport.specifiers.filter((s) => s.type === "ImportSpecifier");
|
|
100
|
+
if (namedSpecifiers.length > 0) {
|
|
101
|
+
const existingSpecifiersMatch = existingText.match(/import\s*(?:[^{]*,\s*)?{([^}]*)}/);
|
|
102
|
+
if (existingSpecifiersMatch) {
|
|
103
|
+
const existingSpecifiersText = existingSpecifiersMatch[1].trim();
|
|
104
|
+
const newSpecifierText = formatSpecifiers(newSpecifiersToAdd);
|
|
105
|
+
const combinedSpecifiers = `${existingSpecifiersText}, ${newSpecifierText}`;
|
|
106
|
+
const newImportText = existingText.replace(/\{[^}]*\}/, `{ ${combinedSpecifiers} }`);
|
|
107
|
+
fixes.push(fixer.replaceText(existingImport, newImportText));
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
const defaultSpecifier = existingImport.specifiers.find((s) => s.type === "ImportDefaultSpecifier");
|
|
111
|
+
if (defaultSpecifier) {
|
|
112
|
+
const defaultName = defaultSpecifier.local.name;
|
|
113
|
+
const newSpecifiersText = formatSpecifiers(newSpecifiersToAdd);
|
|
114
|
+
const newText = `import ${defaultName}, { ${newSpecifiersText} } from ${quote}${replacement}${quote}${semicolon}`;
|
|
115
|
+
fixes.push(fixer.replaceText(existingImport, newText));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return fixes;
|
|
119
|
+
};
|
|
120
|
+
createStringReplacer = (sourceNode, replacement, quote) => {
|
|
121
|
+
return (fixer) => fixer.replaceText(sourceNode, `${quote}${replacement}${quote}`);
|
|
122
|
+
};
|
|
123
|
+
createPatternReplacer = (sourceNode, replacementPatterns, quote) => {
|
|
124
|
+
return (fixer) => {
|
|
125
|
+
let result = sourceNode.value;
|
|
126
|
+
if (typeof replacementPatterns === "string") {
|
|
127
|
+
return createStringReplacer(sourceNode, replacementPatterns, quote)(fixer);
|
|
128
|
+
}
|
|
129
|
+
for (const [pattern, replacement] of Object.entries(replacementPatterns)) {
|
|
130
|
+
const regex = new RegExp(pattern, "g");
|
|
131
|
+
result = result.replace(regex, replacement);
|
|
132
|
+
}
|
|
133
|
+
return fixer.replaceText(sourceNode, `${quote}${result}${quote}`);
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
createModuleReplacer = (node, replacement) => {
|
|
137
|
+
if (!replacement) return null;
|
|
138
|
+
const quote = getQuoteStyle(node.source.raw);
|
|
139
|
+
if (typeof replacement === "string") {
|
|
140
|
+
return createStringReplacer(node.source, replacement, quote);
|
|
141
|
+
}
|
|
142
|
+
return createPatternReplacer(node.source, replacement, quote);
|
|
143
|
+
};
|
|
144
|
+
createMultiNamedImportReplacer = (context, node, importRestrictions) => {
|
|
145
|
+
return (fixer) => {
|
|
146
|
+
if (!importRestrictions.length) return null;
|
|
147
|
+
const quote = getQuoteStyle(node.source.raw);
|
|
148
|
+
const semicolon = node.source.raw?.endsWith(";") || node.source.value.endsWith(";") ? ";" : "";
|
|
149
|
+
const fixes = [];
|
|
150
|
+
const allRestrictedNames = importRestrictions.map((r) => r.importName);
|
|
151
|
+
const groupedByReplacement = importRestrictions.reduce((acc, restriction) => {
|
|
152
|
+
if (!restriction.replacement) return acc;
|
|
153
|
+
if (!acc[restriction.replacement]) {
|
|
154
|
+
acc[restriction.replacement] = [];
|
|
155
|
+
}
|
|
156
|
+
acc[restriction.replacement].push(restriction.importName);
|
|
157
|
+
return acc;
|
|
158
|
+
}, {});
|
|
159
|
+
const remainingSpecifiers = node.specifiers.filter(
|
|
160
|
+
(specifier) => specifier.type !== "ImportSpecifier" || !allRestrictedNames.includes(getImportedName(specifier.imported))
|
|
161
|
+
);
|
|
162
|
+
if (remainingSpecifiers.length === 0) {
|
|
163
|
+
fixes.push(fixer.remove(node));
|
|
164
|
+
} else {
|
|
165
|
+
const newImportText = createImportText({
|
|
166
|
+
specifiers: remainingSpecifiers,
|
|
167
|
+
source: node.source.value,
|
|
168
|
+
quote,
|
|
169
|
+
semicolon
|
|
170
|
+
});
|
|
171
|
+
fixes.push(fixer.replaceText(node, newImportText));
|
|
172
|
+
}
|
|
173
|
+
const sourceCode = context.sourceCode;
|
|
174
|
+
const allImports = sourceCode.ast.body.filter(
|
|
175
|
+
(n) => n.type === "ImportDeclaration" && n.source.type === "Literal"
|
|
176
|
+
);
|
|
177
|
+
Object.entries(groupedByReplacement).forEach(([replacement, restrictedNames]) => {
|
|
178
|
+
const specifiersToMove = restrictedNames.map((name) => {
|
|
179
|
+
const specifier = node.specifiers.find(
|
|
180
|
+
(s) => s.type === "ImportSpecifier" && getImportedName(s.imported) === name
|
|
181
|
+
);
|
|
182
|
+
return specifier ? {
|
|
183
|
+
imported: getImportedName(specifier.imported),
|
|
184
|
+
local: specifier.local.name
|
|
185
|
+
} : null;
|
|
186
|
+
}).filter((s) => s !== null);
|
|
187
|
+
if (specifiersToMove.length === 0) return;
|
|
188
|
+
const existingReplacementImport = allImports.find((importNode) => importNode.source.value === replacement);
|
|
189
|
+
if (existingReplacementImport) {
|
|
190
|
+
fixes.push(
|
|
191
|
+
...updateExistingImport(
|
|
192
|
+
fixer,
|
|
193
|
+
sourceCode,
|
|
194
|
+
existingReplacementImport,
|
|
195
|
+
specifiersToMove,
|
|
196
|
+
quote,
|
|
197
|
+
semicolon,
|
|
198
|
+
replacement
|
|
199
|
+
)
|
|
200
|
+
);
|
|
201
|
+
} else {
|
|
202
|
+
const newSpecifiersText = formatSpecifiers(specifiersToMove);
|
|
203
|
+
const newImport = `import { ${newSpecifiersText} } from ${quote}${replacement}${quote}${semicolon}`;
|
|
204
|
+
fixes.push(fixer.insertTextBefore(node, newImport + "\n"));
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
return fixes;
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
rule = {
|
|
211
|
+
meta: {
|
|
212
|
+
type: "problem",
|
|
213
|
+
docs: {
|
|
214
|
+
description: "Prevent the Import of a Specific Package",
|
|
215
|
+
recommended: false,
|
|
216
|
+
url: "https://github.com/custardcream98/eslint-plugin-restrict-replace-import/blob/main/docs/rules/restrict-import.md"
|
|
217
|
+
},
|
|
218
|
+
fixable: "code",
|
|
219
|
+
messages: {
|
|
220
|
+
ImportRestriction: "`{{ name }}` is restricted from being used.",
|
|
221
|
+
ImportRestrictionWithReplacement: "`{{ name }}` is restricted from being used. Replace it with `{{ replacement }}`.",
|
|
222
|
+
ImportedNameRestriction: "Import of '{{importedName}}' from '{{name}}' is restricted",
|
|
223
|
+
ImportedNameRestrictionWithReplacement: "Import of '{{importedName}}' from '{{name}}' is restricted. Replace it with '{{replacement}}'."
|
|
224
|
+
},
|
|
225
|
+
schema: [
|
|
226
|
+
{
|
|
227
|
+
type: "array",
|
|
228
|
+
items: {
|
|
229
|
+
oneOf: [
|
|
230
|
+
{
|
|
231
|
+
type: "string"
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
type: "object",
|
|
235
|
+
properties: {
|
|
236
|
+
target: {
|
|
237
|
+
type: "string",
|
|
238
|
+
description: "The target of the import to be restricted"
|
|
239
|
+
},
|
|
240
|
+
namedImports: {
|
|
241
|
+
type: "array",
|
|
242
|
+
items: { type: "string" },
|
|
243
|
+
description: "The named imports to be restricted. If not provided, all named imports will be restricted."
|
|
244
|
+
},
|
|
245
|
+
replacement: {
|
|
246
|
+
oneOf: [
|
|
247
|
+
{ type: "string" },
|
|
248
|
+
{
|
|
249
|
+
type: "object",
|
|
250
|
+
patternProperties: {
|
|
251
|
+
".*": { type: "string" }
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
],
|
|
255
|
+
description: "The replacement for the import. If a string is provided, it will be used as the replacement for all imports. If an object is provided, the keys will be used as the pattern and the values will be used as the replacement."
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
required: ["target"],
|
|
259
|
+
additionalProperties: false
|
|
260
|
+
}
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
]
|
|
265
|
+
},
|
|
266
|
+
create(context) {
|
|
267
|
+
const options = context.options;
|
|
268
|
+
const restrictedPackages = createRestrictedPackagesMap(options[0]);
|
|
269
|
+
return {
|
|
270
|
+
ImportDeclaration(node) {
|
|
271
|
+
const importNode = node;
|
|
272
|
+
if (importNode.source.type !== "Literal") return;
|
|
273
|
+
const importSource = importNode.source.value;
|
|
274
|
+
const namedImports = importNode.specifiers.filter((specifier) => specifier.type === "ImportSpecifier").map((specifier) => getImportedName(specifier.imported));
|
|
275
|
+
const checkerResult = checkIsRestrictedImport(importSource, namedImports, restrictedPackages);
|
|
276
|
+
if (!checkerResult) return;
|
|
277
|
+
const restrictedPackageOptions = restrictedPackages.get(checkerResult.pattern);
|
|
278
|
+
if (!restrictedPackageOptions) return;
|
|
279
|
+
const patternName = getPatternDisplayName(checkerResult.pattern.source);
|
|
280
|
+
if (checkerResult.type === "module") {
|
|
281
|
+
context.report({
|
|
282
|
+
node,
|
|
283
|
+
messageId: typeof restrictedPackageOptions.replacement === "string" ? "ImportRestrictionWithReplacement" : "ImportRestriction",
|
|
284
|
+
data: {
|
|
285
|
+
name: patternName,
|
|
286
|
+
replacement: restrictedPackageOptions.replacement
|
|
287
|
+
},
|
|
288
|
+
fix: createModuleReplacer(importNode, restrictedPackageOptions.replacement)
|
|
289
|
+
});
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
const importRestrictions = [];
|
|
293
|
+
namedImports.forEach((importName) => {
|
|
294
|
+
for (const [pattern, patternOptions] of restrictedPackages.entries()) {
|
|
295
|
+
if (pattern.test(importSource) && patternOptions.namedImports && patternOptions.namedImports.includes(importName) && // TODO: handle options.replacement as an object
|
|
296
|
+
(typeof patternOptions.replacement === "string" || patternOptions.replacement === null)) {
|
|
297
|
+
importRestrictions.push({
|
|
298
|
+
importName,
|
|
299
|
+
replacement: patternOptions.replacement,
|
|
300
|
+
pattern
|
|
301
|
+
});
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
if (importRestrictions.length === 0) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
importRestrictions.forEach((restriction) => {
|
|
310
|
+
context.report({
|
|
311
|
+
node,
|
|
312
|
+
messageId: restriction.replacement ? "ImportedNameRestrictionWithReplacement" : "ImportedNameRestriction",
|
|
313
|
+
data: {
|
|
314
|
+
importedName: restriction.importName,
|
|
315
|
+
name: importSource,
|
|
316
|
+
replacement: restriction.replacement ?? ""
|
|
317
|
+
},
|
|
318
|
+
fix: restriction.replacement ? createMultiNamedImportReplacer(context, importNode, importRestrictions) : null
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
restrict_import_default = rule;
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// src/index.ts
|
|
330
|
+
var require_index = __commonJS({
|
|
331
|
+
"src/index.ts"(exports, module) {
|
|
332
|
+
init_restrict_import();
|
|
333
|
+
var name = "eslint-plugin-restrict-replace-import";
|
|
334
|
+
var version = "2.0.0";
|
|
335
|
+
var rules = {
|
|
336
|
+
"restrict-import": restrict_import_default
|
|
337
|
+
};
|
|
338
|
+
var configs = {
|
|
339
|
+
recommended: {
|
|
340
|
+
plugins: ["restrict-replace-import"],
|
|
341
|
+
rules: {
|
|
342
|
+
"restrict-replace-import/restrict-import": "error"
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
var flatConfigs = {
|
|
347
|
+
recommended: {
|
|
348
|
+
plugins: {
|
|
349
|
+
"restrict-replace-import": {
|
|
350
|
+
meta: { name, version },
|
|
351
|
+
rules
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
rules: {
|
|
355
|
+
"restrict-replace-import/restrict-import": "error"
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
var plugin = {
|
|
360
|
+
meta: {
|
|
361
|
+
name,
|
|
362
|
+
version
|
|
363
|
+
},
|
|
364
|
+
rules,
|
|
365
|
+
configs,
|
|
366
|
+
flatConfigs
|
|
367
|
+
};
|
|
368
|
+
module.exports = plugin;
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
export default require_index();
|
|
372
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rules/restrict-import.ts","../src/index.ts"],"sourcesContent":["import type { Rule, SourceCode } from 'eslint'\nimport type { Identifier, ImportDeclaration, ImportSpecifier, Literal } from 'estree'\n\ntype Replacement = string | Record<string, string>\n\n/**\n * Get the name of an import specifier's imported binding.\n * Handles both Identifier (e.g., `import { foo }`) and Literal (e.g., `import { \"foo\" as bar }`)\n */\nconst getImportedName = (imported: Identifier | Literal): string => {\n if (imported.type === 'Identifier') {\n return imported.name\n }\n // For string literals in imports (e.g., import { \"string-name\" as alias })\n return String(imported.value)\n}\n\ninterface ImportRestrictionOptions {\n replacement: Replacement | null\n namedImports: string[] | null\n}\n\ninterface RestrictedImportCheckResult {\n type: 'module' | 'importedName'\n pattern: RegExp\n restrictedImportedName?: string\n}\n\ninterface ImportRestriction {\n importName: string\n replacement: string | null\n pattern: RegExp\n}\n\ninterface SpecifierInfo {\n imported: string\n local: string\n}\n\ntype QuoteStyle = '\"' | \"'\"\n\nconst createRestrictedPackagesMap = (\n options: Array<string | { target: string; replacement?: Replacement; namedImports?: string[] }>,\n): Map<RegExp, ImportRestrictionOptions> => {\n const map = new Map<RegExp, ImportRestrictionOptions>()\n\n options.forEach((config) => {\n if (typeof config === 'string') {\n map.set(new RegExp(`^${config}$`), {\n replacement: null,\n namedImports: null,\n })\n } else {\n map.set(new RegExp(`^${config.target}$`), {\n replacement: config.replacement ?? null,\n namedImports: config.namedImports ?? null,\n })\n }\n })\n\n return map\n}\n\nconst checkIsRestrictedImport = (\n importSource: string,\n namedImports: string[],\n restrictedPackages: Map<RegExp, ImportRestrictionOptions>,\n): RestrictedImportCheckResult | null => {\n for (const [pattern, restrictedPackageOptions] of restrictedPackages) {\n if (pattern.test(importSource)) {\n if (!restrictedPackageOptions.namedImports?.length) {\n return {\n type: 'module',\n pattern,\n }\n }\n\n const restrictedImportedName = restrictedPackageOptions.namedImports.find((namedImport) =>\n namedImports.includes(namedImport),\n )\n if (restrictedImportedName) {\n return {\n type: 'importedName',\n pattern,\n restrictedImportedName,\n }\n }\n }\n }\n return null\n}\n\n/**\n * Strip the beginning and ending of RegExp pattern (e.g. ^pattern$ -> pattern)\n */\nconst getPatternDisplayName = (regExpPatternSource: string): string => regExpPatternSource.slice(1, -1)\n\nconst getQuoteStyle = (target: string | undefined): QuoteStyle => (target?.includes(\"'\") ? \"'\" : '\"')\n\n/**\n * Format a list of import specifiers as a string\n */\nconst formatSpecifiers = (specifiers: SpecifierInfo[]): string => {\n return specifiers.map((s) => (s.imported === s.local ? s.imported : `${s.imported} as ${s.local}`)).join(', ')\n}\n\ninterface CreateImportTextOptions {\n specifiers: ImportDeclaration['specifiers']\n source: string\n quote: QuoteStyle\n semicolon?: string\n}\n\n/**\n * Creates the text for a new import statement\n */\nconst createImportText = ({ specifiers, source, quote, semicolon = '' }: CreateImportTextOptions): string => {\n const defaultSpecifier = specifiers.find((s) => s.type === 'ImportDefaultSpecifier')\n const namespaceSpecifier = specifiers.find((s) => s.type === 'ImportNamespaceSpecifier')\n const namedSpecifiers = specifiers.filter((s): s is ImportSpecifier => s.type === 'ImportSpecifier')\n\n if (namespaceSpecifier) {\n return `import * as ${namespaceSpecifier.local.name} from ${quote}${source}${quote}${semicolon}`\n }\n\n if (defaultSpecifier) {\n if (namedSpecifiers.length === 0) {\n return `import ${defaultSpecifier.local.name} from ${quote}${source}${quote}${semicolon}`\n }\n\n const namedText = namedSpecifiers\n .map((s) => {\n const importedName = getImportedName(s.imported)\n return importedName === s.local.name ? importedName : `${importedName} as ${s.local.name}`\n })\n .join(', ')\n\n return `import ${defaultSpecifier.local.name}, { ${namedText} } from ${quote}${source}${quote}${semicolon}`\n }\n\n if (namedSpecifiers.length > 0) {\n const namedText = namedSpecifiers\n .map((s) => {\n const importedName = getImportedName(s.imported)\n return importedName === s.local.name ? importedName : `${importedName} as ${s.local.name}`\n })\n .join(', ')\n\n return `import { ${namedText} } from ${quote}${source}${quote}${semicolon}`\n }\n\n return `import ${quote}${source}${quote}${semicolon}`\n}\n\n/**\n * Updates an existing import with new specifiers\n */\nconst updateExistingImport = (\n fixer: Rule.RuleFixer,\n sourceCode: SourceCode,\n existingImport: ImportDeclaration,\n specifiersToAdd: SpecifierInfo[],\n quote: QuoteStyle,\n semicolon: string,\n replacement: string,\n): Rule.Fix[] => {\n const fixes: Rule.Fix[] = []\n const existingNamedSpecifiers = existingImport.specifiers\n .filter((s): s is ImportSpecifier => s.type === 'ImportSpecifier')\n .map((s) => getImportedName(s.imported))\n\n const newSpecifiersToAdd = specifiersToAdd.filter((s) => !existingNamedSpecifiers.includes(s.imported))\n\n if (newSpecifiersToAdd.length === 0) {\n return fixes\n }\n\n const existingText = sourceCode.getText(existingImport)\n const namedSpecifiers = existingImport.specifiers.filter((s): s is ImportSpecifier => s.type === 'ImportSpecifier')\n\n if (namedSpecifiers.length > 0) {\n // Add new specifiers to existing named imports\n const existingSpecifiersMatch = existingText.match(/import\\s*(?:[^{]*,\\s*)?{([^}]*)}/)\n if (existingSpecifiersMatch) {\n const existingSpecifiersText = existingSpecifiersMatch[1].trim()\n const newSpecifierText = formatSpecifiers(newSpecifiersToAdd)\n const combinedSpecifiers = `${existingSpecifiersText}, ${newSpecifierText}`\n const newImportText = existingText.replace(/\\{[^}]*\\}/, `{ ${combinedSpecifiers} }`)\n fixes.push(fixer.replaceText(existingImport, newImportText))\n }\n } else {\n // Handle imports with default but no named imports\n const defaultSpecifier = existingImport.specifiers.find((s) => s.type === 'ImportDefaultSpecifier')\n if (defaultSpecifier) {\n const defaultName = defaultSpecifier.local.name\n const newSpecifiersText = formatSpecifiers(newSpecifiersToAdd)\n const newText = `import ${defaultName}, { ${newSpecifiersText} } from ${quote}${replacement}${quote}${semicolon}`\n fixes.push(fixer.replaceText(existingImport, newText))\n }\n }\n\n return fixes\n}\n\nconst createStringReplacer = (\n sourceNode: ImportDeclaration['source'],\n replacement: string,\n quote: QuoteStyle,\n): ((fixer: Rule.RuleFixer) => Rule.Fix) => {\n return (fixer) => fixer.replaceText(sourceNode, `${quote}${replacement}${quote}`)\n}\n\nconst createPatternReplacer = (\n sourceNode: ImportDeclaration['source'],\n replacementPatterns: Replacement,\n quote: QuoteStyle,\n): ((fixer: Rule.RuleFixer) => Rule.Fix) => {\n return (fixer) => {\n let result = sourceNode.value as string\n\n if (typeof replacementPatterns === 'string') {\n return createStringReplacer(sourceNode, replacementPatterns, quote)(fixer)\n }\n\n for (const [pattern, replacement] of Object.entries(replacementPatterns)) {\n const regex = new RegExp(pattern, 'g')\n result = result.replace(regex, replacement)\n }\n return fixer.replaceText(sourceNode, `${quote}${result}${quote}`)\n }\n}\n\nconst createModuleReplacer = (\n node: ImportDeclaration,\n replacement: Replacement | null,\n): ((fixer: Rule.RuleFixer) => Rule.Fix) | null => {\n if (!replacement) return null\n\n const quote = getQuoteStyle(node.source.raw)\n\n if (typeof replacement === 'string') {\n return createStringReplacer(node.source, replacement, quote)\n }\n\n return createPatternReplacer(node.source, replacement, quote)\n}\n\nconst createMultiNamedImportReplacer = (\n context: Rule.RuleContext,\n node: ImportDeclaration,\n importRestrictions: ImportRestriction[],\n): ((fixer: Rule.RuleFixer) => Rule.Fix[] | null) => {\n return (fixer) => {\n if (!importRestrictions.length) return null\n\n const quote = getQuoteStyle(node.source.raw)\n const semicolon = node.source.raw?.endsWith(';') || (node.source.value as string).endsWith(';') ? ';' : ''\n const fixes: Rule.Fix[] = []\n\n const allRestrictedNames = importRestrictions.map((r) => r.importName)\n\n // Group imports by replacement\n const groupedByReplacement = importRestrictions.reduce<Record<string, string[]>>((acc, restriction) => {\n if (!restriction.replacement) return acc\n\n if (!acc[restriction.replacement]) {\n acc[restriction.replacement] = []\n }\n\n acc[restriction.replacement].push(restriction.importName)\n\n return acc\n }, {})\n\n // Find non-restricted specifiers from the original import\n const remainingSpecifiers = node.specifiers.filter(\n (specifier) =>\n specifier.type !== 'ImportSpecifier' ||\n !allRestrictedNames.includes(getImportedName((specifier as ImportSpecifier).imported)),\n )\n\n // Update or remove the original import\n if (remainingSpecifiers.length === 0) {\n fixes.push(fixer.remove(node))\n } else {\n const newImportText = createImportText({\n specifiers: remainingSpecifiers,\n source: node.source.value as string,\n quote,\n semicolon,\n })\n fixes.push(fixer.replaceText(node, newImportText))\n }\n\n // Create new imports for each replacement module\n const sourceCode = context.sourceCode\n const allImports = sourceCode.ast.body.filter(\n (n): n is ImportDeclaration => n.type === 'ImportDeclaration' && n.source.type === 'Literal',\n )\n\n // Process each replacement module\n Object.entries(groupedByReplacement).forEach(([replacement, restrictedNames]) => {\n // Find specifiers to move\n const specifiersToMove = restrictedNames\n .map((name) => {\n const specifier = node.specifiers.find(\n (s): s is ImportSpecifier => s.type === 'ImportSpecifier' && getImportedName(s.imported) === name,\n )\n return specifier\n ? {\n imported: getImportedName(specifier.imported),\n local: specifier.local.name,\n }\n : null\n })\n .filter((s): s is SpecifierInfo => s !== null)\n\n if (specifiersToMove.length === 0) return\n\n // Find existing import for the same replacement module\n const existingReplacementImport = allImports.find((importNode) => importNode.source.value === replacement)\n\n if (existingReplacementImport) {\n // Add to existing import\n fixes.push(\n ...updateExistingImport(\n fixer,\n sourceCode,\n existingReplacementImport,\n specifiersToMove,\n quote,\n semicolon,\n replacement,\n ),\n )\n } else {\n // Create new import\n const newSpecifiersText = formatSpecifiers(specifiersToMove)\n const newImport = `import { ${newSpecifiersText} } from ${quote}${replacement}${quote}${semicolon}`\n fixes.push(fixer.insertTextBefore(node, newImport + '\\n'))\n }\n })\n\n return fixes\n }\n}\n\ntype RuleOptions = [Array<string | { target: string; replacement?: Replacement; namedImports?: string[] }>]\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: {\n description: 'Prevent the Import of a Specific Package',\n recommended: false,\n url: 'https://github.com/custardcream98/eslint-plugin-restrict-replace-import/blob/main/docs/rules/restrict-import.md',\n },\n fixable: 'code',\n\n messages: {\n ImportRestriction: '`{{ name }}` is restricted from being used.',\n ImportRestrictionWithReplacement:\n '`{{ name }}` is restricted from being used. Replace it with `{{ replacement }}`.',\n ImportedNameRestriction: \"Import of '{{importedName}}' from '{{name}}' is restricted\",\n ImportedNameRestrictionWithReplacement:\n \"Import of '{{importedName}}' from '{{name}}' is restricted. Replace it with '{{replacement}}'.\",\n },\n\n schema: [\n {\n type: 'array',\n items: {\n oneOf: [\n {\n type: 'string',\n },\n {\n type: 'object',\n properties: {\n target: {\n type: 'string',\n description: 'The target of the import to be restricted',\n },\n namedImports: {\n type: 'array',\n items: { type: 'string' },\n description:\n 'The named imports to be restricted. If not provided, all named imports will be restricted.',\n },\n replacement: {\n oneOf: [\n { type: 'string' },\n {\n type: 'object',\n patternProperties: {\n '.*': { type: 'string' },\n },\n },\n ],\n description:\n 'The replacement for the import. If a string is provided, it will be used as the replacement for all imports. If an object is provided, the keys will be used as the pattern and the values will be used as the replacement.',\n },\n },\n required: ['target'],\n additionalProperties: false,\n },\n ],\n },\n },\n ],\n },\n\n create(context) {\n const options = context.options as RuleOptions\n const restrictedPackages = createRestrictedPackagesMap(options[0])\n\n return {\n ImportDeclaration(node) {\n const importNode = node as unknown as ImportDeclaration\n if (importNode.source.type !== 'Literal') return\n\n const importSource = importNode.source.value as string\n const namedImports = importNode.specifiers\n .filter((specifier): specifier is ImportSpecifier => specifier.type === 'ImportSpecifier')\n .map((specifier) => getImportedName(specifier.imported))\n const checkerResult = checkIsRestrictedImport(importSource, namedImports, restrictedPackages)\n\n if (!checkerResult) return\n\n const restrictedPackageOptions = restrictedPackages.get(checkerResult.pattern)\n if (!restrictedPackageOptions) return\n\n const patternName = getPatternDisplayName(checkerResult.pattern.source)\n\n if (checkerResult.type === 'module') {\n context.report({\n node,\n messageId:\n typeof restrictedPackageOptions.replacement === 'string'\n ? 'ImportRestrictionWithReplacement'\n : 'ImportRestriction',\n data: {\n name: patternName,\n replacement: restrictedPackageOptions.replacement as string,\n },\n fix: createModuleReplacer(importNode, restrictedPackageOptions.replacement),\n })\n return\n }\n\n // Find potential rules and replacement mappings for multiple restricted named imports\n const importRestrictions: ImportRestriction[] = []\n\n // Check each named import for restrictions\n namedImports.forEach((importName) => {\n for (const [pattern, patternOptions] of restrictedPackages.entries()) {\n if (\n pattern.test(importSource) &&\n patternOptions.namedImports &&\n patternOptions.namedImports.includes(importName) &&\n // TODO: handle options.replacement as an object\n (typeof patternOptions.replacement === 'string' || patternOptions.replacement === null)\n ) {\n importRestrictions.push({\n importName,\n replacement: patternOptions.replacement,\n pattern,\n })\n\n break // Only use the first matching restriction for an import\n }\n }\n })\n\n if (importRestrictions.length === 0) {\n return\n }\n\n // Report separate errors for each restricted import\n importRestrictions.forEach((restriction) => {\n context.report({\n node,\n messageId: restriction.replacement ? 'ImportedNameRestrictionWithReplacement' : 'ImportedNameRestriction',\n data: {\n importedName: restriction.importName,\n name: importSource,\n replacement: restriction.replacement ?? '',\n },\n fix: restriction.replacement\n ? createMultiNamedImportReplacer(context, importNode, importRestrictions)\n : null,\n })\n })\n },\n }\n },\n}\n\nexport default rule\n","import type { ESLint, Linter, Rule } from 'eslint'\nimport restrictImport from './rules/restrict-import'\n\n// Read version from package.json at build time\nconst name = 'eslint-plugin-restrict-replace-import'\nconst version = '2.0.0'\n\nconst rules: Record<string, Rule.RuleModule> = {\n 'restrict-import': restrictImport,\n}\n\n// Legacy config (ESLint < 9)\nconst configs: Record<string, Linter.LegacyConfig> = {\n recommended: {\n plugins: ['restrict-replace-import'],\n rules: {\n 'restrict-replace-import/restrict-import': 'error',\n },\n },\n}\n\n// ESLint v9+ flat configs\nconst flatConfigs: Record<string, Linter.Config> = {\n recommended: {\n plugins: {\n 'restrict-replace-import': {\n meta: { name, version },\n rules,\n },\n },\n rules: {\n 'restrict-replace-import/restrict-import': 'error',\n },\n },\n}\n\nconst plugin: ESLint.Plugin & {\n configs: typeof configs\n flatConfigs: typeof flatConfigs\n} = {\n meta: {\n name,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AAS;AAAA,UACP,2BAA2B;AAAA,YACzB,MAAM,EAAE,MAAM,QAAQ;AAAA,YACtB;AAAA,UACF;AAAA,QACF;AAAA,QACA,OAAO;AAAA,UACL,2CAA2C;AAAA,QAC7C;AAAA,MACF;AAAA,IACF;AAEA,QAAM,SAGF;AAAA,MACF,MAAM;AAAA,QACJ;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAEA,qBAAS;AAAA;AAAA;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-restrict-replace-import",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "ESLint Plugin for Restricting and Replacing Import",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -17,36 +17,50 @@
|
|
|
17
17
|
"type": "git",
|
|
18
18
|
"url": "git+https://github.com/custardcream98/eslint-plugin-restrict-replace-import.git"
|
|
19
19
|
},
|
|
20
|
-
"main": "./
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"release": "npm run lint && npm run test && npm publish"
|
|
30
|
-
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"requireindex": "^1.2.0"
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"module": "./dist/index.mjs",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"require": "./dist/index.js",
|
|
27
|
+
"import": "./dist/index.mjs"
|
|
28
|
+
}
|
|
33
29
|
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
34
33
|
"devDependencies": {
|
|
35
34
|
"@eslint/compat": "^1.2.7",
|
|
35
|
+
"@types/eslint": "^9.6.1",
|
|
36
36
|
"@types/estree": "^1.0.6",
|
|
37
|
+
"@types/node": "^22.10.5",
|
|
37
38
|
"eslint": "^9.22.0",
|
|
38
39
|
"eslint-doc-generator": "^2.1.0",
|
|
39
40
|
"eslint-plugin-eslint-plugin": "^6.4.0",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
41
|
+
"globals": "^16.0.0",
|
|
42
|
+
"prettier": "^3.5.3",
|
|
43
|
+
"tsup": "^8.3.5",
|
|
44
|
+
"typescript": "^5.7.3",
|
|
45
|
+
"typescript-eslint": "^8.21.0",
|
|
46
|
+
"vitest": "^3.0.4"
|
|
44
47
|
},
|
|
45
48
|
"engines": {
|
|
46
|
-
"node": "
|
|
49
|
+
"node": ">=18.0.0"
|
|
47
50
|
},
|
|
48
51
|
"peerDependencies": {
|
|
49
|
-
"eslint": ">=
|
|
52
|
+
"eslint": ">=8"
|
|
50
53
|
},
|
|
51
|
-
"license": "ISC"
|
|
52
|
-
|
|
54
|
+
"license": "ISC",
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup",
|
|
57
|
+
"format": "prettier --write .",
|
|
58
|
+
"lint": "pnpm lint:eslint-docs && pnpm lint:js",
|
|
59
|
+
"lint:eslint-docs": "eslint-doc-generator --check",
|
|
60
|
+
"lint:js": "eslint .",
|
|
61
|
+
"test": "vitest run",
|
|
62
|
+
"test:watch": "vitest",
|
|
63
|
+
"update:eslint-docs": "eslint-doc-generator",
|
|
64
|
+
"release": "pnpm lint && pnpm test && pnpm publish"
|
|
65
|
+
}
|
|
66
|
+
}
|