eslint-plugin-import-next 2.3.14 → 2.3.16

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.
Files changed (62) hide show
  1. package/package.json +9 -4
  2. package/src/files/foo.js +1 -6
  3. package/src/files/no-default.js +1 -4
  4. package/src/index.js +1 -326
  5. package/src/oxlint.js +1 -3
  6. package/src/rules/consistent-type-specifier-style.js +1 -109
  7. package/src/rules/default.js +1 -56
  8. package/src/rules/dynamic-import-chunkname.js +1 -115
  9. package/src/rules/enforce-dependency-direction.js +1 -213
  10. package/src/rules/enforce-import-order.js +1 -299
  11. package/src/rules/enforce-team-boundaries.js +1 -191
  12. package/src/rules/export.js +1 -111
  13. package/src/rules/exports-last.js +1 -67
  14. package/src/rules/extensions.js +1 -105
  15. package/src/rules/first.js +1 -53
  16. package/src/rules/group-exports.js +1 -69
  17. package/src/rules/max-dependencies.js +1 -241
  18. package/src/rules/named.js +1 -67
  19. package/src/rules/namespace.js +1 -64
  20. package/src/rules/newline-after-import.js +1 -57
  21. package/src/rules/no-absolute-path.js +1 -107
  22. package/src/rules/no-amd.js +1 -108
  23. package/src/rules/no-anonymous-default-export.js +1 -135
  24. package/src/rules/no-barrel-file.js +1 -194
  25. package/src/rules/no-barrel-import.js +1 -135
  26. package/src/rules/no-commonjs.js +1 -312
  27. package/src/rules/no-cross-domain-imports.js +1 -233
  28. package/src/rules/no-cycle.js +2 -396
  29. package/src/rules/no-default-export.js +2 -213
  30. package/src/rules/no-deprecated.js +1 -316
  31. package/src/rules/no-duplicates.js +1 -81
  32. package/src/rules/no-dynamic-require.js +1 -78
  33. package/src/rules/no-empty-named-blocks.js +1 -103
  34. package/src/rules/no-extraneous-dependencies.js +7 -385
  35. package/src/rules/no-full-package-import.js +1 -134
  36. package/src/rules/no-import-module-exports.js +1 -76
  37. package/src/rules/no-internal-modules.js +1 -256
  38. package/src/rules/no-legacy-imports.js +1 -125
  39. package/src/rules/no-mutable-exports.js +1 -146
  40. package/src/rules/no-named-as-default-member.js +1 -73
  41. package/src/rules/no-named-as-default.js +1 -90
  42. package/src/rules/no-named-default.js +1 -48
  43. package/src/rules/no-named-export.js +1 -174
  44. package/src/rules/no-namespace.js +1 -71
  45. package/src/rules/no-nodejs-modules.js +1 -229
  46. package/src/rules/no-relative-packages.js +1 -129
  47. package/src/rules/no-relative-parent-imports.js +1 -118
  48. package/src/rules/no-restricted-paths.js +1 -89
  49. package/src/rules/no-self-import.js +1 -113
  50. package/src/rules/no-unassigned-import.js +1 -115
  51. package/src/rules/no-unresolved.js +1 -189
  52. package/src/rules/no-unused-modules.js +1 -82
  53. package/src/rules/no-useless-path-segments.js +1 -107
  54. package/src/rules/prefer-default-export.js +1 -188
  55. package/src/rules/prefer-direct-import.js +1 -170
  56. package/src/rules/prefer-modern-api.js +1 -212
  57. package/src/rules/prefer-node-protocol.js +1 -174
  58. package/src/rules/prefer-tree-shakeable-imports.js +1 -134
  59. package/src/rules/require-import-approval.js +1 -174
  60. package/src/rules/unambiguous.js +1 -70
  61. package/src/types/index.js +1 -2
  62. package/src/utils/typescript-peer.js +1 -23
@@ -1,316 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noDeprecated = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.noDeprecated = (0, eslint_devkit_1.createRule)({
7
- name: 'no-deprecated',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-deprecated.md',
12
- description: 'Forbid imported names marked with @deprecated documentation tag',
13
- },
14
- hasSuggestions: true,
15
- messages: {
16
- deprecatedImport: (0, eslint_devkit_2.formatLLMMessage)({
17
- icon: eslint_devkit_2.MessageIcons.WARNING,
18
- issueName: 'Deprecated Import',
19
- description: 'Importing deprecated API that should be avoided',
20
- severity: 'MEDIUM',
21
- fix: 'Replace with recommended alternative or remove if no longer needed',
22
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-deprecated.md',
23
- }),
24
- deprecatedExport: (0, eslint_devkit_2.formatLLMMessage)({
25
- icon: eslint_devkit_2.MessageIcons.WARNING,
26
- issueName: 'Deprecated Export Usage',
27
- description: 'Using deprecated exported member',
28
- severity: 'MEDIUM',
29
- fix: 'Update to use the recommended replacement API',
30
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-deprecated.md',
31
- }),
32
- deprecatedUsage: (0, eslint_devkit_2.formatLLMMessage)({
33
- icon: eslint_devkit_2.MessageIcons.WARNING,
34
- issueName: 'Deprecated API Usage',
35
- description: 'Using deprecated function or method',
36
- severity: 'MEDIUM',
37
- fix: 'Migrate to the recommended modern API',
38
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-deprecated.md',
39
- }),
40
- },
41
- schema: [
42
- {
43
- type: 'object',
44
- properties: {
45
- allow: {
46
- type: 'array',
47
- items: { type: 'string' },
48
- description: 'List of deprecated items that are allowed (for migration periods)',
49
- },
50
- deprecationMarkers: {
51
- type: 'array',
52
- items: { type: 'string' },
53
- default: ['@deprecated'],
54
- description: 'Custom deprecation markers to look for in comments',
55
- },
56
- checkJSDoc: {
57
- type: 'boolean',
58
- default: true,
59
- description: 'Check for @deprecated in JSDoc comments',
60
- },
61
- checkDecorators: {
62
- type: 'boolean',
63
- default: true,
64
- description: 'Check for @deprecated decorator in TypeScript',
65
- },
66
- },
67
- additionalProperties: false,
68
- },
69
- ],
70
- },
71
- defaultOptions: [
72
- {
73
- allow: [],
74
- deprecationMarkers: ['@deprecated'],
75
- checkJSDoc: true,
76
- checkDecorators: true,
77
- },
78
- ],
79
- create(context) {
80
- const [options] = context.options;
81
- const { allow = [], deprecationMarkers = ['@deprecated'], checkJSDoc = true, checkDecorators = true, } = options || {};
82
- const filename = context.filename;
83
- if (!filename) {
84
- return {};
85
- }
86
- const deprecatedItems = new Map();
87
- function isAllowed(name) {
88
- return allow.includes(name);
89
- }
90
- function parseJSDocDeprecated(comment) {
91
- const lines = comment.split('\n');
92
- for (const line of lines) {
93
- const trimmed = line.trim();
94
- for (const marker of deprecationMarkers) {
95
- if (trimmed.includes(marker)) {
96
- const afterMarker = trimmed
97
- .substring(trimmed.indexOf(marker) + marker.length)
98
- .trim();
99
- let reason;
100
- let replacement;
101
- const insteadMatch = afterMarker.match(/(?:use|replaced by|see)\s+([^\s]+(?:\s+[^\s]+)*?)(?:\s|$)/i);
102
- if (insteadMatch) {
103
- replacement = insteadMatch[1]
104
- .trim()
105
- .replace(/\s+instead$|\s+or$|\s+as$|\s+with$/i, '');
106
- }
107
- const reasonText = afterMarker
108
- .replace(/use\s+[^.]*[.]?/i, '')
109
- .replace(/replaced by\s+[^.]*[.]?/i, '')
110
- .trim();
111
- if (reasonText) {
112
- reason = reasonText;
113
- }
114
- return { deprecated: true, reason, replacement };
115
- }
116
- }
117
- }
118
- return { deprecated: false };
119
- }
120
- function checkComments(node, name) {
121
- if (!checkJSDoc)
122
- return;
123
- const sourceCode = context.sourceCode;
124
- const comments = sourceCode.getCommentsBefore(node);
125
- const allComments = [...comments];
126
- if ('leadingComments' in node && Array.isArray(node.leadingComments)) {
127
- allComments.push(...node.leadingComments);
128
- }
129
- for (const comment of allComments) {
130
- if (comment.type === 'Block' && comment.value.includes('*')) {
131
- const deprecationInfo = parseJSDocDeprecated(comment.value);
132
- if (deprecationInfo.deprecated) {
133
- deprecatedItems.set(name, {
134
- location: node,
135
- reason: deprecationInfo.reason,
136
- replacement: deprecationInfo.replacement,
137
- });
138
- break;
139
- }
140
- }
141
- }
142
- }
143
- function checkDecoratorsForDeprecation(node, name) {
144
- if (!checkDecorators)
145
- return;
146
- if ('decorators' in node &&
147
- Array.isArray(node.decorators)) {
148
- const decorators = node.decorators;
149
- for (const decorator of decorators) {
150
- const dec = decorator;
151
- if ((dec.expression.type === 'CallExpression' &&
152
- dec.expression.callee.type === 'Identifier' &&
153
- dec.expression.callee.name === 'deprecated') ||
154
- (dec.expression.type === 'Identifier' &&
155
- dec.expression.name === 'deprecated')) {
156
- deprecatedItems.set(name, {
157
- location: node,
158
- reason: 'Marked with @deprecated decorator',
159
- });
160
- break;
161
- }
162
- }
163
- }
164
- }
165
- function reportDeprecatedUsage(node, name, usage) {
166
- if (isAllowed(name))
167
- return;
168
- const deprecationInfo = deprecatedItems.get(name);
169
- if (!deprecationInfo)
170
- return;
171
- const { replacement } = deprecationInfo;
172
- context.report({
173
- node,
174
- messageId: 'deprecatedUsage',
175
- data: {
176
- name,
177
- usage,
178
- reason: deprecationInfo.reason || 'This API is deprecated',
179
- replacement: deprecationInfo.replacement ||
180
- 'Check documentation for replacement',
181
- suggestion: deprecationInfo.replacement
182
- ? `Replace with ${deprecationInfo.replacement}`
183
- : 'Find modern replacement in documentation',
184
- },
185
- suggest: replacement
186
- ? [
187
- {
188
- messageId: 'deprecatedUsage',
189
- fix(fixer) {
190
- return fixer.replaceText(node, replacement);
191
- },
192
- data: {
193
- replacement,
194
- suggestion: `Replace with ${replacement}`,
195
- },
196
- },
197
- ]
198
- : [],
199
- });
200
- }
201
- return {
202
- VariableDeclaration(node) {
203
- node.declarations.forEach((decl) => {
204
- if (decl.id.type === 'Identifier') {
205
- checkComments(node, decl.id.name);
206
- checkDecoratorsForDeprecation(node, decl.id.name);
207
- }
208
- });
209
- },
210
- FunctionDeclaration(node) {
211
- if (node.id) {
212
- checkComments(node, node.id.name);
213
- checkDecoratorsForDeprecation(node, node.id.name);
214
- }
215
- },
216
- ClassDeclaration(node) {
217
- if (node.id) {
218
- checkComments(node, node.id.name);
219
- checkDecoratorsForDeprecation(node, node.id.name);
220
- }
221
- },
222
- MethodDefinition(node) {
223
- if (node.key.type === 'Identifier') {
224
- checkComments(node, node.key.name);
225
- checkComments(node.key, node.key.name);
226
- checkDecoratorsForDeprecation(node, node.key.name);
227
- }
228
- },
229
- ExportNamedDeclaration(node) {
230
- if (node.declaration) {
231
- if (node.declaration.type === 'VariableDeclaration') {
232
- node.declaration.declarations.forEach((decl) => {
233
- if (decl.id.type === 'Identifier') {
234
- checkComments(node, decl.id.name);
235
- checkDecoratorsForDeprecation(node.declaration, decl.id.name);
236
- }
237
- });
238
- }
239
- else if (node.declaration.type === 'FunctionDeclaration' &&
240
- node.declaration.id) {
241
- checkComments(node, node.declaration.id.name);
242
- checkDecoratorsForDeprecation(node.declaration, node.declaration.id.name);
243
- }
244
- else if (node.declaration.type === 'ClassDeclaration' &&
245
- node.declaration.id) {
246
- checkComments(node, node.declaration.id.name);
247
- checkDecoratorsForDeprecation(node.declaration, node.declaration.id.name);
248
- }
249
- }
250
- if (node.specifiers) {
251
- node.specifiers.forEach((specifier) => {
252
- if (specifier.exported.type === 'Identifier') {
253
- checkComments(node, specifier.exported.name);
254
- }
255
- });
256
- }
257
- },
258
- ExportDefaultDeclaration(node) {
259
- checkComments(node, 'default');
260
- checkDecoratorsForDeprecation(node, 'default');
261
- },
262
- ImportDeclaration(node) {
263
- },
264
- MemberExpression(node) {
265
- if (node.object.type === 'Identifier' &&
266
- node.property.type === 'Identifier') {
267
- reportDeprecatedUsage(node, node.object.name, `${node.object.name}.${node.property.name}`);
268
- }
269
- },
270
- CallExpression(node) {
271
- if (node.callee.type === 'Identifier' &&
272
- deprecatedItems.has(node.callee.name)) {
273
- reportDeprecatedUsage(node, node.callee.name, `${node.callee.name}()`);
274
- }
275
- },
276
- NewExpression(node) {
277
- if (node.callee.type === 'Identifier' &&
278
- deprecatedItems.has(node.callee.name)) {
279
- reportDeprecatedUsage(node, node.callee.name, `new ${node.callee.name}()`);
280
- }
281
- },
282
- Identifier(node) {
283
- if (deprecatedItems.has(node.name)) {
284
- const parent = node.parent;
285
- if (parent &&
286
- ![
287
- 'VariableDeclarator',
288
- 'FunctionDeclaration',
289
- 'ClassDeclaration',
290
- 'ImportSpecifier',
291
- 'ExportSpecifier',
292
- 'MethodDefinition',
293
- ].includes(parent.type)) {
294
- if (parent.type === 'CallExpression' &&
295
- parent.callee === node) {
296
- return;
297
- }
298
- if (parent.type === 'NewExpression' &&
299
- parent.callee === node) {
300
- return;
301
- }
302
- if (parent.type === 'MemberExpression' &&
303
- parent.object === node) {
304
- return;
305
- }
306
- if (parent.type === 'MemberExpression' &&
307
- parent.property === node) {
308
- return;
309
- }
310
- reportDeprecatedUsage(node, node.name, node.name);
311
- }
312
- }
313
- },
314
- };
315
- },
316
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDeprecated=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.noDeprecated=(0,eslint_devkit_1.createRule)({name:"no-deprecated",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-deprecated.md",description:"Forbid imported names marked with @deprecated documentation tag"},hasSuggestions:true,messages:{deprecatedImport:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Deprecated Import",description:"Importing deprecated API that should be avoided",severity:"MEDIUM",fix:"Replace with recommended alternative or remove if no longer needed",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-deprecated.md"}),deprecatedExport:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Deprecated Export Usage",description:"Using deprecated exported member",severity:"MEDIUM",fix:"Update to use the recommended replacement API",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-deprecated.md"}),deprecatedUsage:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Deprecated API Usage",description:"Using deprecated function or method",severity:"MEDIUM",fix:"Migrate to the recommended modern API",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-deprecated.md"})},schema:[{type:"object",properties:{allow:{type:"array",items:{type:"string"},description:"List of deprecated items that are allowed (for migration periods)"},deprecationMarkers:{type:"array",items:{type:"string"},default:["@deprecated"],description:"Custom deprecation markers to look for in comments"},checkJSDoc:{type:"boolean",default:true,description:"Check for @deprecated in JSDoc comments"},checkDecorators:{type:"boolean",default:true,description:"Check for @deprecated decorator in TypeScript"}},additionalProperties:false}]},defaultOptions:[{allow:[],deprecationMarkers:["@deprecated"],checkJSDoc:true,checkDecorators:true}],create(context){const[options]=context.options;const{allow=[],deprecationMarkers=["@deprecated"],checkJSDoc=true,checkDecorators=true}=options||{};const filename=context.filename;if(!filename){return{}}const deprecatedItems=new Map;function isAllowed(name){return allow.includes(name)}function parseJSDocDeprecated(comment){const lines=comment.split("\n");for(const line of lines){const trimmed=line.trim();for(const marker of deprecationMarkers){if(trimmed.includes(marker)){const afterMarker=trimmed.substring(trimmed.indexOf(marker)+marker.length).trim();let reason;let replacement;const insteadMatch=afterMarker.match(/(?:use|replaced by|see)\s+([^\s]+(?:\s+[^\s]+)*?)(?:\s|$)/i);if(insteadMatch){replacement=insteadMatch[1].trim().replace(/\s+instead$|\s+or$|\s+as$|\s+with$/i,"")}const reasonText=afterMarker.replace(/use\s+[^.]*[.]?/i,"").replace(/replaced by\s+[^.]*[.]?/i,"").trim();if(reasonText){reason=reasonText}return{deprecated:true,reason,replacement}}}}return{deprecated:false}}function checkComments(node,name){if(!checkJSDoc)return;const sourceCode=context.sourceCode;const comments=sourceCode.getCommentsBefore(node);const allComments=[...comments];if("leadingComments"in node&&Array.isArray(node.leadingComments)){allComments.push(...node.leadingComments)}for(const comment of allComments){if(comment.type==="Block"&&comment.value.includes("*")){const deprecationInfo=parseJSDocDeprecated(comment.value);if(deprecationInfo.deprecated){deprecatedItems.set(name,{location:node,reason:deprecationInfo.reason,replacement:deprecationInfo.replacement});break}}}}function checkDecoratorsForDeprecation(node,name){if(!checkDecorators)return;if("decorators"in node&&Array.isArray(node.decorators)){const decorators=node.decorators;for(const decorator of decorators){const dec=decorator;if(dec.expression.type==="CallExpression"&&dec.expression.callee.type==="Identifier"&&dec.expression.callee.name==="deprecated"||dec.expression.type==="Identifier"&&dec.expression.name==="deprecated"){deprecatedItems.set(name,{location:node,reason:"Marked with @deprecated decorator"});break}}}}function reportDeprecatedUsage(node,name,usage){if(isAllowed(name))return;const deprecationInfo=deprecatedItems.get(name);if(!deprecationInfo)return;const{replacement}=deprecationInfo;context.report({node,messageId:"deprecatedUsage",data:{name,usage,reason:deprecationInfo.reason||"This API is deprecated",replacement:deprecationInfo.replacement||"Check documentation for replacement",suggestion:deprecationInfo.replacement?`Replace with ${deprecationInfo.replacement}`:"Find modern replacement in documentation"},suggest:replacement?[{messageId:"deprecatedUsage",fix(fixer){return fixer.replaceText(node,replacement)},data:{replacement,suggestion:`Replace with ${replacement}`}}]:[]})}return{VariableDeclaration(node){node.declarations.forEach(decl=>{if(decl.id.type==="Identifier"){checkComments(node,decl.id.name);checkDecoratorsForDeprecation(node,decl.id.name)}})},FunctionDeclaration(node){if(node.id){checkComments(node,node.id.name);checkDecoratorsForDeprecation(node,node.id.name)}},ClassDeclaration(node){if(node.id){checkComments(node,node.id.name);checkDecoratorsForDeprecation(node,node.id.name)}},MethodDefinition(node){if(node.key.type==="Identifier"){checkComments(node,node.key.name);checkComments(node.key,node.key.name);checkDecoratorsForDeprecation(node,node.key.name)}},ExportNamedDeclaration(node){if(node.declaration){if(node.declaration.type==="VariableDeclaration"){node.declaration.declarations.forEach(decl=>{if(decl.id.type==="Identifier"){checkComments(node,decl.id.name);checkDecoratorsForDeprecation(node.declaration,decl.id.name)}})}else if(node.declaration.type==="FunctionDeclaration"&&node.declaration.id){checkComments(node,node.declaration.id.name);checkDecoratorsForDeprecation(node.declaration,node.declaration.id.name)}else if(node.declaration.type==="ClassDeclaration"&&node.declaration.id){checkComments(node,node.declaration.id.name);checkDecoratorsForDeprecation(node.declaration,node.declaration.id.name)}}if(node.specifiers){node.specifiers.forEach(specifier=>{if(specifier.exported.type==="Identifier"){checkComments(node,specifier.exported.name)}})}},ExportDefaultDeclaration(node){checkComments(node,"default");checkDecoratorsForDeprecation(node,"default")},ImportDeclaration(node){},MemberExpression(node){if(node.object.type==="Identifier"&&node.property.type==="Identifier"){reportDeprecatedUsage(node,node.object.name,`${node.object.name}.${node.property.name}`)}},CallExpression(node){if(node.callee.type==="Identifier"&&deprecatedItems.has(node.callee.name)){reportDeprecatedUsage(node,node.callee.name,`${node.callee.name}()`)}},NewExpression(node){if(node.callee.type==="Identifier"&&deprecatedItems.has(node.callee.name)){reportDeprecatedUsage(node,node.callee.name,`new ${node.callee.name}()`)}},Identifier(node){if(deprecatedItems.has(node.name)){const parent=node.parent;if(parent&&!["VariableDeclarator","FunctionDeclaration","ClassDeclaration","ImportSpecifier","ExportSpecifier","MethodDefinition"].includes(parent.type)){if(parent.type==="CallExpression"&&parent.callee===node){return}if(parent.type==="NewExpression"&&parent.callee===node){return}if(parent.type==="MemberExpression"&&parent.object===node){return}if(parent.type==="MemberExpression"&&parent.property===node){return}reportDeprecatedUsage(node,node.name,node.name)}}}}}});
@@ -1,81 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noDuplicates = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.noDuplicates = (0, eslint_devkit_1.createRule)({
7
- name: 'no-duplicates',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-duplicates.md',
12
- description: 'Reports duplicate imports',
13
- },
14
- fixable: 'code',
15
- messages: {
16
- noDuplicates: (0, eslint_devkit_2.formatLLMMessage)({
17
- icon: eslint_devkit_2.MessageIcons.QUALITY,
18
- issueName: 'Duplicate Import',
19
- description: 'Duplicate import from the same module',
20
- severity: 'HIGH',
21
- fix: 'Merge imports into a single statement',
22
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-duplicates.md',
23
- }),
24
- },
25
- schema: [],
26
- },
27
- defaultOptions: [],
28
- create(context) {
29
- const imports = new Map();
30
- return {
31
- ImportDeclaration(node) {
32
- const source = node.source.value;
33
- let sourceNodes = imports.get(source);
34
- if (!sourceNodes) {
35
- sourceNodes = [];
36
- imports.set(source, sourceNodes);
37
- }
38
- sourceNodes.push(node);
39
- },
40
- 'Program:exit'() {
41
- for (const nodes of imports.values()) {
42
- if (nodes.length > 1) {
43
- const [first, ...duplicates] = nodes;
44
- for (const duplicate of duplicates) {
45
- context.report({
46
- node: duplicate,
47
- messageId: 'noDuplicates',
48
- fix(fixer) {
49
- const firstHasDefault = first.specifiers.some((s) => s.type === 'ImportDefaultSpecifier');
50
- const duplicateHasDefault = duplicate.specifiers.some((s) => s.type === 'ImportDefaultSpecifier');
51
- const firstHasNamespace = first.specifiers.some((s) => s.type === 'ImportNamespaceSpecifier');
52
- const duplicateHasNamespace = duplicate.specifiers.some((s) => s.type === 'ImportNamespaceSpecifier');
53
- if (firstHasNamespace || duplicateHasNamespace) {
54
- return null;
55
- }
56
- if (firstHasDefault && duplicateHasDefault) {
57
- return null;
58
- }
59
- if (duplicate.specifiers.length === 0) {
60
- return fixer.remove(duplicate);
61
- }
62
- if (first.specifiers.length === 0) {
63
- return null;
64
- }
65
- const sourceCode = context.sourceCode;
66
- const specifiersToAdd = duplicate.specifiers.map((s) => sourceCode.getText(s));
67
- const lastSpecifier = first.specifiers[first.specifiers.length - 1];
68
- const replacement = `, ${specifiersToAdd.join(', ')}`;
69
- return [
70
- fixer.insertTextAfter(lastSpecifier, replacement),
71
- fixer.remove(duplicate),
72
- ];
73
- },
74
- });
75
- }
76
- }
77
- }
78
- },
79
- };
80
- },
81
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDuplicates=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.noDuplicates=(0,eslint_devkit_1.createRule)({name:"no-duplicates",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-duplicates.md",description:"Reports duplicate imports"},fixable:"code",messages:{noDuplicates:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.QUALITY,issueName:"Duplicate Import",description:"Duplicate import from the same module",severity:"HIGH",fix:"Merge imports into a single statement",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-duplicates.md"})},schema:[]},defaultOptions:[],create(context){const imports=new Map;return{ImportDeclaration(node){const source=node.source.value;let sourceNodes=imports.get(source);if(!sourceNodes){sourceNodes=[];imports.set(source,sourceNodes)}sourceNodes.push(node)},"Program:exit"(){for(const nodes of imports.values()){if(nodes.length>1){const[first,...duplicates]=nodes;for(const duplicate of duplicates){context.report({node:duplicate,messageId:"noDuplicates",fix(fixer){const firstHasDefault=first.specifiers.some(s=>s.type==="ImportDefaultSpecifier");const duplicateHasDefault=duplicate.specifiers.some(s=>s.type==="ImportDefaultSpecifier");const firstHasNamespace=first.specifiers.some(s=>s.type==="ImportNamespaceSpecifier");const duplicateHasNamespace=duplicate.specifiers.some(s=>s.type==="ImportNamespaceSpecifier");if(firstHasNamespace||duplicateHasNamespace){return null}if(firstHasDefault&&duplicateHasDefault){return null}if(duplicate.specifiers.length===0){return fixer.remove(duplicate)}if(first.specifiers.length===0){return null}const sourceCode=context.sourceCode;const specifiersToAdd=duplicate.specifiers.map(s=>sourceCode.getText(s));const lastSpecifier=first.specifiers[first.specifiers.length-1];const replacement=`, ${specifiersToAdd.join(", ")}`;return[fixer.insertTextAfter(lastSpecifier,replacement),fixer.remove(duplicate)]}})}}}}}}});
@@ -1,78 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noDynamicRequire = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.noDynamicRequire = (0, eslint_devkit_1.createRule)({
6
- name: 'no-dynamic-require',
7
- meta: {
8
- type: 'suggestion',
9
- docs: {
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-dynamic-require.md',
11
- description: 'Forbid require() calls with expressions',
12
- cwe: 'CWE-829',
13
- cvss: 5,
14
- },
15
- messages: {
16
- dynamicRequire: (0, eslint_devkit_1.formatLLMMessage)({
17
- icon: eslint_devkit_1.MessageIcons.ARCHITECTURE,
18
- issueName: 'Dynamic Require',
19
- cwe: 'CWE-829',
20
- description: 'Calls to require() should use literal string arguments',
21
- severity: 'MEDIUM',
22
- fix: 'Use a static string literal for require()',
23
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-dynamic-require.md',
24
- }),
25
- dynamicImport: (0, eslint_devkit_1.formatLLMMessage)({
26
- icon: eslint_devkit_1.MessageIcons.ARCHITECTURE,
27
- issueName: 'Dynamic Import',
28
- cwe: 'CWE-829',
29
- description: 'Calls to import() should use literal string arguments',
30
- severity: 'MEDIUM',
31
- fix: 'Use a static string literal for import()',
32
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-dynamic-require.md',
33
- }),
34
- },
35
- schema: [
36
- {
37
- type: 'object',
38
- properties: {
39
- esmodule: { type: 'boolean', default: false },
40
- },
41
- additionalProperties: false,
42
- },
43
- ],
44
- },
45
- defaultOptions: [{ esmodule: false }],
46
- create(context) {
47
- const options = context.options[0] || {};
48
- const { esmodule = false } = options;
49
- function isStaticValue(node) {
50
- return (node.type === eslint_devkit_1.AST_NODE_TYPES.Literal ||
51
- (node.type === eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral &&
52
- node.expressions.length === 0));
53
- }
54
- return {
55
- CallExpression(node) {
56
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
57
- node.callee.name === 'require' &&
58
- node.arguments.length >= 1) {
59
- const arg = node.arguments[0];
60
- if (!isStaticValue(arg)) {
61
- context.report({
62
- node,
63
- messageId: 'dynamicRequire',
64
- });
65
- }
66
- }
67
- },
68
- ImportExpression(node) {
69
- if (esmodule && !isStaticValue(node.source)) {
70
- context.report({
71
- node,
72
- messageId: 'dynamicImport',
73
- });
74
- }
75
- },
76
- };
77
- },
78
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noDynamicRequire=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noDynamicRequire=(0,eslint_devkit_1.createRule)({name:"no-dynamic-require",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-dynamic-require.md",description:"Forbid require() calls with expressions",cwe:"CWE-829",cvss:5},messages:{dynamicRequire:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.ARCHITECTURE,issueName:"Dynamic Require",cwe:"CWE-829",description:"Calls to require() should use literal string arguments",severity:"MEDIUM",fix:"Use a static string literal for require()",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-dynamic-require.md"}),dynamicImport:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.ARCHITECTURE,issueName:"Dynamic Import",cwe:"CWE-829",description:"Calls to import() should use literal string arguments",severity:"MEDIUM",fix:"Use a static string literal for import()",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-dynamic-require.md"})},schema:[{type:"object",properties:{esmodule:{type:"boolean",default:false}},additionalProperties:false}]},defaultOptions:[{esmodule:false}],create(context){const options=context.options[0]||{};const{esmodule=false}=options;function isStaticValue(node){return node.type===eslint_devkit_1.AST_NODE_TYPES.Literal||node.type===eslint_devkit_1.AST_NODE_TYPES.TemplateLiteral&&node.expressions.length===0}return{CallExpression(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.name==="require"&&node.arguments.length>=1){const arg=node.arguments[0];if(!isStaticValue(arg)){context.report({node,messageId:"dynamicRequire"})}}},ImportExpression(node){if(esmodule&&!isStaticValue(node.source)){context.report({node,messageId:"dynamicImport"})}}}}});
@@ -1,103 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noEmptyNamedBlocks = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- exports.noEmptyNamedBlocks = (0, eslint_devkit_1.createRule)({
6
- name: 'no-empty-named-blocks',
7
- meta: {
8
- type: 'suggestion',
9
- docs: {
10
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-empty-named-blocks.md',
11
- description: 'Forbid empty named import blocks',
12
- cwe: 'CWE-561',
13
- cvss: 2.5,
14
- },
15
- fixable: 'code',
16
- hasSuggestions: true,
17
- messages: {
18
- emptyNamedBlock: (0, eslint_devkit_1.formatLLMMessage)({
19
- icon: eslint_devkit_1.MessageIcons.ARCHITECTURE,
20
- issueName: 'Empty Named Import',
21
- cwe: 'CWE-561',
22
- description: 'Empty named import block serves no purpose',
23
- severity: 'LOW',
24
- fix: 'Remove the empty import or add named imports',
25
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-empty-named-blocks.md',
26
- }),
27
- suggestRemove: 'Remove empty import statement',
28
- },
29
- schema: [],
30
- },
31
- defaultOptions: [],
32
- create(context) {
33
- return {
34
- ImportDeclaration(node) {
35
- const hasDefaultImport = node.specifiers.some((spec) => spec.type === 'ImportDefaultSpecifier');
36
- const hasNamespaceImport = node.specifiers.some((spec) => spec.type === 'ImportNamespaceSpecifier');
37
- const namedImports = node.specifiers.filter((spec) => spec.type === 'ImportSpecifier');
38
- const sourceCode = context.sourceCode;
39
- const importText = sourceCode.getText(node);
40
- const hasEmptyBraces = /\{\s*\}/.test(importText);
41
- if (hasEmptyBraces && namedImports.length === 0) {
42
- if (!hasDefaultImport && !hasNamespaceImport) {
43
- context.report({
44
- node,
45
- messageId: 'emptyNamedBlock',
46
- fix(fixer) {
47
- return fixer.remove(node);
48
- },
49
- suggest: [
50
- {
51
- messageId: 'suggestRemove',
52
- fix(fixer) {
53
- return fixer.remove(node);
54
- },
55
- },
56
- ],
57
- });
58
- }
59
- else if (hasDefaultImport) {
60
- context.report({
61
- node,
62
- messageId: 'emptyNamedBlock',
63
- fix(fixer) {
64
- const fixedText = importText.replace(/,\s*\{\s*\}/, '');
65
- return fixer.replaceText(node, fixedText);
66
- },
67
- suggest: [
68
- {
69
- messageId: 'suggestRemove',
70
- fix(fixer) {
71
- const fixedText = importText.replace(/,\s*\{\s*\}/, '');
72
- return fixer.replaceText(node, fixedText);
73
- },
74
- },
75
- ],
76
- });
77
- }
78
- }
79
- },
80
- ExportNamedDeclaration(node) {
81
- if (node.specifiers.length === 0 &&
82
- !node.declaration &&
83
- node.source) {
84
- context.report({
85
- node,
86
- messageId: 'emptyNamedBlock',
87
- fix(fixer) {
88
- return fixer.remove(node);
89
- },
90
- suggest: [
91
- {
92
- messageId: 'suggestRemove',
93
- fix(fixer) {
94
- return fixer.remove(node);
95
- },
96
- },
97
- ],
98
- });
99
- }
100
- },
101
- };
102
- },
103
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noEmptyNamedBlocks=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noEmptyNamedBlocks=(0,eslint_devkit_1.createRule)({name:"no-empty-named-blocks",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-empty-named-blocks.md",description:"Forbid empty named import blocks",cwe:"CWE-561",cvss:2.5},fixable:"code",hasSuggestions:true,messages:{emptyNamedBlock:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.ARCHITECTURE,issueName:"Empty Named Import",cwe:"CWE-561",description:"Empty named import block serves no purpose",severity:"LOW",fix:"Remove the empty import or add named imports",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-empty-named-blocks.md"}),suggestRemove:"Remove empty import statement"},schema:[]},defaultOptions:[],create(context){return{ImportDeclaration(node){const hasDefaultImport=node.specifiers.some(spec=>spec.type==="ImportDefaultSpecifier");const hasNamespaceImport=node.specifiers.some(spec=>spec.type==="ImportNamespaceSpecifier");const namedImports=node.specifiers.filter(spec=>spec.type==="ImportSpecifier");const sourceCode=context.sourceCode;const importText=sourceCode.getText(node);const hasEmptyBraces=/\{\s*\}/.test(importText);if(hasEmptyBraces&&namedImports.length===0){if(!hasDefaultImport&&!hasNamespaceImport){context.report({node,messageId:"emptyNamedBlock",fix(fixer){return fixer.remove(node)},suggest:[{messageId:"suggestRemove",fix(fixer){return fixer.remove(node)}}]})}else if(hasDefaultImport){context.report({node,messageId:"emptyNamedBlock",fix(fixer){const fixedText=importText.replace(/,\s*\{\s*\}/,"");return fixer.replaceText(node,fixedText)},suggest:[{messageId:"suggestRemove",fix(fixer){const fixedText=importText.replace(/,\s*\{\s*\}/,"");return fixer.replaceText(node,fixedText)}}]})}}},ExportNamedDeclaration(node){if(node.specifiers.length===0&&!node.declaration&&node.source){context.report({node,messageId:"emptyNamedBlock",fix(fixer){return fixer.remove(node)},suggest:[{messageId:"suggestRemove",fix(fixer){return fixer.remove(node)}}]})}}}}});