eslint-plugin-import-next 2.3.15 → 2.3.17

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 (63) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -3
  3. package/src/files/foo.js +1 -6
  4. package/src/files/no-default.js +1 -4
  5. package/src/index.js +1 -273
  6. package/src/oxlint.js +1 -3
  7. package/src/rules/consistent-type-specifier-style.js +1 -109
  8. package/src/rules/default.js +1 -56
  9. package/src/rules/dynamic-import-chunkname.js +1 -115
  10. package/src/rules/enforce-dependency-direction.js +1 -213
  11. package/src/rules/enforce-import-order.js +1 -299
  12. package/src/rules/enforce-team-boundaries.js +1 -191
  13. package/src/rules/export.js +1 -111
  14. package/src/rules/exports-last.js +1 -67
  15. package/src/rules/extensions.js +1 -107
  16. package/src/rules/first.js +1 -53
  17. package/src/rules/group-exports.js +1 -69
  18. package/src/rules/max-dependencies.js +1 -241
  19. package/src/rules/named.js +1 -67
  20. package/src/rules/namespace.js +1 -64
  21. package/src/rules/newline-after-import.js +1 -57
  22. package/src/rules/no-absolute-path.js +1 -139
  23. package/src/rules/no-amd.js +1 -108
  24. package/src/rules/no-anonymous-default-export.js +1 -135
  25. package/src/rules/no-barrel-file.js +1 -194
  26. package/src/rules/no-barrel-import.js +1 -135
  27. package/src/rules/no-commonjs.js +1 -312
  28. package/src/rules/no-cross-domain-imports.js +1 -233
  29. package/src/rules/no-cycle.js +2 -396
  30. package/src/rules/no-default-export.js +2 -213
  31. package/src/rules/no-deprecated.js +1 -316
  32. package/src/rules/no-duplicates.js +1 -81
  33. package/src/rules/no-dynamic-require.js +1 -78
  34. package/src/rules/no-empty-named-blocks.js +1 -103
  35. package/src/rules/no-extraneous-dependencies.js +7 -385
  36. package/src/rules/no-full-package-import.js +1 -134
  37. package/src/rules/no-import-module-exports.js +1 -76
  38. package/src/rules/no-internal-modules.js +1 -256
  39. package/src/rules/no-legacy-imports.js +1 -125
  40. package/src/rules/no-mutable-exports.js +1 -146
  41. package/src/rules/no-named-as-default-member.js +1 -73
  42. package/src/rules/no-named-as-default.js +1 -90
  43. package/src/rules/no-named-default.js +1 -48
  44. package/src/rules/no-named-export.js +1 -174
  45. package/src/rules/no-namespace.js +1 -71
  46. package/src/rules/no-nodejs-modules.js +1 -229
  47. package/src/rules/no-relative-packages.js +1 -161
  48. package/src/rules/no-relative-parent-imports.js +1 -118
  49. package/src/rules/no-restricted-paths.js +1 -89
  50. package/src/rules/no-self-import.js +1 -145
  51. package/src/rules/no-unassigned-import.js +1 -115
  52. package/src/rules/no-unresolved.js +1 -189
  53. package/src/rules/no-unused-modules.js +1 -82
  54. package/src/rules/no-useless-path-segments.js +1 -139
  55. package/src/rules/prefer-default-export.js +1 -188
  56. package/src/rules/prefer-direct-import.js +1 -170
  57. package/src/rules/prefer-modern-api.js +1 -212
  58. package/src/rules/prefer-node-protocol.js +1 -174
  59. package/src/rules/prefer-tree-shakeable-imports.js +1 -134
  60. package/src/rules/require-import-approval.js +1 -174
  61. package/src/rules/unambiguous.js +1 -70
  62. package/src/types/index.js +1 -2
  63. package/src/utils/typescript-peer.js +1 -23
@@ -1,161 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.noRelativePackages = void 0;
37
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
38
- const path = __importStar(require("node:path"));
39
- const fs = __importStar(require("node:fs"));
40
- const packageJsonCache = new Map();
41
- function findPackageJson(startDir) {
42
- if (packageJsonCache.has(startDir)) {
43
- return packageJsonCache.get(startDir) ?? null;
44
- }
45
- let currentDir = startDir;
46
- while (currentDir !== path.dirname(currentDir)) {
47
- const pkgPath = path.join(currentDir, 'package.json');
48
- if (fs.existsSync(pkgPath)) {
49
- packageJsonCache.set(startDir, currentDir);
50
- return currentDir;
51
- }
52
- currentDir = path.dirname(currentDir);
53
- }
54
- packageJsonCache.set(startDir, null);
55
- return null;
56
- }
57
- exports.noRelativePackages = (0, eslint_devkit_1.createRule)({
58
- name: 'no-relative-packages',
59
- meta: {
60
- type: 'suggestion',
61
- docs: {
62
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-relative-packages.md',
63
- description: 'Forbid importing packages through relative paths',
64
- cwe: 'CWE-1047',
65
- cvss: 5,
66
- },
67
- fixable: 'code',
68
- messages: {
69
- relativePackage: (0, eslint_devkit_1.formatLLMMessage)({
70
- icon: eslint_devkit_1.MessageIcons.ARCHITECTURE,
71
- issueName: 'Relative Package Import',
72
- cwe: 'CWE-1047',
73
- description: 'Relative import from another package: {{importPath}}. Use package name instead: {{packageName}}',
74
- severity: 'MEDIUM',
75
- fix: 'Import using the package name: {{packageName}}',
76
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-relative-packages.md',
77
- }),
78
- },
79
- schema: [
80
- {
81
- type: 'object',
82
- properties: {
83
- allowSamePackage: { type: 'boolean', default: true },
84
- },
85
- additionalProperties: false,
86
- },
87
- ],
88
- },
89
- defaultOptions: [{ allowSamePackage: true }],
90
- create(context) {
91
- const options = context.options[0] || {};
92
- const { allowSamePackage = true } = options;
93
- const filename = context.filename;
94
- const currentDir = path.dirname(filename);
95
- const currentPackageRoot = findPackageJson(currentDir);
96
- function checkImport(node, source) {
97
- const importPath = source.value;
98
- if (typeof importPath !== 'string')
99
- return;
100
- if (!importPath.startsWith('./') && !importPath.startsWith('../')) {
101
- return;
102
- }
103
- const resolvedPath = path.resolve(currentDir, importPath);
104
- const importPackageRoot = findPackageJson(path.dirname(resolvedPath));
105
- if (allowSamePackage && currentPackageRoot === importPackageRoot) {
106
- return;
107
- }
108
- if (!currentPackageRoot || !importPackageRoot) {
109
- return;
110
- }
111
- if (currentPackageRoot !== importPackageRoot) {
112
- try {
113
- const pkgJsonPath = path.join(importPackageRoot, 'package.json');
114
- const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
115
- const packageName = pkgJson.name || path.basename(importPackageRoot);
116
- context.report({
117
- node: source,
118
- messageId: 'relativePackage',
119
- data: {
120
- importPath,
121
- packageName,
122
- },
123
- fix(fixer) {
124
- const subPath = path.relative(importPackageRoot, resolvedPath);
125
- const newImport = `${packageName}/${subPath.replace(/\.[^/.]+$/, '')}`;
126
- return fixer.replaceText(source, `'${newImport}'`);
127
- },
128
- });
129
- }
130
- catch {
131
- context.report({
132
- node: source,
133
- messageId: 'relativePackage',
134
- data: {
135
- importPath,
136
- packageName: path.basename(importPackageRoot),
137
- },
138
- });
139
- }
140
- }
141
- }
142
- return {
143
- ImportDeclaration(node) {
144
- checkImport(node, node.source);
145
- },
146
- ImportExpression(node) {
147
- if (node.source.type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
148
- checkImport(node, node.source);
149
- }
150
- },
151
- CallExpression(node) {
152
- if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
153
- node.callee.name === 'require' &&
154
- node.arguments.length === 1 &&
155
- node.arguments[0].type === eslint_devkit_1.AST_NODE_TYPES.Literal) {
156
- checkImport(node, node.arguments[0]);
157
- }
158
- },
159
- };
160
- },
161
- });
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,145 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.noSelfImport = void 0;
37
- const path = __importStar(require("node:path"));
38
- const eslint_devkit_1 = require("@interlace/eslint-devkit");
39
- const eslint_devkit_2 = require("@interlace/eslint-devkit");
40
- function isImportingSelf(context, node, importPath) {
41
- const filename = context.filename;
42
- if (filename === '<text>') {
43
- return false;
44
- }
45
- const [options] = context.options;
46
- const { allowInTests = false } = options || {};
47
- if (allowInTests &&
48
- (filename.includes('.test.') ||
49
- filename.includes('.spec.') ||
50
- filename.includes('/__tests__/') ||
51
- filename.includes('__tests__'))) {
52
- return false;
53
- }
54
- let resolvedPath;
55
- if (importPath.startsWith('./') || importPath.startsWith('../')) {
56
- const currentDir = path.dirname(filename);
57
- resolvedPath = path.resolve(currentDir, importPath);
58
- }
59
- else if (importPath.startsWith('/')) {
60
- resolvedPath = importPath;
61
- }
62
- else {
63
- return false;
64
- }
65
- const normalizedCurrent = filename.replace(/\.[^/.]+$/, '');
66
- const normalizedImport = resolvedPath.replace(/\.[^/.]+$/, '');
67
- return normalizedCurrent === normalizedImport;
68
- }
69
- exports.noSelfImport = (0, eslint_devkit_1.createRule)({
70
- name: 'no-self-import',
71
- meta: {
72
- type: 'problem',
73
- docs: {
74
- url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-import-next/docs/rules/no-self-import.md',
75
- description: 'Forbid a module from importing itself',
76
- },
77
- messages: {
78
- selfImport: (0, eslint_devkit_2.formatLLMMessage)({
79
- icon: eslint_devkit_2.MessageIcons.ARCHITECTURE,
80
- issueName: 'Self Import',
81
- description: 'Module imports itself',
82
- severity: 'HIGH',
83
- fix: 'Remove the self-import statement',
84
- documentationLink: 'https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-self-import.md',
85
- }),
86
- },
87
- schema: [
88
- {
89
- type: 'object',
90
- properties: {
91
- allowInTests: {
92
- type: 'boolean',
93
- default: false,
94
- description: 'Allow self-imports in test files.',
95
- },
96
- },
97
- additionalProperties: false,
98
- },
99
- ],
100
- },
101
- defaultOptions: [{ allowInTests: false }],
102
- create(context) {
103
- function visitModule(source, node) {
104
- const importPath = source.value;
105
- if (typeof importPath === 'string' &&
106
- isImportingSelf(context, node, importPath)) {
107
- context.report({
108
- node: source,
109
- messageId: 'selfImport',
110
- });
111
- }
112
- }
113
- return {
114
- ImportDeclaration(node) {
115
- if (node.importKind === 'type') {
116
- return;
117
- }
118
- visitModule(node.source, node);
119
- },
120
- CallExpression(node) {
121
- if (node.callee.type === 'Identifier' &&
122
- node.callee.name === 'require' &&
123
- node.arguments.length === 1) {
124
- const arg = node.arguments[0];
125
- if (arg.type === 'Literal') {
126
- visitModule(arg, node);
127
- }
128
- }
129
- },
130
- ImportExpression(node) {
131
- if (node.source.type === 'Literal') {
132
- visitModule(node.source, node);
133
- }
134
- },
135
- ExportNamedDeclaration(node) {
136
- if (node.source) {
137
- visitModule(node.source, node);
138
- }
139
- },
140
- ExportAllDeclaration(node) {
141
- visitModule(node.source, node);
142
- },
143
- };
144
- },
145
- });
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"})}}}}}}}}});