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,129 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noRelativePackages = void 0;
4
- const tslib_1 = require("tslib");
5
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
6
- const path = tslib_1.__importStar(require("node:path"));
7
- const fs = tslib_1.__importStar(require("node:fs"));
8
- const packageJsonCache = new Map();
9
- function findPackageJson(startDir) {
10
- if (packageJsonCache.has(startDir)) {
11
- return packageJsonCache.get(startDir) ?? null;
12
- }
13
- let currentDir = startDir;
14
- while (currentDir !== path.dirname(currentDir)) {
15
- const pkgPath = path.join(currentDir, 'package.json');
16
- if (fs.existsSync(pkgPath)) {
17
- packageJsonCache.set(startDir, currentDir);
18
- return currentDir;
19
- }
20
- currentDir = path.dirname(currentDir);
21
- }
22
- packageJsonCache.set(startDir, null);
23
- return null;
24
- }
25
- exports.noRelativePackages = (0, eslint_devkit_1.createRule)({
26
- name: 'no-relative-packages',
27
- meta: {
28
- type: 'suggestion',
29
- docs: {
30
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-relative-packages.md',
31
- description: 'Forbid importing packages through relative paths',
32
- cwe: 'CWE-1047',
33
- cvss: 5,
34
- },
35
- fixable: 'code',
36
- messages: {
37
- relativePackage: (0, eslint_devkit_1.formatLLMMessage)({
38
- icon: eslint_devkit_1.MessageIcons.ARCHITECTURE,
39
- issueName: 'Relative Package Import',
40
- cwe: 'CWE-1047',
41
- description: 'Relative import from another package: {{importPath}}. Use package name instead: {{packageName}}',
42
- severity: 'MEDIUM',
43
- fix: 'Import using the package name: {{packageName}}',
44
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-relative-packages.md',
45
- }),
46
- },
47
- schema: [
48
- {
49
- type: 'object',
50
- properties: {
51
- allowSamePackage: { type: 'boolean', default: true },
52
- },
53
- additionalProperties: false,
54
- },
55
- ],
56
- },
57
- defaultOptions: [{ allowSamePackage: true }],
58
- create(context) {
59
- const options = context.options[0] || {};
60
- const { allowSamePackage = true } = options;
61
- const filename = context.filename;
62
- const currentDir = path.dirname(filename);
63
- const currentPackageRoot = findPackageJson(currentDir);
64
- function checkImport(node, source) {
65
- const importPath = source.value;
66
- if (typeof importPath !== 'string')
67
- return;
68
- if (!importPath.startsWith('./') && !importPath.startsWith('../')) {
69
- return;
70
- }
71
- const resolvedPath = path.resolve(currentDir, importPath);
72
- const importPackageRoot = findPackageJson(path.dirname(resolvedPath));
73
- if (allowSamePackage && currentPackageRoot === importPackageRoot) {
74
- return;
75
- }
76
- if (!currentPackageRoot || !importPackageRoot) {
77
- return;
78
- }
79
- if (currentPackageRoot !== importPackageRoot) {
80
- try {
81
- const pkgJsonPath = path.join(importPackageRoot, 'package.json');
82
- const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
83
- const packageName = pkgJson.name || path.basename(importPackageRoot);
84
- context.report({
85
- node: source,
86
- messageId: 'relativePackage',
87
- data: {
88
- importPath,
89
- packageName,
90
- },
91
- fix(fixer) {
92
- const subPath = path.relative(importPackageRoot, resolvedPath);
93
- const newImport = `${packageName}/${subPath.replace(/\.[^/.]+$/, '')}`;
94
- return fixer.replaceText(source, `'${newImport}'`);
95
- },
96
- });
97
- }
98
- catch {
99
- context.report({
100
- node: source,
101
- messageId: 'relativePackage',
102
- data: {
103
- importPath,
104
- packageName: path.basename(importPackageRoot),
105
- },
106
- });
107
- }
108
- }
109
- }
110
- return {
111
- ImportDeclaration(node) {
112
- checkImport(node, node.source);
113
- },
114
- ImportExpression(node) {
115
- if (node.source.type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
116
- checkImport(node, node.source);
117
- }
118
- },
119
- CallExpression(node) {
120
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
121
- node.callee.name === 'require' &&
122
- node.arguments.length === 1 &&
123
- node.arguments[0].type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
124
- checkImport(node, node.arguments[0]);
125
- }
126
- },
127
- };
128
- },
129
- });
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(o,m,k,k2){if(k2===void 0)k2=k;var desc=Object.getOwnPropertyDescriptor(m,k);if(!desc||("get"in desc?!m.__esModule:desc.writable||desc.configurable)){desc={enumerable:true,get:function(){return m[k]}}}Object.defineProperty(o,k2,desc)}):(function(o,m,k,k2){if(k2===void 0)k2=k;o[k2]=m[k]}));var __setModuleDefault=this&&this.__setModuleDefault||(Object.create?(function(o,v){Object.defineProperty(o,"default",{enumerable:true,value:v})}):function(o,v){o["default"]=v});var __importStar=this&&this.__importStar||(function(){var ownKeys=function(o){ownKeys=Object.getOwnPropertyNames||function(o2){var ar=[];for(var k in o2)if(Object.prototype.hasOwnProperty.call(o2,k))ar[ar.length]=k;return ar};return ownKeys(o)};return function(mod){if(mod&&mod.__esModule)return mod;var result={};if(mod!=null){for(var k=ownKeys(mod),i=0;i<k.length;i++)if(k[i]!=="default")__createBinding(result,mod,k[i])}__setModuleDefault(result,mod);return result}})();Object.defineProperty(exports,"__esModule",{value:true});exports.noRelativePackages=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const path=__importStar(require("node:path"));const fs=__importStar(require("node:fs"));const packageJsonCache=new Map;function findPackageJson(startDir){if(packageJsonCache.has(startDir)){return packageJsonCache.get(startDir)??null}let currentDir=startDir;while(currentDir!==path.dirname(currentDir)){const pkgPath=path.join(currentDir,"package.json");if(fs.existsSync(pkgPath)){packageJsonCache.set(startDir,currentDir);return currentDir}currentDir=path.dirname(currentDir)}packageJsonCache.set(startDir,null);return null}exports.noRelativePackages=(0,eslint_devkit_1.createRule)({name:"no-relative-packages",meta:{type:"suggestion",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-relative-packages.md",description:"Forbid importing packages through relative paths",cwe:"CWE-1047",cvss:5},fixable:"code",messages:{relativePackage:(0,eslint_devkit_1.formatLLMMessage)({icon:eslint_devkit_1.MessageIcons.ARCHITECTURE,issueName:"Relative Package Import",cwe:"CWE-1047",description:"Relative import from another package: {{importPath}}. Use package name instead: {{packageName}}",severity:"MEDIUM",fix:"Import using the package name: {{packageName}}",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-relative-packages.md"})},schema:[{type:"object",properties:{allowSamePackage:{type:"boolean",default:true}},additionalProperties:false}]},defaultOptions:[{allowSamePackage:true}],create(context){const options=context.options[0]||{};const{allowSamePackage=true}=options;const filename=context.filename;const currentDir=path.dirname(filename);const currentPackageRoot=findPackageJson(currentDir);function checkImport(node,source){const importPath=source.value;if(typeof importPath!=="string")return;if(!importPath.startsWith("./")&&!importPath.startsWith("../")){return}const resolvedPath=path.resolve(currentDir,importPath);const importPackageRoot=findPackageJson(path.dirname(resolvedPath));if(allowSamePackage&&currentPackageRoot===importPackageRoot){return}if(!currentPackageRoot||!importPackageRoot){return}if(currentPackageRoot!==importPackageRoot){try{const pkgJsonPath=path.join(importPackageRoot,"package.json");const pkgJson=JSON.parse(fs.readFileSync(pkgJsonPath,"utf-8"));const packageName=pkgJson.name||path.basename(importPackageRoot);context.report({node:source,messageId:"relativePackage",data:{importPath,packageName},fix(fixer){const subPath=path.relative(importPackageRoot,resolvedPath);const newImport=`${packageName}/${subPath.replace(/\.[^/.]+$/,"")}`;return fixer.replaceText(source,`'${newImport}'`)}})}catch{context.report({node:source,messageId:"relativePackage",data:{importPath,packageName:path.basename(importPackageRoot)}})}}}return{ImportDeclaration(node){checkImport(node,node.source)},ImportExpression(node){if(node.source.type===eslint_devkit_1.AST_NODE_TYPES.Literal){checkImport(node,node.source)}},CallExpression(node){if(node.callee.type===eslint_devkit_1.AST_NODE_TYPES.Identifier&&node.callee.name==="require"&&node.arguments.length===1&&node.arguments[0].type===eslint_devkit_1.AST_NODE_TYPES.Literal){checkImport(node,node.arguments[0])}}}}});
@@ -1,118 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noRelativeParentImports = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.noRelativeParentImports = (0, eslint_devkit_1.createRule)({
7
- name: 'no-relative-parent-imports',
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-relative-parent-imports.md',
12
- description: 'Prevents ../ imports',
13
- },
14
- hasSuggestions: false,
15
- messages: {
16
- relativeParentImport: (0, eslint_devkit_2.formatLLMMessage)({
17
- icon: eslint_devkit_2.MessageIcons.ARCHITECTURE,
18
- issueName: 'Relative Parent Import',
19
- description: 'Relative parent import (..) detected',
20
- severity: 'MEDIUM',
21
- fix: 'Use absolute import or move code closer to dependencies',
22
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-relative-parent-imports.md',
23
- }),
24
- preferAbsoluteImport: (0, eslint_devkit_2.formatLLMMessage)({
25
- icon: eslint_devkit_2.MessageIcons.ARCHITECTURE,
26
- issueName: 'Prefer Absolute Import',
27
- description: 'Parent directory import makes dependencies unclear',
28
- severity: 'LOW',
29
- fix: 'Use absolute import path instead of relative',
30
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-relative-parent-imports.md',
31
- }),
32
- suggestAlias: (0, eslint_devkit_2.formatLLMMessage)({
33
- icon: eslint_devkit_2.MessageIcons.ARCHITECTURE,
34
- issueName: 'Import Alias Suggestion',
35
- description: 'Consider using import alias for cleaner imports',
36
- severity: 'LOW',
37
- fix: 'Configure import alias (e.g., @/ or ~/ ) for absolute imports',
38
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-relative-parent-imports.md',
39
- }),
40
- },
41
- schema: [
42
- {
43
- type: 'object',
44
- properties: {
45
- commonjs: {
46
- type: 'boolean',
47
- default: true,
48
- description: 'Check CommonJS require() calls.',
49
- },
50
- amd: {
51
- type: 'boolean',
52
- default: false,
53
- description: 'Check AMD define/require calls.',
54
- },
55
- },
56
- additionalProperties: false,
57
- },
58
- ],
59
- },
60
- defaultOptions: [
61
- {
62
- commonjs: true,
63
- amd: false,
64
- },
65
- ],
66
- create(context) {
67
- const [options] = context.options;
68
- const { commonjs = true, amd = false } = options || {};
69
- function checkImport(importPath, node) {
70
- if (importPath.startsWith('..')) {
71
- context.report({
72
- node,
73
- messageId: 'preferAbsoluteImport',
74
- });
75
- }
76
- }
77
- return {
78
- ImportDeclaration(node) {
79
- const importPath = node.source.value;
80
- if (typeof importPath === 'string') {
81
- checkImport(importPath, node.source);
82
- }
83
- },
84
- CallExpression(node) {
85
- if (commonjs &&
86
- node.callee.type === 'Identifier' &&
87
- node.callee.name === 'require' &&
88
- node.arguments.length === 1) {
89
- const arg = node.arguments[0];
90
- if (arg.type === 'Literal' && typeof arg.value === 'string') {
91
- checkImport(arg.value, arg);
92
- }
93
- }
94
- if (amd &&
95
- node.callee.type === 'Identifier' &&
96
- (node.callee.name === 'define' || node.callee.name === 'require') &&
97
- node.arguments.length >= 1) {
98
- const depsArg = node.arguments[0];
99
- if (depsArg.type === 'ArrayExpression') {
100
- depsArg.elements.forEach((element) => {
101
- if (element?.type === 'Literal' &&
102
- typeof element.value === 'string') {
103
- checkImport(element.value, element);
104
- }
105
- });
106
- }
107
- }
108
- },
109
- TSImportEqualsDeclaration(node) {
110
- if (node.moduleReference.type === 'TSExternalModuleReference' &&
111
- node.moduleReference.expression.type === 'Literal' &&
112
- typeof node.moduleReference.expression.value === 'string') {
113
- checkImport(node.moduleReference.expression.value, node.moduleReference);
114
- }
115
- },
116
- };
117
- },
118
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noRelativeParentImports=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.noRelativeParentImports=(0,eslint_devkit_1.createRule)({name:"no-relative-parent-imports",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-relative-parent-imports.md",description:"Prevents ../ imports"},hasSuggestions:false,messages:{relativeParentImport:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.ARCHITECTURE,issueName:"Relative Parent Import",description:"Relative parent import (..) detected",severity:"MEDIUM",fix:"Use absolute import or move code closer to dependencies",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-relative-parent-imports.md"}),preferAbsoluteImport:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.ARCHITECTURE,issueName:"Prefer Absolute Import",description:"Parent directory import makes dependencies unclear",severity:"LOW",fix:"Use absolute import path instead of relative",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-relative-parent-imports.md"}),suggestAlias:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.ARCHITECTURE,issueName:"Import Alias Suggestion",description:"Consider using import alias for cleaner imports",severity:"LOW",fix:"Configure import alias (e.g., @/ or ~/ ) for absolute imports",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-relative-parent-imports.md"})},schema:[{type:"object",properties:{commonjs:{type:"boolean",default:true,description:"Check CommonJS require() calls."},amd:{type:"boolean",default:false,description:"Check AMD define/require calls."}},additionalProperties:false}]},defaultOptions:[{commonjs:true,amd:false}],create(context){const[options]=context.options;const{commonjs=true,amd=false}=options||{};function checkImport(importPath,node){if(importPath.startsWith("..")){context.report({node,messageId:"preferAbsoluteImport"})}}return{ImportDeclaration(node){const importPath=node.source.value;if(typeof importPath==="string"){checkImport(importPath,node.source)}},CallExpression(node){if(commonjs&&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)}}if(amd&&node.callee.type==="Identifier"&&(node.callee.name==="define"||node.callee.name==="require")&&node.arguments.length>=1){const depsArg=node.arguments[0];if(depsArg.type==="ArrayExpression"){depsArg.elements.forEach(element=>{if(element?.type==="Literal"&&typeof element.value==="string"){checkImport(element.value,element)}})}}},TSImportEqualsDeclaration(node){if(node.moduleReference.type==="TSExternalModuleReference"&&node.moduleReference.expression.type==="Literal"&&typeof node.moduleReference.expression.value==="string"){checkImport(node.moduleReference.expression.value,node.moduleReference)}}}}});
@@ -1,89 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noRestrictedPaths = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.noRestrictedPaths = (0, eslint_devkit_1.createRule)({
7
- name: 'no-restricted-paths',
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-restricted-paths.md',
12
- description: 'Enforce which files can be imported in a given folder',
13
- },
14
- hasSuggestions: false,
15
- messages: {
16
- restrictedPath: (0, eslint_devkit_2.formatLLMMessage)({
17
- icon: eslint_devkit_2.MessageIcons.ARCHITECTURE,
18
- issueName: 'Restricted Import Path',
19
- description: 'Import violates architectural boundary rules',
20
- severity: 'HIGH',
21
- fix: 'Restructure code to respect architectural boundaries',
22
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-restricted-paths.md',
23
- }),
24
- pathViolation: (0, eslint_devkit_2.formatLLMMessage)({
25
- icon: eslint_devkit_2.MessageIcons.ARCHITECTURE,
26
- issueName: 'Architecture Violation',
27
- description: 'Import crosses forbidden architectural boundary',
28
- severity: 'HIGH',
29
- fix: 'Move code or adjust import to comply with architecture rules',
30
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-restricted-paths.md',
31
- }),
32
- zoneViolation: (0, eslint_devkit_2.formatLLMMessage)({
33
- icon: eslint_devkit_2.MessageIcons.ARCHITECTURE,
34
- issueName: 'Zone Boundary Violation',
35
- description: 'Import violates defined architectural zones',
36
- severity: 'MEDIUM',
37
- fix: 'Restructure imports to respect zone boundaries',
38
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-restricted-paths.md',
39
- }),
40
- },
41
- schema: [
42
- {
43
- type: 'object',
44
- properties: {
45
- restricted: {
46
- type: 'array',
47
- items: { type: 'string' },
48
- description: 'Array of restricted path patterns',
49
- },
50
- },
51
- additionalProperties: false,
52
- },
53
- ],
54
- },
55
- defaultOptions: [{ restricted: [] }],
56
- create(context) {
57
- const [options] = context.options;
58
- const { restricted = [] } = options || {};
59
- function checkImport(importPath, node) {
60
- for (const pattern of restricted) {
61
- if (importPath.includes(pattern)) {
62
- context.report({
63
- node,
64
- messageId: 'pathViolation',
65
- });
66
- return;
67
- }
68
- }
69
- }
70
- return {
71
- ImportDeclaration(node) {
72
- const importPath = node.source.value;
73
- if (typeof importPath === 'string') {
74
- checkImport(importPath, node.source);
75
- }
76
- },
77
- CallExpression(node) {
78
- if (node.callee.type === 'Identifier' &&
79
- node.callee.name === 'require' &&
80
- node.arguments.length === 1) {
81
- const arg = node.arguments[0];
82
- if (arg.type === 'Literal' && typeof arg.value === 'string') {
83
- checkImport(arg.value, arg);
84
- }
85
- }
86
- },
87
- };
88
- },
89
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noRestrictedPaths=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.noRestrictedPaths=(0,eslint_devkit_1.createRule)({name:"no-restricted-paths",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-restricted-paths.md",description:"Enforce which files can be imported in a given folder"},hasSuggestions:false,messages:{restrictedPath:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.ARCHITECTURE,issueName:"Restricted Import Path",description:"Import violates architectural boundary rules",severity:"HIGH",fix:"Restructure code to respect architectural boundaries",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-restricted-paths.md"}),pathViolation:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.ARCHITECTURE,issueName:"Architecture Violation",description:"Import crosses forbidden architectural boundary",severity:"HIGH",fix:"Move code or adjust import to comply with architecture rules",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-restricted-paths.md"}),zoneViolation:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.ARCHITECTURE,issueName:"Zone Boundary Violation",description:"Import violates defined architectural zones",severity:"MEDIUM",fix:"Restructure imports to respect zone boundaries",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-restricted-paths.md"})},schema:[{type:"object",properties:{restricted:{type:"array",items:{type:"string"},description:"Array of restricted path patterns"}},additionalProperties:false}]},defaultOptions:[{restricted:[]}],create(context){const[options]=context.options;const{restricted=[]}=options||{};function checkImport(importPath,node){for(const pattern of restricted){if(importPath.includes(pattern)){context.report({node,messageId:"pathViolation"});return}}}return{ImportDeclaration(node){const importPath=node.source.value;if(typeof importPath==="string"){checkImport(importPath,node.source)}},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)}}}}}});
@@ -1,113 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noSelfImport = void 0;
4
- const tslib_1 = require("tslib");
5
- const path = tslib_1.__importStar(require("node:path"));
6
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
7
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
8
- function isImportingSelf(context, node, importPath) {
9
- const filename = context.filename;
10
- if (filename === '<text>') {
11
- return false;
12
- }
13
- const [options] = context.options;
14
- const { allowInTests = false } = options || {};
15
- if (allowInTests &&
16
- (filename.includes('.test.') ||
17
- filename.includes('.spec.') ||
18
- filename.includes('/__tests__/') ||
19
- filename.includes('__tests__'))) {
20
- return false;
21
- }
22
- let resolvedPath;
23
- if (importPath.startsWith('./') || importPath.startsWith('../')) {
24
- const currentDir = path.dirname(filename);
25
- resolvedPath = path.resolve(currentDir, importPath);
26
- }
27
- else if (importPath.startsWith('/')) {
28
- resolvedPath = importPath;
29
- }
30
- else {
31
- return false;
32
- }
33
- const normalizedCurrent = filename.replace(/\.[^/.]+$/, '');
34
- const normalizedImport = resolvedPath.replace(/\.[^/.]+$/, '');
35
- return normalizedCurrent === normalizedImport;
36
- }
37
- exports.noSelfImport = (0, eslint_devkit_1.createRule)({
38
- name: 'no-self-import',
39
- meta: {
40
- type: 'problem',
41
- docs: {
42
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-self-import.md',
43
- description: 'Forbid a module from importing itself',
44
- },
45
- messages: {
46
- selfImport: (0, eslint_devkit_2.formatLLMMessage)({
47
- icon: eslint_devkit_2.MessageIcons.ARCHITECTURE,
48
- issueName: 'Self Import',
49
- description: 'Module imports itself',
50
- severity: 'HIGH',
51
- fix: 'Remove the self-import statement',
52
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-self-import.md',
53
- }),
54
- },
55
- schema: [
56
- {
57
- type: 'object',
58
- properties: {
59
- allowInTests: {
60
- type: 'boolean',
61
- default: false,
62
- description: 'Allow self-imports in test files.',
63
- },
64
- },
65
- additionalProperties: false,
66
- },
67
- ],
68
- },
69
- defaultOptions: [{ allowInTests: false }],
70
- create(context) {
71
- function visitModule(source, node) {
72
- const importPath = source.value;
73
- if (typeof importPath === 'string' &&
74
- isImportingSelf(context, node, importPath)) {
75
- context.report({
76
- node: source,
77
- messageId: 'selfImport',
78
- });
79
- }
80
- }
81
- return {
82
- ImportDeclaration(node) {
83
- if (node.importKind === 'type') {
84
- return;
85
- }
86
- visitModule(node.source, node);
87
- },
88
- CallExpression(node) {
89
- if (node.callee.type === 'Identifier' &&
90
- node.callee.name === 'require' &&
91
- node.arguments.length === 1) {
92
- const arg = node.arguments[0];
93
- if (arg.type === 'Literal') {
94
- visitModule(arg, node);
95
- }
96
- }
97
- },
98
- ImportExpression(node) {
99
- if (node.source.type === 'Literal') {
100
- visitModule(node.source, node);
101
- }
102
- },
103
- ExportNamedDeclaration(node) {
104
- if (node.source) {
105
- visitModule(node.source, node);
106
- }
107
- },
108
- ExportAllDeclaration(node) {
109
- visitModule(node.source, node);
110
- },
111
- };
112
- },
113
- });
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(o,m,k,k2){if(k2===void 0)k2=k;var desc=Object.getOwnPropertyDescriptor(m,k);if(!desc||("get"in desc?!m.__esModule:desc.writable||desc.configurable)){desc={enumerable:true,get:function(){return m[k]}}}Object.defineProperty(o,k2,desc)}):(function(o,m,k,k2){if(k2===void 0)k2=k;o[k2]=m[k]}));var __setModuleDefault=this&&this.__setModuleDefault||(Object.create?(function(o,v){Object.defineProperty(o,"default",{enumerable:true,value:v})}):function(o,v){o["default"]=v});var __importStar=this&&this.__importStar||(function(){var ownKeys=function(o){ownKeys=Object.getOwnPropertyNames||function(o2){var ar=[];for(var k in o2)if(Object.prototype.hasOwnProperty.call(o2,k))ar[ar.length]=k;return ar};return ownKeys(o)};return function(mod){if(mod&&mod.__esModule)return mod;var result={};if(mod!=null){for(var k=ownKeys(mod),i=0;i<k.length;i++)if(k[i]!=="default")__createBinding(result,mod,k[i])}__setModuleDefault(result,mod);return result}})();Object.defineProperty(exports,"__esModule",{value:true});exports.noSelfImport=void 0;const path=__importStar(require("node:path"));const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");function isImportingSelf(context,node,importPath){const filename=context.filename;if(filename==="<text>"){return false}const[options]=context.options;const{allowInTests=false}=options||{};if(allowInTests&&(filename.includes(".test.")||filename.includes(".spec.")||filename.includes("/__tests__/")||filename.includes("__tests__"))){return false}let resolvedPath;if(importPath.startsWith("./")||importPath.startsWith("../")){const currentDir=path.dirname(filename);resolvedPath=path.resolve(currentDir,importPath)}else if(importPath.startsWith("/")){resolvedPath=importPath}else{return false}const normalizedCurrent=filename.replace(/\.[^/.]+$/,"");const normalizedImport=resolvedPath.replace(/\.[^/.]+$/,"");return normalizedCurrent===normalizedImport}exports.noSelfImport=(0,eslint_devkit_1.createRule)({name:"no-self-import",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-self-import.md",description:"Forbid a module from importing itself"},messages:{selfImport:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.ARCHITECTURE,issueName:"Self Import",description:"Module imports itself",severity:"HIGH",fix:"Remove the self-import statement",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-self-import.md"})},schema:[{type:"object",properties:{allowInTests:{type:"boolean",default:false,description:"Allow self-imports in test files."}},additionalProperties:false}]},defaultOptions:[{allowInTests:false}],create(context){function visitModule(source,node){const importPath=source.value;if(typeof importPath==="string"&&isImportingSelf(context,node,importPath)){context.report({node:source,messageId:"selfImport"})}}return{ImportDeclaration(node){if(node.importKind==="type"){return}visitModule(node.source,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"){visitModule(arg,node)}}},ImportExpression(node){if(node.source.type==="Literal"){visitModule(node.source,node)}},ExportNamedDeclaration(node){if(node.source){visitModule(node.source,node)}},ExportAllDeclaration(node){visitModule(node.source,node)}}}});
@@ -1,115 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noUnassignedImport = void 0;
4
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
5
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
6
- exports.noUnassignedImport = (0, eslint_devkit_1.createRule)({
7
- name: 'no-unassigned-import',
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-unassigned-import.md',
12
- description: 'Prevents unassigned imports',
13
- },
14
- hasSuggestions: false,
15
- messages: {
16
- unassignedImport: (0, eslint_devkit_2.formatLLMMessage)({
17
- icon: eslint_devkit_2.MessageIcons.ARCHITECTURE,
18
- issueName: 'Unassigned Import',
19
- description: 'Import statement without variable assignment',
20
- severity: 'MEDIUM',
21
- fix: 'Assign import to variable or use side-effect comment',
22
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-unassigned-import.md',
23
- }),
24
- sideEffectOnly: (0, eslint_devkit_2.formatLLMMessage)({
25
- icon: eslint_devkit_2.MessageIcons.ARCHITECTURE,
26
- issueName: 'Side Effect Import',
27
- description: 'Import for side effects should be documented',
28
- severity: 'LOW',
29
- fix: 'Add comment explaining side effect or assign to variable',
30
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-unassigned-import.md',
31
- }),
32
- missingAssignment: (0, eslint_devkit_2.formatLLMMessage)({
33
- icon: eslint_devkit_2.MessageIcons.ARCHITECTURE,
34
- issueName: 'Missing Import Assignment',
35
- description: 'Import requires explicit variable assignment',
36
- severity: 'HIGH',
37
- fix: 'Import must be assigned to variable for tracking',
38
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-unassigned-import.md',
39
- }),
40
- },
41
- schema: [
42
- {
43
- type: 'object',
44
- properties: {
45
- allowModules: {
46
- type: 'array',
47
- items: {
48
- type: 'string',
49
- },
50
- description: 'Allow specific modules to be imported without assignment.',
51
- },
52
- },
53
- additionalProperties: false,
54
- },
55
- ],
56
- },
57
- defaultOptions: [
58
- {
59
- allowModules: [],
60
- },
61
- ],
62
- create(context) {
63
- const [options] = context.options;
64
- const { allowModules = [] } = options || {};
65
- function shouldAllow(importPath) {
66
- return allowModules.includes(importPath);
67
- }
68
- return {
69
- ImportDeclaration(node) {
70
- const importPath = node.source.value;
71
- if (typeof importPath !== 'string') {
72
- return;
73
- }
74
- if (shouldAllow(importPath)) {
75
- return;
76
- }
77
- const hasSpecifiers = node.specifiers && node.specifiers.length > 0;
78
- if (!hasSpecifiers) {
79
- context.report({
80
- node: node.source,
81
- messageId: 'unassignedImport',
82
- });
83
- }
84
- },
85
- CallExpression(node) {
86
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
87
- node.callee.name === 'require' &&
88
- node.arguments.length === 1) {
89
- const arg = node.arguments[0];
90
- if (arg.type === 'Literal' && typeof arg.value === 'string') {
91
- if (!shouldAllow(arg.value)) {
92
- const parent = node.parent;
93
- if (parent && parent.type === eslint_devkit_1.AST_NODE_TYPES.ExpressionStatement) {
94
- context.report({
95
- node: arg,
96
- messageId: 'unassignedImport',
97
- });
98
- }
99
- else if (parent &&
100
- parent.type === eslint_devkit_1.AST_NODE_TYPES.SequenceExpression) {
101
- const expressions = parent.expressions;
102
- if (expressions[expressions.length - 1] !== node) {
103
- context.report({
104
- node: arg,
105
- messageId: 'unassignedImport',
106
- });
107
- }
108
- }
109
- }
110
- }
111
- }
112
- },
113
- };
114
- },
115
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.noUnassignedImport=void 0;const eslint_devkit_1=require("@interlace/eslint-devkit");const eslint_devkit_2=require("@interlace/eslint-devkit");exports.noUnassignedImport=(0,eslint_devkit_1.createRule)({name:"no-unassigned-import",meta:{type:"problem",docs:{url:"https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-unassigned-import.md",description:"Prevents unassigned imports"},hasSuggestions:false,messages:{unassignedImport:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.ARCHITECTURE,issueName:"Unassigned Import",description:"Import statement without variable assignment",severity:"MEDIUM",fix:"Assign import to variable or use side-effect comment",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-unassigned-import.md"}),sideEffectOnly:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.ARCHITECTURE,issueName:"Side Effect Import",description:"Import for side effects should be documented",severity:"LOW",fix:"Add comment explaining side effect or assign to variable",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-unassigned-import.md"}),missingAssignment:(0,eslint_devkit_2.formatLLMMessage)({icon:eslint_devkit_2.MessageIcons.ARCHITECTURE,issueName:"Missing Import Assignment",description:"Import requires explicit variable assignment",severity:"HIGH",fix:"Import must be assigned to variable for tracking",documentationLink:"https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-unassigned-import.md"})},schema:[{type:"object",properties:{allowModules:{type:"array",items:{type:"string"},description:"Allow specific modules to be imported without assignment."}},additionalProperties:false}]},defaultOptions:[{allowModules:[]}],create(context){const[options]=context.options;const{allowModules=[]}=options||{};function shouldAllow(importPath){return allowModules.includes(importPath)}return{ImportDeclaration(node){const importPath=node.source.value;if(typeof importPath!=="string"){return}if(shouldAllow(importPath)){return}const hasSpecifiers=node.specifiers&&node.specifiers.length>0;if(!hasSpecifiers){context.report({node:node.source,messageId:"unassignedImport"})}},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(arg.type==="Literal"&&typeof arg.value==="string"){if(!shouldAllow(arg.value)){const parent=node.parent;if(parent&&parent.type===eslint_devkit_1.AST_NODE_TYPES.ExpressionStatement){context.report({node:arg,messageId:"unassignedImport"})}else if(parent&&parent.type===eslint_devkit_1.AST_NODE_TYPES.SequenceExpression){const expressions=parent.expressions;if(expressions[expressions.length-1]!==node){context.report({node:arg,messageId:"unassignedImport"})}}}}}}}}});