eslint-plugin-barrel-rules 1.4.4 → 1.4.5
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 +51 -3
- package/README.md +51 -3
- package/package.json +1 -1
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.4.
|
|
6
|
+
<img src="https://img.shields.io/badge/version-1.4.5-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>
|
|
@@ -33,8 +33,8 @@ JavaScript/TypeScript 프로젝트에서 Barrel Pattern(배럴 패턴)을 강제
|
|
|
33
33
|
> > 이 플러그인은 `node_modules`(외부 패키지)의 import는 제한하거나 검사하지 않습니다.
|
|
34
34
|
> > 모든 규칙은 오직 프로젝트 내부(로컬 소스 파일) 경로의 import에만 적용됩니다.
|
|
35
35
|
>
|
|
36
|
-
>
|
|
37
|
-
>
|
|
36
|
+
> **순환 참조 감지 (Beta)**: 이 플러그인에는 이제 내장된 `no-cycle` 규칙(Beta 버전)이 포함되어 있어 순환 참조를 감지합니다.
|
|
37
|
+
> 프로덕션 환경에서는 [eslint-plugin-import](https://github.com/import-js/eslint-plugin-import)의 `no-cycle` 규칙을 대안으로 사용할 수도 있습니다.
|
|
38
38
|
|
|
39
39
|
---
|
|
40
40
|
|
|
@@ -68,6 +68,12 @@ JavaScript/TypeScript 프로젝트에서 Barrel Pattern(배럴 패턴)을 강제
|
|
|
68
68
|
`import * as foo from "module"` 또는 `export * from "./module"`과 같은 와일드카드(네임스페이스) import/export를 금지합니다.
|
|
69
69
|
명시적인 이름 기반 import/export만 허용하여 트리쉐이킹과 코드 명확성을 높입니다.
|
|
70
70
|
|
|
71
|
+
- **순환 참조 감지 (Beta)**
|
|
72
|
+
import 그래프에서 순환 참조를 감지하고 방지합니다.
|
|
73
|
+
배럴 파일과 TypeScript alias를 통한 순환 참조도 감지합니다.
|
|
74
|
+
또한 배럴 파일 내부 모듈에 대한 상대 경로 import를 강제합니다.
|
|
75
|
+
⚠️ **참고**: 이는 Beta 기능이며 추가 검증이 필요할 수 있습니다.
|
|
76
|
+
|
|
71
77
|
- **고성능 glob 매칭**
|
|
72
78
|
`src/domains/*`처럼 glob 패턴으로 여러 디렉토리 지정 가능
|
|
73
79
|
|
|
@@ -92,11 +98,23 @@ JavaScript/TypeScript 프로젝트에서 Barrel Pattern(배럴 패턴)을 강제
|
|
|
92
98
|
3. **isolate-barrel-file** (isolated 기능을 새로운 룰로 제작했습니다.)
|
|
93
99
|
모듈 import 시 barrel 패턴을 강제합니다.
|
|
94
100
|
지정한 barrel 파일(예: index.ts)로만 import를 허용하고, 내부 모듈에 대한 직접 접근을 차단합니다.
|
|
101
|
+
|
|
95
102
|
- **옵션:**
|
|
96
103
|
- `isolations(Array<{ path: string, allowedPaths: string[] }>)`: `path`와 `allowedPaths`로 구성된 isolation을 추가할 수 있습니다.
|
|
97
104
|
- `baseDir`: `paths` 기준이 되는 베이스 디렉토리 (기본값: ESLint 실행 디렉토리)
|
|
98
105
|
- `globalAllowedPaths` : 모든 isolations에 공통적으로 허용할 경로를 지정합니다(node_modules ... etc)
|
|
99
106
|
|
|
107
|
+
4. **no-cycle** (Beta ⚠️)
|
|
108
|
+
import 그래프에서 순환 참조를 감지하고, 배럴 파일 내부 모듈에 대한 상대 경로 import를 강제합니다.
|
|
109
|
+
- **기능:**
|
|
110
|
+
- 양방향 순환 참조 감지 (A → B와 B → A)
|
|
111
|
+
- DFS(깊이 우선 탐색)를 통한 긴 순환 참조 감지
|
|
112
|
+
- 배럴 파일과 TypeScript alias를 통한 순환 참조 감지 지원
|
|
113
|
+
- 배럴 파일 내부 모듈에 대한 상대 경로 import(./ 또는 ../) 강제
|
|
114
|
+
- **옵션:**
|
|
115
|
+
- 옵션 없음. 규칙이 자동으로 import 그래프를 분석합니다.
|
|
116
|
+
- **참고:** 이는 Beta 기능입니다. 철저히 테스트되었지만, 프로덕션 환경에서의 추가 검증을 권장합니다.
|
|
117
|
+
|
|
100
118
|
---
|
|
101
119
|
|
|
102
120
|
## 설치
|
|
@@ -159,6 +177,9 @@ module.exports = {
|
|
|
159
177
|
|
|
160
178
|
// "*"를 사용한 불 분명한 import/export 방지
|
|
161
179
|
"barrel-rules/no-wildcard": ["error"],
|
|
180
|
+
|
|
181
|
+
// 순환 참조 감지 (Beta)
|
|
182
|
+
"barrel-rules/no-cycle": ["error"],
|
|
162
183
|
},
|
|
163
184
|
};
|
|
164
185
|
```
|
|
@@ -232,6 +253,9 @@ export default tseslint.config([
|
|
|
232
253
|
|
|
233
254
|
// "*"를 사용한 불 분명한 import/export 방지
|
|
234
255
|
"barrel-rules/no-wildcard": ["error"],
|
|
256
|
+
|
|
257
|
+
// 순환 참조 감지 (Beta)
|
|
258
|
+
"barrel-rules/no-cycle": ["error"],
|
|
235
259
|
},
|
|
236
260
|
},
|
|
237
261
|
]);
|
|
@@ -270,6 +294,29 @@ import { Utils } from "./utils/helper"; // 같은 barrel 내부에서
|
|
|
270
294
|
import { SharedUtil } from "@shared/utils"; // allowedImportPaths에 "src/shared/*"가 있는 경우
|
|
271
295
|
```
|
|
272
296
|
|
|
297
|
+
### 3. 순환 참조 감지 (Beta)
|
|
298
|
+
|
|
299
|
+
```ts
|
|
300
|
+
// ❌ 순환 참조 감지됨
|
|
301
|
+
// 파일: src/features/user/user-service.ts
|
|
302
|
+
import { userRepository } from "./user-repository";
|
|
303
|
+
|
|
304
|
+
// 파일: src/features/user/user-repository.ts
|
|
305
|
+
import { userService } from "./user-service"; // 에러: 순환 참조 감지됨
|
|
306
|
+
|
|
307
|
+
// ✅ 배럴 파일은 내부 모듈에 대해 상대 경로를 사용해야 함
|
|
308
|
+
// 파일: src/features/user/index.ts
|
|
309
|
+
import { userService } from "@features/user/user-service"; // ❌ 에러: 상대 경로 사용
|
|
310
|
+
import { userService } from "./user-service"; // ✅ 올바름
|
|
311
|
+
|
|
312
|
+
// ✅ 순환 참조 없음
|
|
313
|
+
// 파일: src/features/user/user-service.ts
|
|
314
|
+
import { userRepository } from "./user-repository";
|
|
315
|
+
|
|
316
|
+
// 파일: src/features/user/user-repository.ts
|
|
317
|
+
import { helper } from "./helper"; // 순환 참조 없음
|
|
318
|
+
```
|
|
319
|
+
|
|
273
320
|
---
|
|
274
321
|
|
|
275
322
|
## 앞으로의 계획
|
|
@@ -283,6 +330,7 @@ import { SharedUtil } from "@shared/utils"; // allowedImportPaths에 "src/shared
|
|
|
283
330
|
- **와일드카드 import/export 제한 규칙** (OK)
|
|
284
331
|
- **지정한 Barrel 경로 격리** (OK)
|
|
285
332
|
- **빈 디렉토리 지원** (예: 'src/shares/\*'가 설정되어 있어도 shares 디렉토리가 비어있어도 됨) (OK)
|
|
333
|
+
- **순환 참조 감지** (Beta - 추가 검증 필요)
|
|
286
334
|
|
|
287
335
|
---
|
|
288
336
|
|
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.4.
|
|
6
|
+
<img src="https://img.shields.io/badge/version-1.4.5-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>
|
|
@@ -35,8 +35,8 @@ Direct imports from internal files are blocked, maximizing
|
|
|
35
35
|
> This plugin does not restrict or track imports from `node_modules` (external packages).
|
|
36
36
|
> The rules only apply to imports of internal (local source file) paths within your project.
|
|
37
37
|
>
|
|
38
|
-
>
|
|
39
|
-
>
|
|
38
|
+
> **Circular Dependency Detection (Beta)**: This plugin now includes a built-in `no-cycle` rule (currently in Beta) that detects circular dependencies.
|
|
39
|
+
> For production use, you can also use the `no-cycle` rule from [eslint-plugin-import](https://github.com/import-js/eslint-plugin-import) as an alternative.
|
|
40
40
|
|
|
41
41
|
---
|
|
42
42
|
|
|
@@ -71,6 +71,12 @@ Direct imports from internal files are blocked, maximizing
|
|
|
71
71
|
Disallows wildcard (namespace) imports and exports such as `import * as foo from "module"` or `export * from "./module"`.
|
|
72
72
|
This enforces the use of named imports/exports for better tree-shaking and code clarity.
|
|
73
73
|
|
|
74
|
+
- **Circular Dependency Detection (Beta)**
|
|
75
|
+
Detects and prevents circular dependencies in your import graph.
|
|
76
|
+
Supports detection through barrel files and TypeScript aliases.
|
|
77
|
+
Also enforces relative imports for internal modules within barrel files.
|
|
78
|
+
⚠️ **Note**: This is a Beta feature and may require additional validation.
|
|
79
|
+
|
|
74
80
|
- **High-performance glob matching**
|
|
75
81
|
Specify multiple directories using glob patterns like `src/domains/*`
|
|
76
82
|
|
|
@@ -95,11 +101,23 @@ Direct imports from internal files are blocked, maximizing
|
|
|
95
101
|
3. **isolate-barrel-file** (New Rules!!!)
|
|
96
102
|
Only files within the same barrel path can import each other, and any import from outside the barrel path is completely blocked (even via the barrel file).
|
|
97
103
|
You can allow specific shared import paths by using the `allowedPaths` option.
|
|
104
|
+
|
|
98
105
|
- **Options:**
|
|
99
106
|
- `isolations(Array<{ path: string, allowedPaths: string[] }>)`: If you set isolation path, blocks all imports from outside the barrel path, even via the barrel file. Only allows imports within the same barrel path or from `allowedPaths` or `globalAllowedPaths`.
|
|
100
107
|
- `baseDir`: The base directory for resolving `paths`. Defaults to the ESLint execution directory.
|
|
101
108
|
- `globalAllowedPaths` : Array of paths that are allowed to be imported directly, even in isolation mode.
|
|
102
109
|
|
|
110
|
+
4. **no-cycle** (Beta ⚠️)
|
|
111
|
+
Detects circular dependencies in your import graph and enforces relative imports for internal modules within barrel files.
|
|
112
|
+
- **Features:**
|
|
113
|
+
- Detects bidirectional cycles (A → B and B → A)
|
|
114
|
+
- Detects longer cycles using DFS (Depth-First Search)
|
|
115
|
+
- Supports cycle detection through barrel files and TypeScript aliases
|
|
116
|
+
- Enforces relative imports (./ or ../) for internal modules in barrel files
|
|
117
|
+
- **Options:**
|
|
118
|
+
- No options required. The rule automatically analyzes your import graph.
|
|
119
|
+
- **Note:** This is a Beta feature. While it has been thoroughly tested, additional validation in production environments is recommended.
|
|
120
|
+
|
|
103
121
|
---
|
|
104
122
|
|
|
105
123
|
## Install
|
|
@@ -163,6 +181,9 @@ module.exports = {
|
|
|
163
181
|
// protect wildcard import/export
|
|
164
182
|
"barrel-rules/no-wildcard": ["error"],
|
|
165
183
|
|
|
184
|
+
// detect circular dependencies (Beta)
|
|
185
|
+
"barrel-rules/no-cycle": ["error"],
|
|
186
|
+
|
|
166
187
|
},
|
|
167
188
|
};
|
|
168
189
|
```
|
|
@@ -238,6 +259,9 @@ export default tseslint.config([
|
|
|
238
259
|
// protect wildcard import/export
|
|
239
260
|
"barrel-rules/no-wildcard": ["error"],
|
|
240
261
|
|
|
262
|
+
// detect circular dependencies (Beta)
|
|
263
|
+
"barrel-rules/no-cycle": ["error"],
|
|
264
|
+
|
|
241
265
|
},
|
|
242
266
|
},
|
|
243
267
|
]);
|
|
@@ -276,6 +300,29 @@ import { Utils } from "./utils/helper"; // from inside same barrel
|
|
|
276
300
|
import { SharedUtil } from "@shared/utils"; // if "src/shared/*" is in allowedPaths or globalAllowedPaths
|
|
277
301
|
```
|
|
278
302
|
|
|
303
|
+
### 3. Circular Dependency Detection (Beta)
|
|
304
|
+
|
|
305
|
+
```ts
|
|
306
|
+
// ❌ Circular dependency detected
|
|
307
|
+
// file: src/features/user/user-service.ts
|
|
308
|
+
import { userRepository } from "./user-repository";
|
|
309
|
+
|
|
310
|
+
// file: src/features/user/user-repository.ts
|
|
311
|
+
import { userService } from "./user-service"; // Error: Circular dependency detected
|
|
312
|
+
|
|
313
|
+
// ✅ Barrel files must use relative imports for internal modules
|
|
314
|
+
// file: src/features/user/index.ts
|
|
315
|
+
import { userService } from "@features/user/user-service"; // ❌ Error: Use relative path
|
|
316
|
+
import { userService } from "./user-service"; // ✅ Correct
|
|
317
|
+
|
|
318
|
+
// ✅ No circular dependency
|
|
319
|
+
// file: src/features/user/user-service.ts
|
|
320
|
+
import { userRepository } from "./user-repository";
|
|
321
|
+
|
|
322
|
+
// file: src/features/user/user-repository.ts
|
|
323
|
+
import { helper } from "./helper"; // No cycle
|
|
324
|
+
```
|
|
325
|
+
|
|
279
326
|
---
|
|
280
327
|
|
|
281
328
|
## Future Work
|
|
@@ -292,6 +339,7 @@ import { SharedUtil } from "@shared/utils"; // if "src/shared/*" is in allowedPa
|
|
|
292
339
|
- **Wildcard Import/Export Protection Rule** (OK)
|
|
293
340
|
- **Isolation Barrel Module** (OK)
|
|
294
341
|
- **Empty Directory Support** (e.g., 'src/shares/\*' can be configured even if the shares directory is empty) (OK)
|
|
342
|
+
- **Circular Dependency Detection** (Beta - requires additional validation)
|
|
295
343
|
|
|
296
344
|
---
|
|
297
345
|
|