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.
- package/package.json +9 -4
- package/src/files/foo.js +1 -6
- package/src/files/no-default.js +1 -4
- package/src/index.js +1 -326
- package/src/oxlint.js +1 -3
- package/src/rules/consistent-type-specifier-style.js +1 -109
- package/src/rules/default.js +1 -56
- package/src/rules/dynamic-import-chunkname.js +1 -115
- package/src/rules/enforce-dependency-direction.js +1 -213
- package/src/rules/enforce-import-order.js +1 -299
- package/src/rules/enforce-team-boundaries.js +1 -191
- package/src/rules/export.js +1 -111
- package/src/rules/exports-last.js +1 -67
- package/src/rules/extensions.js +1 -105
- package/src/rules/first.js +1 -53
- package/src/rules/group-exports.js +1 -69
- package/src/rules/max-dependencies.js +1 -241
- package/src/rules/named.js +1 -67
- package/src/rules/namespace.js +1 -64
- package/src/rules/newline-after-import.js +1 -57
- package/src/rules/no-absolute-path.js +1 -107
- package/src/rules/no-amd.js +1 -108
- package/src/rules/no-anonymous-default-export.js +1 -135
- package/src/rules/no-barrel-file.js +1 -194
- package/src/rules/no-barrel-import.js +1 -135
- package/src/rules/no-commonjs.js +1 -312
- package/src/rules/no-cross-domain-imports.js +1 -233
- package/src/rules/no-cycle.js +2 -396
- package/src/rules/no-default-export.js +2 -213
- package/src/rules/no-deprecated.js +1 -316
- package/src/rules/no-duplicates.js +1 -81
- package/src/rules/no-dynamic-require.js +1 -78
- package/src/rules/no-empty-named-blocks.js +1 -103
- package/src/rules/no-extraneous-dependencies.js +7 -385
- package/src/rules/no-full-package-import.js +1 -134
- package/src/rules/no-import-module-exports.js +1 -76
- package/src/rules/no-internal-modules.js +1 -256
- package/src/rules/no-legacy-imports.js +1 -125
- package/src/rules/no-mutable-exports.js +1 -146
- package/src/rules/no-named-as-default-member.js +1 -73
- package/src/rules/no-named-as-default.js +1 -90
- package/src/rules/no-named-default.js +1 -48
- package/src/rules/no-named-export.js +1 -174
- package/src/rules/no-namespace.js +1 -71
- package/src/rules/no-nodejs-modules.js +1 -229
- package/src/rules/no-relative-packages.js +1 -129
- package/src/rules/no-relative-parent-imports.js +1 -118
- package/src/rules/no-restricted-paths.js +1 -89
- package/src/rules/no-self-import.js +1 -113
- package/src/rules/no-unassigned-import.js +1 -115
- package/src/rules/no-unresolved.js +1 -189
- package/src/rules/no-unused-modules.js +1 -82
- package/src/rules/no-useless-path-segments.js +1 -107
- package/src/rules/prefer-default-export.js +1 -188
- package/src/rules/prefer-direct-import.js +1 -170
- package/src/rules/prefer-modern-api.js +1 -212
- package/src/rules/prefer-node-protocol.js +1 -174
- package/src/rules/prefer-tree-shakeable-imports.js +1 -134
- package/src/rules/require-import-approval.js +1 -174
- package/src/rules/unambiguous.js +1 -70
- package/src/types/index.js +1 -2
- package/src/utils/typescript-peer.js +1 -23
|
@@ -1,256 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noInternalModules = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
function matchGlob(pattern, path) {
|
|
7
|
-
const regexPattern = pattern
|
|
8
|
-
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
9
|
-
.replace(/\*\*/g, '{{DOUBLE_STAR}}')
|
|
10
|
-
.replace(/\*/g, '[^/]*')
|
|
11
|
-
.replace(/\{\{DOUBLE_STAR\}\}/g, '.*');
|
|
12
|
-
return new RegExp(`^${regexPattern}$`).test(path);
|
|
13
|
-
}
|
|
14
|
-
function matchesAnyPattern(path, patterns) {
|
|
15
|
-
return patterns.some((pattern) => matchGlob(pattern, path));
|
|
16
|
-
}
|
|
17
|
-
function getImportDepth(importPath) {
|
|
18
|
-
if (importPath.startsWith('./') || importPath.startsWith('../')) {
|
|
19
|
-
const parts = importPath.split('/').filter((p) => p !== '.' && p !== '..');
|
|
20
|
-
return parts.length;
|
|
21
|
-
}
|
|
22
|
-
if (importPath.startsWith('@')) {
|
|
23
|
-
const parts = importPath.split('/');
|
|
24
|
-
return Math.max(0, parts.length - 2);
|
|
25
|
-
}
|
|
26
|
-
const parts = importPath.split('/');
|
|
27
|
-
return parts.length - 1;
|
|
28
|
-
}
|
|
29
|
-
function getRootImport(importPath) {
|
|
30
|
-
if (importPath.startsWith('./') || importPath.startsWith('../')) {
|
|
31
|
-
return '.';
|
|
32
|
-
}
|
|
33
|
-
if (importPath.startsWith('@')) {
|
|
34
|
-
const parts = importPath.split('/');
|
|
35
|
-
return parts.slice(0, 2).join('/');
|
|
36
|
-
}
|
|
37
|
-
return importPath.split('/')[0];
|
|
38
|
-
}
|
|
39
|
-
function getImportAtDepth(importPath, maxDepth) {
|
|
40
|
-
if (importPath.startsWith('./') || importPath.startsWith('../')) {
|
|
41
|
-
if (maxDepth === 0)
|
|
42
|
-
return '.';
|
|
43
|
-
const prefix = importPath.startsWith('../') ? '../' : './';
|
|
44
|
-
const parts = importPath.replace(/^\.\.?\//, '').split('/');
|
|
45
|
-
return prefix + parts.slice(0, maxDepth).join('/');
|
|
46
|
-
}
|
|
47
|
-
if (importPath.startsWith('@')) {
|
|
48
|
-
const parts = importPath.split('/');
|
|
49
|
-
return parts.slice(0, 2 + maxDepth).join('/');
|
|
50
|
-
}
|
|
51
|
-
const parts = importPath.split('/');
|
|
52
|
-
return parts.slice(0, 1 + maxDepth).join('/');
|
|
53
|
-
}
|
|
54
|
-
exports.noInternalModules = (0, eslint_devkit_1.createRule)({
|
|
55
|
-
name: 'no-internal-modules',
|
|
56
|
-
meta: {
|
|
57
|
-
type: 'problem',
|
|
58
|
-
docs: {
|
|
59
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-internal-modules.md',
|
|
60
|
-
description: 'Forbid importing the submodules of other modules',
|
|
61
|
-
},
|
|
62
|
-
fixable: 'code',
|
|
63
|
-
hasSuggestions: true,
|
|
64
|
-
messages: {
|
|
65
|
-
internalModuleImport: (0, eslint_devkit_2.formatLLMMessage)({
|
|
66
|
-
icon: eslint_devkit_2.MessageIcons.ARCHITECTURE,
|
|
67
|
-
issueName: 'Internal Module Import',
|
|
68
|
-
description: 'Import "{{importPath}}" exceeds maximum allowed depth ({{depth}} > {{maxDepth}})',
|
|
69
|
-
severity: 'MEDIUM',
|
|
70
|
-
fix: 'Import from "{{suggestedPath}}" instead of deep internal path',
|
|
71
|
-
documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-internal-modules.md',
|
|
72
|
-
}),
|
|
73
|
-
suggestPublicApi: (0, eslint_devkit_2.formatLLMMessage)({
|
|
74
|
-
icon: eslint_devkit_2.MessageIcons.ARCHITECTURE,
|
|
75
|
-
issueName: 'Use Public API',
|
|
76
|
-
description: 'Import from the public API entry point',
|
|
77
|
-
severity: 'LOW',
|
|
78
|
-
fix: 'Change import to "{{suggestedPath}}"',
|
|
79
|
-
documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-internal-modules.md',
|
|
80
|
-
}),
|
|
81
|
-
suggestBarrelExport: (0, eslint_devkit_2.formatLLMMessage)({
|
|
82
|
-
icon: eslint_devkit_2.MessageIcons.ARCHITECTURE,
|
|
83
|
-
issueName: 'Use Barrel Export',
|
|
84
|
-
description: 'Import from a barrel export file',
|
|
85
|
-
severity: 'LOW',
|
|
86
|
-
fix: 'Change import to "{{suggestedPath}}"',
|
|
87
|
-
documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-internal-modules.md',
|
|
88
|
-
}),
|
|
89
|
-
},
|
|
90
|
-
schema: [
|
|
91
|
-
{
|
|
92
|
-
type: 'object',
|
|
93
|
-
properties: {
|
|
94
|
-
maxDepth: {
|
|
95
|
-
type: 'number',
|
|
96
|
-
minimum: 0,
|
|
97
|
-
default: 1,
|
|
98
|
-
description: 'Maximum allowed depth of module imports (0 = only root, 1 = one level deep)',
|
|
99
|
-
},
|
|
100
|
-
allow: {
|
|
101
|
-
type: 'array',
|
|
102
|
-
items: { type: 'string' },
|
|
103
|
-
default: [],
|
|
104
|
-
description: 'Glob patterns for paths that are allowed regardless of depth',
|
|
105
|
-
},
|
|
106
|
-
forbid: {
|
|
107
|
-
type: 'array',
|
|
108
|
-
items: { type: 'string' },
|
|
109
|
-
default: [],
|
|
110
|
-
description: 'Glob patterns for paths that are explicitly forbidden',
|
|
111
|
-
},
|
|
112
|
-
ignorePaths: {
|
|
113
|
-
type: 'array',
|
|
114
|
-
items: { type: 'string' },
|
|
115
|
-
default: [],
|
|
116
|
-
description: 'Glob patterns for paths to ignore completely',
|
|
117
|
-
},
|
|
118
|
-
strategy: {
|
|
119
|
-
type: 'string',
|
|
120
|
-
enum: ['error', 'warn', 'autofix', 'suggest'],
|
|
121
|
-
default: 'error',
|
|
122
|
-
description: 'How to handle violations: error (report), warn (report), autofix (fix automatically), suggest (provide suggestions)',
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
additionalProperties: false,
|
|
126
|
-
},
|
|
127
|
-
],
|
|
128
|
-
},
|
|
129
|
-
defaultOptions: [
|
|
130
|
-
{
|
|
131
|
-
maxDepth: 1,
|
|
132
|
-
allow: [],
|
|
133
|
-
forbid: [],
|
|
134
|
-
ignorePaths: [],
|
|
135
|
-
strategy: 'error',
|
|
136
|
-
},
|
|
137
|
-
],
|
|
138
|
-
create(context) {
|
|
139
|
-
const [options] = context.options;
|
|
140
|
-
const { maxDepth = 1, allow = [], forbid = [], ignorePaths = [], strategy = 'error', } = options || {};
|
|
141
|
-
function checkImport(importPath, node) {
|
|
142
|
-
if (matchesAnyPattern(importPath, ignorePaths)) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
if (matchesAnyPattern(importPath, allow)) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
const depth = getImportDepth(importPath);
|
|
149
|
-
const isForbidden = forbid.length > 0 && matchesAnyPattern(importPath, forbid);
|
|
150
|
-
const exceedsDepth = depth > maxDepth;
|
|
151
|
-
if (!isForbidden && !exceedsDepth) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
const rootImport = getRootImport(importPath);
|
|
155
|
-
const suggestedPath = exceedsDepth
|
|
156
|
-
? getImportAtDepth(importPath, maxDepth)
|
|
157
|
-
: rootImport;
|
|
158
|
-
const barrelPath = depth > 1
|
|
159
|
-
? getImportAtDepth(importPath, Math.max(0, depth - 1))
|
|
160
|
-
: rootImport;
|
|
161
|
-
const reportData = {
|
|
162
|
-
importPath,
|
|
163
|
-
depth: String(depth),
|
|
164
|
-
maxDepth: String(maxDepth),
|
|
165
|
-
suggestedPath,
|
|
166
|
-
};
|
|
167
|
-
if (strategy === 'autofix') {
|
|
168
|
-
context.report({
|
|
169
|
-
node,
|
|
170
|
-
messageId: 'internalModuleImport',
|
|
171
|
-
data: reportData,
|
|
172
|
-
fix(fixer) {
|
|
173
|
-
const sourceNode = node.type === 'Literal'
|
|
174
|
-
? node
|
|
175
|
-
: node.source;
|
|
176
|
-
return fixer.replaceText(sourceNode, `'${rootImport}'`);
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
else if (strategy === 'suggest') {
|
|
181
|
-
context.report({
|
|
182
|
-
node,
|
|
183
|
-
messageId: 'internalModuleImport',
|
|
184
|
-
data: reportData,
|
|
185
|
-
suggest: [
|
|
186
|
-
{
|
|
187
|
-
messageId: 'suggestPublicApi',
|
|
188
|
-
data: { suggestedPath: rootImport },
|
|
189
|
-
fix(fixer) {
|
|
190
|
-
const sourceNode = node.type === 'Literal'
|
|
191
|
-
? node
|
|
192
|
-
: node.source;
|
|
193
|
-
return fixer.replaceText(sourceNode, `'${rootImport}'`);
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
...(barrelPath !== rootImport && barrelPath !== suggestedPath
|
|
197
|
-
? [
|
|
198
|
-
{
|
|
199
|
-
messageId: 'suggestBarrelExport',
|
|
200
|
-
data: { suggestedPath: barrelPath },
|
|
201
|
-
fix(fixer) {
|
|
202
|
-
const sourceNode = node.type === 'Literal'
|
|
203
|
-
? node
|
|
204
|
-
: node.source;
|
|
205
|
-
return fixer.replaceText(sourceNode, `'${barrelPath}'`);
|
|
206
|
-
},
|
|
207
|
-
},
|
|
208
|
-
]
|
|
209
|
-
: []),
|
|
210
|
-
],
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
context.report({
|
|
215
|
-
node,
|
|
216
|
-
messageId: 'internalModuleImport',
|
|
217
|
-
data: reportData,
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return {
|
|
222
|
-
ImportDeclaration(node) {
|
|
223
|
-
const importPath = node.source.value;
|
|
224
|
-
if (typeof importPath === 'string') {
|
|
225
|
-
checkImport(importPath, node);
|
|
226
|
-
}
|
|
227
|
-
},
|
|
228
|
-
ExportNamedDeclaration(node) {
|
|
229
|
-
if (node.source && typeof node.source.value === 'string') {
|
|
230
|
-
checkImport(node.source.value, node);
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
ExportAllDeclaration(node) {
|
|
234
|
-
if (typeof node.source.value === 'string') {
|
|
235
|
-
checkImport(node.source.value, node);
|
|
236
|
-
}
|
|
237
|
-
},
|
|
238
|
-
CallExpression(node) {
|
|
239
|
-
if (node.callee.type === 'Identifier' &&
|
|
240
|
-
node.callee.name === 'require' &&
|
|
241
|
-
node.arguments.length === 1) {
|
|
242
|
-
const arg = node.arguments[0];
|
|
243
|
-
if (arg.type === 'Literal' && typeof arg.value === 'string') {
|
|
244
|
-
checkImport(arg.value, arg);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
},
|
|
248
|
-
ImportExpression(node) {
|
|
249
|
-
if (node.source.type === 'Literal' &&
|
|
250
|
-
typeof node.source.value === 'string') {
|
|
251
|
-
checkImport(node.source.value, node.source);
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
};
|
|
255
|
-
},
|
|
256
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noInternalModules=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");function matchGlob(pattern,path){const regexPattern=pattern.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"{{DOUBLE_STAR}}").replace(/\*/g,"[^/]*").replace(/\{\{DOUBLE_STAR\}\}/g,".*");return new RegExp(`^${regexPattern}$`).test(path)}function matchesAnyPattern(path,patterns){return patterns.some(pattern=>matchGlob(pattern,path))}function getImportDepth(importPath){if(importPath.startsWith("./")||importPath.startsWith("../")){const parts2=importPath.split("/").filter(p=>p!=="."&&p!=="..");return parts2.length}if(importPath.startsWith("@")){const parts2=importPath.split("/");return Math.max(0,parts2.length-2)}const parts=importPath.split("/");return parts.length-1}function getRootImport(importPath){if(importPath.startsWith("./")||importPath.startsWith("../")){return"."}if(importPath.startsWith("@")){const parts=importPath.split("/");return parts.slice(0,2).join("/")}return importPath.split("/")[0]}function getImportAtDepth(importPath,maxDepth){if(importPath.startsWith("./")||importPath.startsWith("../")){if(maxDepth===0)return".";const prefix=importPath.startsWith("../")?"../":"./";const parts2=importPath.replace(/^\.\.?\//,"").split("/");return prefix+parts2.slice(0,maxDepth).join("/")}if(importPath.startsWith("@")){const parts2=importPath.split("/");return parts2.slice(0,2+maxDepth).join("/")}const parts=importPath.split("/");return parts.slice(0,1+maxDepth).join("/")}exports.noInternalModules=(0,eslint_devkit_1.createRule)({name:"no-internal-modules",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-internal-modules.md",description:"Forbid importing the submodules of other modules"},fixable:"code",hasSuggestions:true,messages:{internalModuleImport:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.ARCHITECTURE,issueName:"Internal Module Import",description:'Import "{{importPath}}" exceeds maximum allowed depth ({{depth}} > {{maxDepth}})',severity:"MEDIUM",fix:'Import from "{{suggestedPath}}" instead of deep internal path',documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-internal-modules.md"}),suggestPublicApi:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.ARCHITECTURE,issueName:"Use Public API",description:"Import from the public API entry point",severity:"LOW",fix:'Change import to "{{suggestedPath}}"',documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-internal-modules.md"}),suggestBarrelExport:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.ARCHITECTURE,issueName:"Use Barrel Export",description:"Import from a barrel export file",severity:"LOW",fix:'Change import to "{{suggestedPath}}"',documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-internal-modules.md"})},schema:[{type:"object",properties:{maxDepth:{type:"number",minimum:0,default:1,description:"Maximum allowed depth of module imports (0 = only root, 1 = one level deep)"},allow:{type:"array",items:{type:"string"},default:[],description:"Glob patterns for paths that are allowed regardless of depth"},forbid:{type:"array",items:{type:"string"},default:[],description:"Glob patterns for paths that are explicitly forbidden"},ignorePaths:{type:"array",items:{type:"string"},default:[],description:"Glob patterns for paths to ignore completely"},strategy:{type:"string",enum:["error","warn","autofix","suggest"],default:"error",description:"How to handle violations: error (report), warn (report), autofix (fix automatically), suggest (provide suggestions)"}},additionalProperties:false}]},defaultOptions:[{maxDepth:1,allow:[],forbid:[],ignorePaths:[],strategy:"error"}],create(context){const[options]=context.options;const{maxDepth=1,allow=[],forbid=[],ignorePaths=[],strategy="error"}=options||{};function checkImport(importPath,node){if(matchesAnyPattern(importPath,ignorePaths)){return}if(matchesAnyPattern(importPath,allow)){return}const depth=getImportDepth(importPath);const isForbidden=forbid.length>0&&matchesAnyPattern(importPath,forbid);const exceedsDepth=depth>maxDepth;if(!isForbidden&&!exceedsDepth){return}const rootImport=getRootImport(importPath);const suggestedPath=exceedsDepth?getImportAtDepth(importPath,maxDepth):rootImport;const barrelPath=depth>1?getImportAtDepth(importPath,Math.max(0,depth-1)):rootImport;const reportData={importPath,depth:String(depth),maxDepth:String(maxDepth),suggestedPath};if(strategy==="autofix"){context.report({node,messageId:"internalModuleImport",data:reportData,fix(fixer){const sourceNode=node.type==="Literal"?node:node.source;return fixer.replaceText(sourceNode,`'${rootImport}'`)}})}else if(strategy==="suggest"){context.report({node,messageId:"internalModuleImport",data:reportData,suggest:[{messageId:"suggestPublicApi",data:{suggestedPath:rootImport},fix(fixer){const sourceNode=node.type==="Literal"?node:node.source;return fixer.replaceText(sourceNode,`'${rootImport}'`)}},...barrelPath!==rootImport&&barrelPath!==suggestedPath?[{messageId:"suggestBarrelExport",data:{suggestedPath:barrelPath},fix(fixer){const sourceNode=node.type==="Literal"?node:node.source;return fixer.replaceText(sourceNode,`'${barrelPath}'`)}}]:[]]})}else{context.report({node,messageId:"internalModuleImport",data:reportData})}}return{ImportDeclaration(node){const importPath=node.source.value;if(typeof importPath==="string"){checkImport(importPath,node)}},ExportNamedDeclaration(node){if(node.source&&typeof node.source.value==="string"){checkImport(node.source.value,node)}},ExportAllDeclaration(node){if(typeof node.source.value==="string"){checkImport(node.source.value,node)}},CallExpression(node){if(node.callee.type==="Identifier"&&node.callee.name==="require"&&node.arguments.length===1){const arg=node.arguments[0];if(arg.type==="Literal"&&typeof arg.value==="string"){checkImport(arg.value,arg)}}},ImportExpression(node){if(node.source.type==="Literal"&&typeof node.source.value==="string"){checkImport(node.source.value,node.source)}}}}});
|
|
@@ -1,125 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noLegacyImports = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
function matchLegacyPattern(importPath, pattern) {
|
|
6
|
-
try {
|
|
7
|
-
const regex = new RegExp(pattern);
|
|
8
|
-
return regex.test(importPath);
|
|
9
|
-
}
|
|
10
|
-
catch {
|
|
11
|
-
return importPath === pattern || importPath.startsWith(pattern);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.noLegacyImports = (0, eslint_devkit_1.createRule)({
|
|
15
|
-
name: 'no-legacy-imports',
|
|
16
|
-
meta: {
|
|
17
|
-
type: 'suggestion',
|
|
18
|
-
docs: {
|
|
19
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-legacy-imports.md',
|
|
20
|
-
description: 'Detect imports from deprecated internal paths and suggest alternatives',
|
|
21
|
-
},
|
|
22
|
-
fixable: 'code',
|
|
23
|
-
messages: {
|
|
24
|
-
legacyImport: (0, eslint_devkit_1.formatLLMMessage)({
|
|
25
|
-
icon: eslint_devkit_1.MessageIcons.DEPRECATION,
|
|
26
|
-
issueName: 'Legacy Import Detected',
|
|
27
|
-
description: "The import '{{deprecated}}' is deprecated{{reason}}. " +
|
|
28
|
-
"Please use '{{replacement}}' instead.{{deadline}}",
|
|
29
|
-
severity: 'MEDIUM',
|
|
30
|
-
fix: 'Replace the import:\n' +
|
|
31
|
-
" - import { X } from '{{deprecated}}';\n" +
|
|
32
|
-
" + import { X } from '{{replacement}}';",
|
|
33
|
-
documentationLink: '',
|
|
34
|
-
}),
|
|
35
|
-
},
|
|
36
|
-
schema: [
|
|
37
|
-
{
|
|
38
|
-
type: 'object',
|
|
39
|
-
properties: {
|
|
40
|
-
mappings: {
|
|
41
|
-
type: 'array',
|
|
42
|
-
items: {
|
|
43
|
-
type: 'object',
|
|
44
|
-
properties: {
|
|
45
|
-
deprecated: { type: 'string' },
|
|
46
|
-
replacement: { type: 'string' },
|
|
47
|
-
reason: { type: 'string' },
|
|
48
|
-
since: { type: 'string' },
|
|
49
|
-
deadline: { type: 'string' },
|
|
50
|
-
},
|
|
51
|
-
required: ['deprecated', 'replacement'],
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
severity: {
|
|
55
|
-
type: 'string',
|
|
56
|
-
enum: ['warn', 'error'],
|
|
57
|
-
default: 'warn',
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
required: ['mappings'],
|
|
61
|
-
additionalProperties: false,
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
},
|
|
65
|
-
defaultOptions: [
|
|
66
|
-
{
|
|
67
|
-
mappings: [],
|
|
68
|
-
severity: 'warn',
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
create(context, [options]) {
|
|
72
|
-
const { mappings } = options;
|
|
73
|
-
function checkImport(importPath, node, sourceNode) {
|
|
74
|
-
for (const mapping of mappings) {
|
|
75
|
-
if (matchLegacyPattern(importPath, mapping.deprecated)) {
|
|
76
|
-
const reasonText = mapping.reason ? ` (${mapping.reason})` : '';
|
|
77
|
-
const deadlineText = mapping.deadline
|
|
78
|
-
? ` Migration deadline: ${mapping.deadline}.`
|
|
79
|
-
: '';
|
|
80
|
-
context.report({
|
|
81
|
-
node,
|
|
82
|
-
messageId: 'legacyImport',
|
|
83
|
-
data: {
|
|
84
|
-
deprecated: importPath,
|
|
85
|
-
replacement: mapping.replacement,
|
|
86
|
-
reason: reasonText,
|
|
87
|
-
deadline: deadlineText,
|
|
88
|
-
},
|
|
89
|
-
fix: (fixer) => {
|
|
90
|
-
return fixer.replaceText(sourceNode, `'${mapping.replacement}'`);
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
ImportDeclaration(node) {
|
|
99
|
-
const importPath = node.source.value;
|
|
100
|
-
if (typeof importPath === 'string') {
|
|
101
|
-
checkImport(importPath, node, node.source);
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
ImportExpression(node) {
|
|
105
|
-
if (node.source.type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
|
|
106
|
-
const importPath = node.source.value;
|
|
107
|
-
if (typeof importPath === 'string') {
|
|
108
|
-
checkImport(importPath, node, node.source);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
CallExpression(node) {
|
|
113
|
-
if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
|
|
114
|
-
node.callee.name === 'require' &&
|
|
115
|
-
node.arguments.length > 0 &&
|
|
116
|
-
node.arguments[0].type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
|
|
117
|
-
const importPath = node.arguments[0].value;
|
|
118
|
-
if (typeof importPath === 'string') {
|
|
119
|
-
checkImport(importPath, node, node.arguments[0]);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
},
|
|
125
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noLegacyImports=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");function matchLegacyPattern(importPath,pattern){try{const regex=new RegExp(pattern);return regex.test(importPath)}catch{return importPath===pattern||importPath.startsWith(pattern)}}exports.noLegacyImports=(0,eslint_devkit_1.createRule)({name:"no-legacy-imports",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-legacy-imports.md",description:"Detect imports from deprecated internal paths and suggest alternatives"},fixable:"code",messages:{legacyImport:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.DEPRECATION,issueName:"Legacy Import Detected",description:"The import '{{deprecated}}' is deprecated{{reason}}. Please use '{{replacement}}' instead.{{deadline}}",severity:"MEDIUM",fix:"Replace the import:\n - import { X } from '{{deprecated}}';\n + import { X } from '{{replacement}}';",documentationLink:""})},schema:[{type:"object",properties:{mappings:{type:"array",items:{type:"object",properties:{deprecated:{type:"string"},replacement:{type:"string"},reason:{type:"string"},since:{type:"string"},deadline:{type:"string"}},required:["deprecated","replacement"]}},severity:{type:"string",enum:["warn","error"],default:"warn"}},required:["mappings"],additionalProperties:false}]},defaultOptions:[{mappings:[],severity:"warn"}],create(context,[options]){const{mappings}=options;function checkImport(importPath,node,sourceNode){for(const mapping of mappings){if(matchLegacyPattern(importPath,mapping.deprecated)){const reasonText=mapping.reason?` (${mapping.reason})`:"";const deadlineText=mapping.deadline?` Migration deadline: ${mapping.deadline}.`:"";context.report({node,messageId:"legacyImport",data:{deprecated:importPath,replacement:mapping.replacement,reason:reasonText,deadline:deadlineText},fix:fixer=>{return fixer.replaceText(sourceNode,`'${mapping.replacement}'`)}});break}}}return{ImportDeclaration(node){const importPath=node.source.value;if(typeof importPath==="string"){checkImport(importPath,node,node.source)}},ImportExpression(node){if(node.source.type===eslint_devkit_1.AST_NODE_TYPES.Literal){const importPath=node.source.value;if(typeof importPath==="string"){checkImport(importPath,node,node.source)}}},CallExpression(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.name==="require"&&node.arguments.length>0&&node.arguments[0].type===eslint_devkit_1.AST_NODE_TYPES.Literal){const importPath=node.arguments[0].value;if(typeof importPath==="string"){checkImport(importPath,node,node.arguments[0])}}}}}});
|
|
@@ -1,146 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noMutableExports = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
6
|
-
exports.noMutableExports = (0, eslint_devkit_1.createRule)({
|
|
7
|
-
name: 'no-mutable-exports',
|
|
8
|
-
meta: {
|
|
9
|
-
type: 'suggestion',
|
|
10
|
-
docs: {
|
|
11
|
-
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-mutable-exports.md',
|
|
12
|
-
description: 'Forbid the use of mutable exports with `var` or `let`',
|
|
13
|
-
},
|
|
14
|
-
hasSuggestions: false,
|
|
15
|
-
messages: {
|
|
16
|
-
mutableExport: (0, eslint_devkit_2.formatLLMMessage)({
|
|
17
|
-
icon: eslint_devkit_2.MessageIcons.WARNING,
|
|
18
|
-
issueName: 'Mutable Export',
|
|
19
|
-
description: 'Export uses mutable declaration that can be reassigned',
|
|
20
|
-
severity: 'MEDIUM',
|
|
21
|
-
fix: 'Use const for exports to ensure immutability',
|
|
22
|
-
documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-mutable-exports.md',
|
|
23
|
-
}),
|
|
24
|
-
varExport: (0, eslint_devkit_2.formatLLMMessage)({
|
|
25
|
-
icon: eslint_devkit_2.MessageIcons.WARNING,
|
|
26
|
-
issueName: 'Var Export',
|
|
27
|
-
description: 'Export declared with var can be reassigned',
|
|
28
|
-
severity: 'MEDIUM',
|
|
29
|
-
fix: 'Change var to const for better predictability',
|
|
30
|
-
documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-mutable-exports.md',
|
|
31
|
-
}),
|
|
32
|
-
letExport: (0, eslint_devkit_2.formatLLMMessage)({
|
|
33
|
-
icon: eslint_devkit_2.MessageIcons.WARNING,
|
|
34
|
-
issueName: 'Let Export',
|
|
35
|
-
description: 'Export declared with let can be reassigned',
|
|
36
|
-
severity: 'MEDIUM',
|
|
37
|
-
fix: 'Change let to const if value never changes',
|
|
38
|
-
documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-mutable-exports.md',
|
|
39
|
-
}),
|
|
40
|
-
},
|
|
41
|
-
schema: [
|
|
42
|
-
{
|
|
43
|
-
type: 'object',
|
|
44
|
-
properties: {
|
|
45
|
-
allowInFiles: {
|
|
46
|
-
type: 'array',
|
|
47
|
-
items: { type: 'string' },
|
|
48
|
-
description: 'File patterns where mutable exports are allowed',
|
|
49
|
-
},
|
|
50
|
-
ignoreExports: {
|
|
51
|
-
type: 'array',
|
|
52
|
-
items: { type: 'string' },
|
|
53
|
-
description: 'Specific export names to ignore',
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
additionalProperties: false,
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
defaultOptions: [
|
|
61
|
-
{
|
|
62
|
-
allowInFiles: [],
|
|
63
|
-
ignoreExports: [],
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
create(context) {
|
|
67
|
-
const [options] = context.options;
|
|
68
|
-
const { allowInFiles = [], ignoreExports = [] } = options || {};
|
|
69
|
-
const filename = context.filename;
|
|
70
|
-
if (!filename) {
|
|
71
|
-
return {};
|
|
72
|
-
}
|
|
73
|
-
function shouldSkipFile() {
|
|
74
|
-
return allowInFiles.some((pattern) => filename.includes(pattern));
|
|
75
|
-
}
|
|
76
|
-
function shouldIgnoreExport(exportName) {
|
|
77
|
-
return ignoreExports.includes(exportName);
|
|
78
|
-
}
|
|
79
|
-
function reportMutableExport(node, exportName, declarationKind) {
|
|
80
|
-
if (shouldSkipFile() || shouldIgnoreExport(exportName)) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const messageId = declarationKind === 'var' ? 'varExport' : 'letExport';
|
|
84
|
-
context.report({
|
|
85
|
-
node,
|
|
86
|
-
messageId,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
function checkPattern(node, kind, reportNode = node) {
|
|
90
|
-
if (node.type === 'Identifier') {
|
|
91
|
-
reportMutableExport(reportNode, node.name, kind);
|
|
92
|
-
}
|
|
93
|
-
else if (node.type === 'ObjectPattern') {
|
|
94
|
-
node.properties.forEach((prop) => {
|
|
95
|
-
if (prop.type === 'Property' && prop.value) {
|
|
96
|
-
checkPattern(prop.value, kind, prop.key);
|
|
97
|
-
}
|
|
98
|
-
else if (prop.type === 'RestElement') {
|
|
99
|
-
checkPattern(prop.argument, kind, prop);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
else if (node.type === 'ArrayPattern') {
|
|
104
|
-
node.elements.forEach((element) => {
|
|
105
|
-
if (element) {
|
|
106
|
-
checkPattern(element, kind, element);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return {
|
|
112
|
-
ExportNamedDeclaration(node) {
|
|
113
|
-
if (!node.declaration ||
|
|
114
|
-
node.declaration.type !== 'VariableDeclaration') {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
const { kind, declarations } = node.declaration;
|
|
118
|
-
if (kind !== 'var' && kind !== 'let') {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
declarations.forEach((decl) => {
|
|
122
|
-
checkPattern(decl.id, kind);
|
|
123
|
-
});
|
|
124
|
-
},
|
|
125
|
-
VariableDeclaration(node) {
|
|
126
|
-
const parent = node.parent;
|
|
127
|
-
if (parent && parent.type === 'ExportNamedDeclaration') {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
const sourceCode = context.sourceCode;
|
|
131
|
-
const fileText = sourceCode.getText();
|
|
132
|
-
if (node.kind === 'var' || node.kind === 'let') {
|
|
133
|
-
node.declarations.forEach((decl) => {
|
|
134
|
-
if (decl.id.type === 'Identifier') {
|
|
135
|
-
const varName = decl.id.name;
|
|
136
|
-
const exportPattern = new RegExp(`export\\s*{\\s*${varName}\\s*}`, 'g');
|
|
137
|
-
if (exportPattern.test(fileText)) {
|
|
138
|
-
reportMutableExport(decl.id, varName, node.kind);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
},
|
|
146
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noMutableExports=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.noMutableExports=(0,eslint_devkit_1.createRule)({name:"no-mutable-exports",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-mutable-exports.md",description:"Forbid the use of mutable exports with `var` or `let`"},hasSuggestions:false,messages:{mutableExport:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Mutable Export",description:"Export uses mutable declaration that can be reassigned",severity:"MEDIUM",fix:"Use const for exports to ensure immutability",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-mutable-exports.md"}),varExport:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Var Export",description:"Export declared with var can be reassigned",severity:"MEDIUM",fix:"Change var to const for better predictability",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-mutable-exports.md"}),letExport:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.WARNING,issueName:"Let Export",description:"Export declared with let can be reassigned",severity:"MEDIUM",fix:"Change let to const if value never changes",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-mutable-exports.md"})},schema:[{type:"object",properties:{allowInFiles:{type:"array",items:{type:"string"},description:"File patterns where mutable exports are allowed"},ignoreExports:{type:"array",items:{type:"string"},description:"Specific export names to ignore"}},additionalProperties:false}]},defaultOptions:[{allowInFiles:[],ignoreExports:[]}],create(context){const[options]=context.options;const{allowInFiles=[],ignoreExports=[]}=options||{};const filename=context.filename;if(!filename){return{}}function shouldSkipFile(){return allowInFiles.some(pattern=>filename.includes(pattern))}function shouldIgnoreExport(exportName){return ignoreExports.includes(exportName)}function reportMutableExport(node,exportName,declarationKind){if(shouldSkipFile()||shouldIgnoreExport(exportName)){return}const messageId=declarationKind==="var"?"varExport":"letExport";context.report({node,messageId})}function checkPattern(node,kind,reportNode=node){if(node.type==="Identifier"){reportMutableExport(reportNode,node.name,kind)}else if(node.type==="ObjectPattern"){node.properties.forEach(prop=>{if(prop.type==="Property"&&prop.value){checkPattern(prop.value,kind,prop.key)}else if(prop.type==="RestElement"){checkPattern(prop.argument,kind,prop)}})}else if(node.type==="ArrayPattern"){node.elements.forEach(element=>{if(element){checkPattern(element,kind,element)}})}}return{ExportNamedDeclaration(node){if(!node.declaration||node.declaration.type!=="VariableDeclaration"){return}const{kind,declarations}=node.declaration;if(kind!=="var"&&kind!=="let"){return}declarations.forEach(decl=>{checkPattern(decl.id,kind)})},VariableDeclaration(node){const parent=node.parent;if(parent&&parent.type==="ExportNamedDeclaration"){return}const sourceCode=context.sourceCode;const fileText=sourceCode.getText();if(node.kind==="var"||node.kind==="let"){node.declarations.forEach(decl=>{if(decl.id.type==="Identifier"){const varName=decl.id.name;const exportPattern=new RegExp(`export\\s*{\\s*${varName}\\s*}`,"g");if(exportPattern.test(fileText)){reportMutableExport(decl.id,varName,node.kind)}}})}}}}});
|
|
@@ -1,73 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noNamedAsDefaultMember = void 0;
|
|
4
|
-
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
5
|
-
exports.noNamedAsDefaultMember = (0, eslint_devkit_1.createRule)({
|
|
6
|
-
name: 'no-named-as-default-member',
|
|
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-named-as-default-member.md',
|
|
11
|
-
description: 'Forbid use of exported name as property of default export',
|
|
12
|
-
cwe: 'CWE-1078',
|
|
13
|
-
cvss: 2.5,
|
|
14
|
-
},
|
|
15
|
-
messages: {
|
|
16
|
-
namedAsDefaultMember: (0, eslint_devkit_1.formatLLMMessage)({
|
|
17
|
-
icon: eslint_devkit_1.MessageIcons.ARCHITECTURE,
|
|
18
|
-
issueName: 'Named as Default Member',
|
|
19
|
-
cwe: 'CWE-1078',
|
|
20
|
-
description: 'Accessing "{{name}}" as property of default import. Import it directly instead',
|
|
21
|
-
severity: 'LOW',
|
|
22
|
-
fix: 'Import the named export directly: import { {{name}} } from "..."',
|
|
23
|
-
documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-named-as-default-member.md',
|
|
24
|
-
}),
|
|
25
|
-
},
|
|
26
|
-
schema: [],
|
|
27
|
-
},
|
|
28
|
-
defaultOptions: [],
|
|
29
|
-
create(context) {
|
|
30
|
-
const defaultImports = new Map();
|
|
31
|
-
const namedImportsBySource = new Map();
|
|
32
|
-
return {
|
|
33
|
-
ImportDeclaration(node) {
|
|
34
|
-
const source = node.source.value;
|
|
35
|
-
node.specifiers.forEach((spec) => {
|
|
36
|
-
if (spec.type === eslint_devkit_1.AST_NODE_TYPES.ImportDefaultSpecifier) {
|
|
37
|
-
defaultImports.set(spec.local.name, { source, node: spec });
|
|
38
|
-
}
|
|
39
|
-
else if (spec.type === eslint_devkit_1.AST_NODE_TYPES.ImportSpecifier) {
|
|
40
|
-
if (!namedImportsBySource.has(source)) {
|
|
41
|
-
namedImportsBySource.set(source, new Set());
|
|
42
|
-
}
|
|
43
|
-
const importedName = spec.imported.type === eslint_devkit_1.AST_NODE_TYPES.Identifier
|
|
44
|
-
? spec.imported.name
|
|
45
|
-
: spec.imported.value;
|
|
46
|
-
namedImportsBySource.get(source)?.add(importedName);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
},
|
|
50
|
-
MemberExpression(node) {
|
|
51
|
-
if (node.object.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (node.computed)
|
|
55
|
-
return;
|
|
56
|
-
const defaultImportInfo = defaultImports.get(node.object.name);
|
|
57
|
-
if (!defaultImportInfo)
|
|
58
|
-
return;
|
|
59
|
-
if (node.property.type !== eslint_devkit_1.AST_NODE_TYPES.Identifier)
|
|
60
|
-
return;
|
|
61
|
-
const propertyName = node.property.name;
|
|
62
|
-
const namedExports = namedImportsBySource.get(defaultImportInfo.source);
|
|
63
|
-
if (namedExports && namedExports.has(propertyName)) {
|
|
64
|
-
context.report({
|
|
65
|
-
node,
|
|
66
|
-
messageId: 'namedAsDefaultMember',
|
|
67
|
-
data: { name: propertyName },
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
},
|
|
73
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noNamedAsDefaultMember=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");exports.noNamedAsDefaultMember=(0,eslint_devkit_1.createRule)({name:"no-named-as-default-member",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-named-as-default-member.md",description:"Forbid use of exported name as property of default export",cwe:"CWE-1078",cvss:2.5},messages:{namedAsDefaultMember:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.ARCHITECTURE,issueName:"Named as Default Member",cwe:"CWE-1078",description:'Accessing "{{name}}" as property of default import. Import it directly instead',severity:"LOW",fix:'Import the named export directly: import { {{name}} } from "..."',documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-named-as-default-member.md"})},schema:[]},defaultOptions:[],create(context){const defaultImports=new Map;const namedImportsBySource=new Map;return{ImportDeclaration(node){const source=node.source.value;node.specifiers.forEach(spec=>{if(spec.type===eslint_devkit_1.AST_NODE_TYPES.ImportDefaultSpecifier){defaultImports.set(spec.local.name,{source,node:spec})}else if(spec.type===eslint_devkit_1.AST_NODE_TYPES.ImportSpecifier){if(!namedImportsBySource.has(source)){namedImportsBySource.set(source,new Set)}const importedName=spec.imported.type===eslint_devkit_1.AST_NODE_TYPES.Identifier?spec.imported.name:spec.imported.value;namedImportsBySource.get(source)?.add(importedName)}})},MemberExpression(node){if(node.object.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier){return}if(node.computed)return;const defaultImportInfo=defaultImports.get(node.object.name);if(!defaultImportInfo)return;if(node.property.type!==eslint_devkit_1.AST_NODE_TYPES.Identifier)return;const propertyName=node.property.name;const namedExports=namedImportsBySource.get(defaultImportInfo.source);if(namedExports&&namedExports.has(propertyName)){context.report({node,messageId:"namedAsDefaultMember",data:{name:propertyName}})}}}}});
|