eslint-plugin-barrel-rules 1.3.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.ko.md CHANGED
@@ -3,7 +3,7 @@
3
3
  # **Advanced Barrel Pattern Enforcement for JavaScript/TypeScript Projects**
4
4
 
5
5
  <div align="center">
6
- <img src="https://img.shields.io/badge/version-1.3.1-blue.svg" alt="Version"/>
6
+ <img src="https://img.shields.io/badge/version-1.4.2-blue.svg" alt="Version"/>
7
7
  <img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License"/>
8
8
  <img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs Welcome"/>
9
9
  </div>
@@ -282,6 +282,7 @@ import { SharedUtil } from "@shared/utils"; // allowedImportPaths에 "src/shared
282
282
  - **잘못된 경로 설정 검증 기능** (OK)
283
283
  - **와일드카드 import/export 제한 규칙** (OK)
284
284
  - **지정한 Barrel 경로 격리** (OK)
285
+ - **빈 디렉토리 지원** (예: 'src/shares/\*'가 설정되어 있어도 shares 디렉토리가 비어있어도 됨) (OK)
285
286
 
286
287
  ---
287
288
 
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  # **Advanced Barrel Pattern Enforcement for JavaScript/TypeScript Projects**
4
4
 
5
5
  <div align="center">
6
- <img src="https://img.shields.io/badge/version-1.3.1-blue.svg" alt="Version"/>
6
+ <img src="https://img.shields.io/badge/version-1.4.2-blue.svg" alt="Version"/>
7
7
  <img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License"/>
8
8
  <img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs Welcome"/>
9
9
  </div>
@@ -291,6 +291,7 @@ import { SharedUtil } from "@shared/utils"; // if "src/shared/*" is in allowedPa
291
291
  - **Wrong Path Setup Validator** (OK)
292
292
  - **Wildcard Import/Export Protection Rule** (OK)
293
293
  - **Isolation Barrel Module** (OK)
294
+ - **Empty Directory Support** (e.g., 'src/shares/\*' can be configured even if the shares directory is empty) (OK)
294
295
 
295
296
  ---
296
297
 
package/dist/index.cjs CHANGED
@@ -30,7 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- default: () => index_default
33
+ rules: () => rules
34
34
  });
35
35
  module.exports = __toCommonJS(index_exports);
36
36
 
@@ -48,11 +48,6 @@ var Glob = class {
48
48
  onlyDirectories: true,
49
49
  absolute: true
50
50
  });
51
- if (globResult.length === 0) {
52
- throw new Error(
53
- `[Glob] In baseDir: ${baseDir}, path: ${path4}, any directory was not found`
54
- );
55
- }
56
51
  return globResult;
57
52
  }
58
53
  };
@@ -111,33 +106,59 @@ var Alias = class {
111
106
  }
112
107
  };
113
108
 
114
- // src/rules/enforce-barrel-pattern.ts
109
+ // src/utils/constants.ts
115
110
  var BARREL_ENTRY_POINT_FILE_NAMES = [
116
111
  "index.ts",
112
+ // TypeScript entry
117
113
  "index.tsx",
114
+ // React TypeScript entry
118
115
  "index.js",
116
+ // JavaScript entry
119
117
  "index.jsx",
118
+ // React JavaScript entry
120
119
  "index.cjs",
121
- "index.mjs",
122
- "index.d.ts"
120
+ // CommonJS entry
121
+ "index.mjs"
122
+ // ES Module entry
123
123
  ];
124
124
  var RESOLVE_EXTENSIONS = [
125
125
  ".ts",
126
+ // TypeScript
126
127
  ".js",
128
+ // JavaScript
127
129
  ".tsx",
130
+ // React TypeScript
128
131
  ".jsx",
132
+ // React JavaScript
129
133
  ".json",
134
+ // JSON file
135
+ // Type declaration and transformed files
130
136
  ".d.js",
137
+ // JS file with type declarations (rare)
131
138
  ".d.ts",
139
+ // Type declaration file
140
+ // Various module systems
132
141
  ".mjs",
142
+ // ES Module
133
143
  ".cjs",
144
+ // CommonJS
145
+ // Module-related TypeScript extensions
134
146
  ".mts",
147
+ // ES Module TypeScript
135
148
  ".cts",
149
+ // CommonJS TypeScript
150
+ // Type declarations for module-related files
136
151
  ".d.mjs",
152
+ // Type declarations for ES Module
137
153
  ".d.cjs",
154
+ // Type declarations for CommonJS
138
155
  ".d.mts",
156
+ // Type declarations for ES Module TS
139
157
  ".d.cts"
158
+ // Type declarations for CommonJS TS
140
159
  ];
160
+
161
+ // src/rules/enforce-barrel-pattern.ts
141
162
  var enforceBarrelPattern = {
142
163
  meta: {
143
164
  type: "problem",
@@ -190,66 +211,78 @@ var enforceBarrelPattern = {
190
211
  const absoluteTargetPaths = option.paths.flatMap((_path) => {
191
212
  return Glob.resolvePath(_path, baseDir);
192
213
  });
193
- return {
194
- //check only import declaration(ESM)
195
- ImportDeclaration(node) {
196
- const rawImportPath = node.source.value;
197
- const absoluteCurrentFilePath = context.getFilename();
198
- let absoluteImportPath = null;
199
- try {
200
- const aliasResult = Alias.resolvePath(
201
- rawImportPath,
202
- import_path2.default.dirname(absoluteCurrentFilePath)
203
- );
204
- if (aliasResult.type === "success") {
205
- absoluteImportPath = aliasResult.absolutePath;
206
- } else {
207
- if (!rawImportPath.startsWith(".") && !rawImportPath.startsWith("/") || rawImportPath.includes("/node_modules/")) {
208
- return;
209
- }
210
- absoluteImportPath = import_resolve.default.sync(rawImportPath, {
211
- basedir: import_path2.default.dirname(absoluteCurrentFilePath),
212
- extensions: RESOLVE_EXTENSIONS
213
- });
214
+ function checker(node) {
215
+ if (!node.source) {
216
+ return;
217
+ }
218
+ const rawImportPath = node.source.value;
219
+ const absoluteCurrentFilePath = context.getFilename();
220
+ let absoluteImportPath = null;
221
+ try {
222
+ const aliasResult = Alias.resolvePath(
223
+ rawImportPath,
224
+ import_path2.default.dirname(absoluteCurrentFilePath)
225
+ );
226
+ if (aliasResult.type === "success") {
227
+ absoluteImportPath = aliasResult.absolutePath;
228
+ } else {
229
+ if (!rawImportPath.startsWith(".") && !rawImportPath.startsWith("/") || rawImportPath.includes("/node_modules/")) {
230
+ return;
214
231
  }
215
- } catch (e) {
216
- context.report({
217
- node,
218
- messageId: "TransformedAliasResolveFailed"
232
+ absoluteImportPath = import_resolve.default.sync(rawImportPath, {
233
+ basedir: import_path2.default.dirname(absoluteCurrentFilePath),
234
+ extensions: RESOLVE_EXTENSIONS
219
235
  });
220
- return;
221
236
  }
222
- {
223
- let matchedLatestTargetPath = null;
224
- const invalidDirectedImport = absoluteTargetPaths.some(
225
- (absoluteTargetPath) => {
226
- const targetPathEntryPoints = BARREL_ENTRY_POINT_FILE_NAMES.map(
227
- (entry) => import_path2.default.resolve(absoluteTargetPath, entry)
228
- );
229
- const closedTargetPath = absoluteTargetPath + "/";
230
- const targetPathEntryPointed = targetPathEntryPoints.includes(absoluteImportPath);
231
- const importedEnforceBarrelFile = absoluteImportPath.startsWith(closedTargetPath);
232
- const currentFileInEnforceBarrel = absoluteCurrentFilePath.startsWith(closedTargetPath);
233
- const importedOutsideOfTargetPath = !currentFileInEnforceBarrel && importedEnforceBarrelFile;
234
- const invalidImported = !targetPathEntryPointed && importedOutsideOfTargetPath;
235
- if (invalidImported) {
236
- matchedLatestTargetPath = absoluteTargetPath;
237
- }
238
- return invalidImported;
237
+ } catch (e) {
238
+ context.report({
239
+ node,
240
+ messageId: "TransformedAliasResolveFailed"
241
+ });
242
+ return;
243
+ }
244
+ {
245
+ let matchedLatestTargetPath = null;
246
+ const invalidDirectedImport = absoluteTargetPaths.some(
247
+ (absoluteTargetPath) => {
248
+ const targetPathEntryPoints = BARREL_ENTRY_POINT_FILE_NAMES.map(
249
+ (entry) => import_path2.default.resolve(absoluteTargetPath, entry)
250
+ );
251
+ const closedTargetPath = absoluteTargetPath + "/";
252
+ const targetPathEntryPointed = targetPathEntryPoints.includes(absoluteImportPath);
253
+ const importedEnforceBarrelFile = absoluteImportPath.startsWith(closedTargetPath);
254
+ const currentFileInEnforceBarrel = absoluteCurrentFilePath.startsWith(closedTargetPath);
255
+ const importedOutsideOfTargetPath = !currentFileInEnforceBarrel && importedEnforceBarrelFile;
256
+ const invalidImported = !targetPathEntryPointed && importedOutsideOfTargetPath;
257
+ if (invalidImported) {
258
+ matchedLatestTargetPath = absoluteTargetPath;
239
259
  }
240
- );
241
- if (invalidDirectedImport) {
242
- context.report({
243
- node,
244
- messageId: "DirectImportDisallowed",
245
- data: {
246
- rawImportPath,
247
- matchedTargetPath: matchedLatestTargetPath
248
- }
249
- });
260
+ return invalidImported;
250
261
  }
262
+ );
263
+ if (invalidDirectedImport) {
264
+ context.report({
265
+ node,
266
+ messageId: "DirectImportDisallowed",
267
+ data: {
268
+ rawImportPath,
269
+ matchedTargetPath: matchedLatestTargetPath
270
+ }
271
+ });
251
272
  }
252
273
  }
274
+ }
275
+ return {
276
+ ExportNamedDeclaration(node) {
277
+ return checker(node);
278
+ },
279
+ ExportAllDeclaration(node) {
280
+ return checker(node);
281
+ },
282
+ //check only import declaration(ESM)
283
+ ImportDeclaration(node) {
284
+ return checker(node);
285
+ }
253
286
  };
254
287
  }
255
288
  };
@@ -258,23 +291,6 @@ var enforceBarrelPattern = {
258
291
  var import_types2 = require("@typescript-eslint/types");
259
292
  var import_path3 = __toESM(require("path"), 1);
260
293
  var import_resolve2 = __toESM(require("resolve"), 1);
261
- var RESOLVE_EXTENSIONS2 = [
262
- ".ts",
263
- ".js",
264
- ".tsx",
265
- ".jsx",
266
- ".json",
267
- ".d.js",
268
- ".d.ts",
269
- ".mjs",
270
- ".cjs",
271
- ".mts",
272
- ".cts",
273
- ".d.mjs",
274
- ".d.cjs",
275
- ".d.mts",
276
- ".d.cts"
277
- ];
278
294
  var isolateBarrelFile = {
279
295
  meta: {
280
296
  type: "problem",
@@ -327,6 +343,9 @@ var isolateBarrelFile = {
327
343
  //check only import declaration(ESM)
328
344
  ImportDeclaration(node) {
329
345
  const rawImportPath = node.source.value;
346
+ if (rawImportPath.includes("/node_modules/")) {
347
+ return;
348
+ }
330
349
  const absoluteCurrentFilePath = context.getFilename();
331
350
  let absoluteImportPath = null;
332
351
  try {
@@ -336,13 +355,16 @@ var isolateBarrelFile = {
336
355
  );
337
356
  if (aliasResult.type === "success") {
338
357
  absoluteImportPath = aliasResult.absolutePath;
358
+ if (absoluteImportPath.includes("/node_modules/")) {
359
+ return;
360
+ }
339
361
  } else {
340
- if (!rawImportPath.startsWith(".") && !rawImportPath.startsWith("/") || rawImportPath.includes("/node_modules/")) {
362
+ if (!rawImportPath.startsWith(".") && !rawImportPath.startsWith("/")) {
341
363
  return;
342
364
  }
343
365
  absoluteImportPath = import_resolve2.default.sync(rawImportPath, {
344
366
  basedir: import_path3.default.dirname(absoluteCurrentFilePath),
345
- extensions: RESOLVE_EXTENSIONS2
367
+ extensions: RESOLVE_EXTENSIONS
346
368
  });
347
369
  }
348
370
  } catch (e) {
@@ -430,6 +452,9 @@ var rules = {
430
452
  "enforce-barrel-pattern": enforceBarrelPattern,
431
453
  "isolate-barrel-file": isolateBarrelFile,
432
454
  "no-wildcard": noWildcard
455
+ // "no-cycle": noCycle,
433
456
  };
434
- var index_default = { rules };
435
- module.exports = { rules };
457
+ // Annotate the CommonJS export names for ESM import in node:
458
+ 0 && (module.exports = {
459
+ rules
460
+ });
package/dist/index.d.cts CHANGED
@@ -1,21 +1,19 @@
1
1
  import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
2
2
 
3
- declare const _default: {
4
- rules: {
5
- "enforce-barrel-pattern": _typescript_eslint_utils_ts_eslint.RuleModule<"DirectImportDisallowed" | "TransformedAliasResolveFailed" | "EmptyEslintConfig", {
6
- paths: string[];
7
- baseDir: string;
8
- }[], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
9
- "isolate-barrel-file": _typescript_eslint_utils_ts_eslint.RuleModule<"TransformedAliasResolveFailed" | "IsolatedBarrelImportDisallowed", {
10
- isolations: {
11
- path: string;
12
- allowedPaths: string[];
13
- }[];
14
- baseDir: string;
15
- globalAllowPaths: string[];
16
- }[], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
17
- "no-wildcard": _typescript_eslint_utils_ts_eslint.RuleModule<"NoWildcardImport" | "NoExportAll", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
18
- };
3
+ declare const rules: {
4
+ "enforce-barrel-pattern": _typescript_eslint_utils_ts_eslint.RuleModule<"DirectImportDisallowed" | "TransformedAliasResolveFailed" | "EmptyEslintConfig", {
5
+ paths: string[];
6
+ baseDir: string;
7
+ }[], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
8
+ "isolate-barrel-file": _typescript_eslint_utils_ts_eslint.RuleModule<"TransformedAliasResolveFailed" | "IsolatedBarrelImportDisallowed", {
9
+ isolations: {
10
+ path: string;
11
+ allowedPaths: string[];
12
+ }[];
13
+ baseDir: string;
14
+ globalAllowPaths: string[];
15
+ }[], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
16
+ "no-wildcard": _typescript_eslint_utils_ts_eslint.RuleModule<"NoWildcardImport" | "NoExportAll", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
19
17
  };
20
18
 
21
- export { _default as default };
19
+ export { rules };
package/dist/index.d.ts CHANGED
@@ -1,21 +1,19 @@
1
1
  import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
2
2
 
3
- declare const _default: {
4
- rules: {
5
- "enforce-barrel-pattern": _typescript_eslint_utils_ts_eslint.RuleModule<"DirectImportDisallowed" | "TransformedAliasResolveFailed" | "EmptyEslintConfig", {
6
- paths: string[];
7
- baseDir: string;
8
- }[], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
9
- "isolate-barrel-file": _typescript_eslint_utils_ts_eslint.RuleModule<"TransformedAliasResolveFailed" | "IsolatedBarrelImportDisallowed", {
10
- isolations: {
11
- path: string;
12
- allowedPaths: string[];
13
- }[];
14
- baseDir: string;
15
- globalAllowPaths: string[];
16
- }[], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
17
- "no-wildcard": _typescript_eslint_utils_ts_eslint.RuleModule<"NoWildcardImport" | "NoExportAll", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
18
- };
3
+ declare const rules: {
4
+ "enforce-barrel-pattern": _typescript_eslint_utils_ts_eslint.RuleModule<"DirectImportDisallowed" | "TransformedAliasResolveFailed" | "EmptyEslintConfig", {
5
+ paths: string[];
6
+ baseDir: string;
7
+ }[], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
8
+ "isolate-barrel-file": _typescript_eslint_utils_ts_eslint.RuleModule<"TransformedAliasResolveFailed" | "IsolatedBarrelImportDisallowed", {
9
+ isolations: {
10
+ path: string;
11
+ allowedPaths: string[];
12
+ }[];
13
+ baseDir: string;
14
+ globalAllowPaths: string[];
15
+ }[], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
16
+ "no-wildcard": _typescript_eslint_utils_ts_eslint.RuleModule<"NoWildcardImport" | "NoExportAll", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
19
17
  };
20
18
 
21
- export { _default as default };
19
+ export { rules };
package/dist/index.js CHANGED
@@ -12,11 +12,6 @@ var Glob = class {
12
12
  onlyDirectories: true,
13
13
  absolute: true
14
14
  });
15
- if (globResult.length === 0) {
16
- throw new Error(
17
- `[Glob] In baseDir: ${baseDir}, path: ${path4}, any directory was not found`
18
- );
19
- }
20
15
  return globResult;
21
16
  }
22
17
  };
@@ -75,33 +70,59 @@ var Alias = class {
75
70
  }
76
71
  };
77
72
 
78
- // src/rules/enforce-barrel-pattern.ts
73
+ // src/utils/constants.ts
79
74
  var BARREL_ENTRY_POINT_FILE_NAMES = [
80
75
  "index.ts",
76
+ // TypeScript entry
81
77
  "index.tsx",
78
+ // React TypeScript entry
82
79
  "index.js",
80
+ // JavaScript entry
83
81
  "index.jsx",
82
+ // React JavaScript entry
84
83
  "index.cjs",
85
- "index.mjs",
86
- "index.d.ts"
84
+ // CommonJS entry
85
+ "index.mjs"
86
+ // ES Module entry
87
87
  ];
88
88
  var RESOLVE_EXTENSIONS = [
89
89
  ".ts",
90
+ // TypeScript
90
91
  ".js",
92
+ // JavaScript
91
93
  ".tsx",
94
+ // React TypeScript
92
95
  ".jsx",
96
+ // React JavaScript
93
97
  ".json",
98
+ // JSON file
99
+ // Type declaration and transformed files
94
100
  ".d.js",
101
+ // JS file with type declarations (rare)
95
102
  ".d.ts",
103
+ // Type declaration file
104
+ // Various module systems
96
105
  ".mjs",
106
+ // ES Module
97
107
  ".cjs",
108
+ // CommonJS
109
+ // Module-related TypeScript extensions
98
110
  ".mts",
111
+ // ES Module TypeScript
99
112
  ".cts",
113
+ // CommonJS TypeScript
114
+ // Type declarations for module-related files
100
115
  ".d.mjs",
116
+ // Type declarations for ES Module
101
117
  ".d.cjs",
118
+ // Type declarations for CommonJS
102
119
  ".d.mts",
120
+ // Type declarations for ES Module TS
103
121
  ".d.cts"
122
+ // Type declarations for CommonJS TS
104
123
  ];
124
+
125
+ // src/rules/enforce-barrel-pattern.ts
105
126
  var enforceBarrelPattern = {
106
127
  meta: {
107
128
  type: "problem",
@@ -154,66 +175,78 @@ var enforceBarrelPattern = {
154
175
  const absoluteTargetPaths = option.paths.flatMap((_path) => {
155
176
  return Glob.resolvePath(_path, baseDir);
156
177
  });
157
- return {
158
- //check only import declaration(ESM)
159
- ImportDeclaration(node) {
160
- const rawImportPath = node.source.value;
161
- const absoluteCurrentFilePath = context.getFilename();
162
- let absoluteImportPath = null;
163
- try {
164
- const aliasResult = Alias.resolvePath(
165
- rawImportPath,
166
- path2.dirname(absoluteCurrentFilePath)
167
- );
168
- if (aliasResult.type === "success") {
169
- absoluteImportPath = aliasResult.absolutePath;
170
- } else {
171
- if (!rawImportPath.startsWith(".") && !rawImportPath.startsWith("/") || rawImportPath.includes("/node_modules/")) {
172
- return;
173
- }
174
- absoluteImportPath = resolve.sync(rawImportPath, {
175
- basedir: path2.dirname(absoluteCurrentFilePath),
176
- extensions: RESOLVE_EXTENSIONS
177
- });
178
+ function checker(node) {
179
+ if (!node.source) {
180
+ return;
181
+ }
182
+ const rawImportPath = node.source.value;
183
+ const absoluteCurrentFilePath = context.getFilename();
184
+ let absoluteImportPath = null;
185
+ try {
186
+ const aliasResult = Alias.resolvePath(
187
+ rawImportPath,
188
+ path2.dirname(absoluteCurrentFilePath)
189
+ );
190
+ if (aliasResult.type === "success") {
191
+ absoluteImportPath = aliasResult.absolutePath;
192
+ } else {
193
+ if (!rawImportPath.startsWith(".") && !rawImportPath.startsWith("/") || rawImportPath.includes("/node_modules/")) {
194
+ return;
178
195
  }
179
- } catch (e) {
180
- context.report({
181
- node,
182
- messageId: "TransformedAliasResolveFailed"
196
+ absoluteImportPath = resolve.sync(rawImportPath, {
197
+ basedir: path2.dirname(absoluteCurrentFilePath),
198
+ extensions: RESOLVE_EXTENSIONS
183
199
  });
184
- return;
185
200
  }
186
- {
187
- let matchedLatestTargetPath = null;
188
- const invalidDirectedImport = absoluteTargetPaths.some(
189
- (absoluteTargetPath) => {
190
- const targetPathEntryPoints = BARREL_ENTRY_POINT_FILE_NAMES.map(
191
- (entry) => path2.resolve(absoluteTargetPath, entry)
192
- );
193
- const closedTargetPath = absoluteTargetPath + "/";
194
- const targetPathEntryPointed = targetPathEntryPoints.includes(absoluteImportPath);
195
- const importedEnforceBarrelFile = absoluteImportPath.startsWith(closedTargetPath);
196
- const currentFileInEnforceBarrel = absoluteCurrentFilePath.startsWith(closedTargetPath);
197
- const importedOutsideOfTargetPath = !currentFileInEnforceBarrel && importedEnforceBarrelFile;
198
- const invalidImported = !targetPathEntryPointed && importedOutsideOfTargetPath;
199
- if (invalidImported) {
200
- matchedLatestTargetPath = absoluteTargetPath;
201
- }
202
- return invalidImported;
201
+ } catch (e) {
202
+ context.report({
203
+ node,
204
+ messageId: "TransformedAliasResolveFailed"
205
+ });
206
+ return;
207
+ }
208
+ {
209
+ let matchedLatestTargetPath = null;
210
+ const invalidDirectedImport = absoluteTargetPaths.some(
211
+ (absoluteTargetPath) => {
212
+ const targetPathEntryPoints = BARREL_ENTRY_POINT_FILE_NAMES.map(
213
+ (entry) => path2.resolve(absoluteTargetPath, entry)
214
+ );
215
+ const closedTargetPath = absoluteTargetPath + "/";
216
+ const targetPathEntryPointed = targetPathEntryPoints.includes(absoluteImportPath);
217
+ const importedEnforceBarrelFile = absoluteImportPath.startsWith(closedTargetPath);
218
+ const currentFileInEnforceBarrel = absoluteCurrentFilePath.startsWith(closedTargetPath);
219
+ const importedOutsideOfTargetPath = !currentFileInEnforceBarrel && importedEnforceBarrelFile;
220
+ const invalidImported = !targetPathEntryPointed && importedOutsideOfTargetPath;
221
+ if (invalidImported) {
222
+ matchedLatestTargetPath = absoluteTargetPath;
203
223
  }
204
- );
205
- if (invalidDirectedImport) {
206
- context.report({
207
- node,
208
- messageId: "DirectImportDisallowed",
209
- data: {
210
- rawImportPath,
211
- matchedTargetPath: matchedLatestTargetPath
212
- }
213
- });
224
+ return invalidImported;
214
225
  }
226
+ );
227
+ if (invalidDirectedImport) {
228
+ context.report({
229
+ node,
230
+ messageId: "DirectImportDisallowed",
231
+ data: {
232
+ rawImportPath,
233
+ matchedTargetPath: matchedLatestTargetPath
234
+ }
235
+ });
215
236
  }
216
237
  }
238
+ }
239
+ return {
240
+ ExportNamedDeclaration(node) {
241
+ return checker(node);
242
+ },
243
+ ExportAllDeclaration(node) {
244
+ return checker(node);
245
+ },
246
+ //check only import declaration(ESM)
247
+ ImportDeclaration(node) {
248
+ return checker(node);
249
+ }
217
250
  };
218
251
  }
219
252
  };
@@ -222,23 +255,6 @@ var enforceBarrelPattern = {
222
255
  import "@typescript-eslint/types";
223
256
  import path3 from "path";
224
257
  import resolve2 from "resolve";
225
- var RESOLVE_EXTENSIONS2 = [
226
- ".ts",
227
- ".js",
228
- ".tsx",
229
- ".jsx",
230
- ".json",
231
- ".d.js",
232
- ".d.ts",
233
- ".mjs",
234
- ".cjs",
235
- ".mts",
236
- ".cts",
237
- ".d.mjs",
238
- ".d.cjs",
239
- ".d.mts",
240
- ".d.cts"
241
- ];
242
258
  var isolateBarrelFile = {
243
259
  meta: {
244
260
  type: "problem",
@@ -291,6 +307,9 @@ var isolateBarrelFile = {
291
307
  //check only import declaration(ESM)
292
308
  ImportDeclaration(node) {
293
309
  const rawImportPath = node.source.value;
310
+ if (rawImportPath.includes("/node_modules/")) {
311
+ return;
312
+ }
294
313
  const absoluteCurrentFilePath = context.getFilename();
295
314
  let absoluteImportPath = null;
296
315
  try {
@@ -300,13 +319,16 @@ var isolateBarrelFile = {
300
319
  );
301
320
  if (aliasResult.type === "success") {
302
321
  absoluteImportPath = aliasResult.absolutePath;
322
+ if (absoluteImportPath.includes("/node_modules/")) {
323
+ return;
324
+ }
303
325
  } else {
304
- if (!rawImportPath.startsWith(".") && !rawImportPath.startsWith("/") || rawImportPath.includes("/node_modules/")) {
326
+ if (!rawImportPath.startsWith(".") && !rawImportPath.startsWith("/")) {
305
327
  return;
306
328
  }
307
329
  absoluteImportPath = resolve2.sync(rawImportPath, {
308
330
  basedir: path3.dirname(absoluteCurrentFilePath),
309
- extensions: RESOLVE_EXTENSIONS2
331
+ extensions: RESOLVE_EXTENSIONS
310
332
  });
311
333
  }
312
334
  } catch (e) {
@@ -394,9 +416,8 @@ var rules = {
394
416
  "enforce-barrel-pattern": enforceBarrelPattern,
395
417
  "isolate-barrel-file": isolateBarrelFile,
396
418
  "no-wildcard": noWildcard
419
+ // "no-cycle": noCycle,
397
420
  };
398
- var index_default = { rules };
399
- module.exports = { rules };
400
421
  export {
401
- index_default as default
422
+ rules
402
423
  };
package/package.json CHANGED
@@ -25,31 +25,32 @@
25
25
  "isolated barrel module",
26
26
  "no-wildcard"
27
27
  ],
28
- "version": "1.3.1",
28
+ "version": "1.4.2",
29
29
  "type": "module",
30
30
  "main": "dist/index.cjs",
31
31
  "module": "dist/index.js",
32
32
  "types": "dist/index.d.ts",
33
33
  "dependencies": {
34
- "@types/jest": "^30.0.0",
35
- "@typescript-eslint/parser": "^8.46.2",
36
- "@typescript-eslint/rule-tester": "^8.46.2",
37
34
  "@typescript-eslint/types": "^8.46.2",
38
35
  "@typescript-eslint/utils": "^8.36.0",
39
36
  "fast-glob": "^3.3.3",
40
- "jest": "^30.2.0",
41
37
  "resolve": "^1.22.10",
42
- "ts-jest": "^29.4.5",
43
38
  "tsconfig-paths": "^4.2.0"
44
39
  },
45
40
  "devDependencies": {
41
+ "jest": "^30.2.0",
46
42
  "@types/node": "^24.0.13",
47
43
  "@types/resolve": "^1.20.6",
48
44
  "tsup": "^8.5.0",
49
- "typescript": "~5.8.3"
45
+ "typescript": "~5.8.3",
46
+ "@types/jest": "^30.0.0",
47
+ "@typescript-eslint/parser": "^8.46.2",
48
+ "@typescript-eslint/rule-tester": "^8.46.2",
49
+ "ts-jest": "^29.4.5"
50
50
  },
51
51
  "scripts": {
52
- "build": "pnpm run test && tsup src/index.ts --dts --format cjs,esm",
52
+ "lint": "eslint src/**/*.ts",
53
+ "build": "pnpm run test && tsup",
53
54
  "type-check": "tsc --noEmit",
54
55
  "test": "jest",
55
56
  "test:watch": "jest --watch",