eslint-plugin-barrel-rules 1.0.3 → 1.1.0

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.0.3-blue.svg" alt="Version"/>
6
+ <img src="https://img.shields.io/badge/version-1.1.0-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>
@@ -23,7 +23,7 @@ NPM: [https://www.npmjs.com/package/eslint-plugin-barrel-rules](https://www.npmj
23
23
  **eslint-plugin-barrel-rules**는
24
24
  JavaScript/TypeScript 프로젝트에서 Barrel Pattern(배럴 패턴)을 강제하고, 모듈 경계와 캡슐화를 보장하는 고급 ESLint 플러그인입니다.
25
25
 
26
- 지정한 디렉토리(예: `src/domains/*`)의 내부 구현은
26
+ 지정한 디렉토리(예: `src/domains/*`, `src/domains/cart`)의 내부 구현은
27
27
  오직 해당 디렉토리의 **index(배럴) 파일**을 통해서만 접근할 수 있도록 강제합니다.
28
28
  내부 파일을 직접 import하는 것을 차단하여
29
29
  **모듈화, 추상화, 유지보수성, 확장성**을 극대화합니다.
@@ -32,8 +32,12 @@ JavaScript/TypeScript 프로젝트에서 Barrel Pattern(배럴 패턴)을 강제
32
32
 
33
33
  ## 지원 환경
34
34
 
35
- - Node.js (ES2015+)
36
- - ES Modules(ESM)
35
+ - ESLint 9
36
+ > Flat config(eslint.config.js), TypeScript 지원 시 "typescript-eslint" config 사용 필요
37
+ - ESLint 8
38
+ > Legacy config(.eslintrc.js), TypeScript 지원 시 "@typescript-eslint/parser"를 parser로 지정하고, "@typescript-eslint"를 plugin에 추가해야 함
39
+ - Node.js (ES2015 이상)
40
+ - ES 모듈, CommonJS 모듈 모두 지원
37
41
 
38
42
  ---
39
43
 
@@ -61,39 +65,77 @@ pnpm add -D eslint-plugin-barrel-rules
61
65
 
62
66
  ---
63
67
 
64
- ## 사용법
68
+ ## Eslint8 사용법
65
69
 
66
70
  ```js
71
+ file(.eslintrc.js)
72
+
73
+ module.exports = {
74
+ ...(any other options)
75
+ // 타입스크립트를 사용할 경우 "@typescript-eslint/parser", "@typescript-eslint"를 설치하고 설정해 주세요.
76
+ parser: "@typescript-eslint/parser",
77
+ plugins: ["@typescript-eslint", "barrel-rules"],
78
+ rules: {
79
+ "barrel-rules/enforce-barrel-pattern": [
80
+ "error",
81
+ {
82
+ // 배럴 파일로 보호할 디렉토리의 경로입니다. baseDir을 기준으로 상대 경로로 설정합니다.
83
+ paths: ["src/typescript/barrel/*", "src/javascript/barrel/*"],
84
+ // (옵션) 설정하지 않으면 기본값은 ESLint를 실행한 위치(작업 디렉토리)입니다.
85
+ // 예: `npx eslint .`처럼 실행하면, 실행 시점의 현재 디렉토리가 기본값이 됩니다.
86
+ baseDir: __dirname,
87
+ },
88
+ ],
89
+ },
90
+ };
91
+ ```
92
+
93
+ ---
94
+
95
+ ## Eslint9 사용법
96
+
97
+ ```js
98
+ file(eslintrc.config.js);
99
+
100
+ import js from "@eslint/js";
101
+ import tseslint from "typescript-eslint";
102
+ import { globalIgnores } from "eslint/config";
103
+ import barrelRules from "eslint-plugin-barrel-rules";
104
+ // ESM에서 __dirname을 사용하기 위한 코드
67
105
  import { fileURLToPath } from "url";
68
106
  import path from "path";
69
- import { enforceBarrelPattern } from "eslint-plugin-barrel-rules";
70
-
71
- //ESM은 __dirname을 지원하지 않기에 직접 구현합니다.
107
+ // 커스텀 __dirname 생성
72
108
  const __filename = fileURLToPath(import.meta.url);
73
109
  const __dirname = path.dirname(__filename);
74
-
75
- export default [
110
+ // 타입스크립트 사용 시 필요
111
+ export default tseslint.config([
112
+ globalIgnores(["dist"]),
76
113
  {
114
+ // (다른 옵션들 추가 가능)
115
+ files: ["**/*.{ts,tsx}"],
116
+ extends: [js.configs.recommended, tseslint.configs.recommended],
117
+ languageOptions: {
118
+ ecmaVersion: 2020,
119
+ },
120
+ // barrel-rules 플러그인만 추가하면 됩니다.
77
121
  plugins: {
78
- "barrel-rules": {
79
- rules: {
80
- "enforce-barrel-pattern": enforceBarrelPattern,
81
- },
82
- },
122
+ "barrel-rules": barrelRules,
83
123
  },
124
+ // barrel-rules에 대한 설정만 추가하면 됩니다.
84
125
  rules: {
85
126
  "barrel-rules/enforce-barrel-pattern": [
86
127
  "error",
87
128
  {
88
- //Barrel Pattern을 강제할 디렉토리를 정의합니다(baseDir 기준으로 상대경로)
89
- paths: ["src/domains/*"],
90
- //paths들의 root경로를 지정합니다.
129
+ // 배럴 파일로 보호할 디렉토리의 경로입니다. baseDir 기준으로 상대 경로로 설정합니다.
130
+ paths: ["src/typescript/barrel/*"],
131
+ // (옵션) 설정하지 않으면 기본값은 ESLint를 실행한 위치(작업 디렉토리)입니다.
132
+ // 예: `npx eslint .`처럼 실행하면, 실행 시점의 현재 디렉토리가 기본값이 됩니다.
91
133
  baseDir: __dirname,
92
134
  },
93
135
  ],
94
136
  },
95
137
  },
96
- ];
138
+ ]);
97
139
  ```
98
140
 
99
141
  ---
@@ -113,15 +155,15 @@ import { Test } from "../domains/foo";
113
155
  ## 앞으로의 계획
114
156
 
115
157
  - 더 다양한 모듈 경계/추상화 관련 룰 추가 예정
116
-
117
- - **Alias/tsconfig 지원**
118
- TypeScript `paths`, Vite `resolve.alias` 등 다양한 경로 매핑 완벽 지원 예정
119
-
120
- - **Commonjs 지원**
158
+ - Alias/tsconfig 지원: TypeScript의 paths, Vite의 resolve.alias, 기타 커스텀 경로 매핑을 완벽하게 지원
159
+ - **CJS 지원** (OK)
160
+ - **ESLint 8 지원** (OK)
161
+ - **번들 플러그인(플러그인 내 모든 기능 통합)** (OK)
162
+ - **잘못된 경로 설정 검증 기능** (OK)
121
163
 
122
164
  ---
123
165
 
124
166
  ## 문의
125
167
 
126
168
  질문, 제안, 버그 리포트, 기여 모두 환영합니다!
127
- [[📬 send mail]](mailto:lhsung98@naver.com)
169
+ [[📬 send mail lhsung98@naver.com]](mailto:lhsung98@naver.com)
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.0.3-blue.svg" alt="Version"/>
6
+ <img src="https://img.shields.io/badge/version-1.1.0-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>
@@ -26,7 +26,7 @@ NPM: [https://www.npmjs.com/package/eslint-plugin-barrel-rules](https://www.npmj
26
26
  that enforces the Barrel Pattern in JavaScript/TypeScript projects,
27
27
  ensuring strict module boundaries and encapsulation.
28
28
 
29
- You can specify directories (e.g., `src/domains/*`) where
29
+ You can specify directories (e.g., `src/domains/*`, `src/domains/cart`) where
30
30
  internal implementation details must only be accessed via the directory’s **index (barrel) file**.
31
31
  Direct imports from internal files are blocked, maximizing
32
32
  **modularity, abstraction, maintainability, and scalability**.
@@ -35,8 +35,12 @@ Direct imports from internal files are blocked, maximizing
35
35
 
36
36
  ## Supports
37
37
 
38
+ - ESLint 9
39
+ > Flat config(eslint.config.js), for TypeScript support, use the "typescript-eslint" config
40
+ - ESLint 8
41
+ > Legacy config(.eslintrc.js), for TypeScript support, set "@typescript-eslint/parser" as the parser and add "@typescript-eslint" as a plugin
38
42
  - Node.js (ES2015+)
39
- - Supports ES Modules (ESM)
43
+ - Supports both ES Modules and CommonJS
40
44
 
41
45
  ---
42
46
 
@@ -64,39 +68,77 @@ pnpm add -D eslint-plugin-barrel-rules
64
68
 
65
69
  ---
66
70
 
67
- ## Usage
71
+ ## Eslint8 Usage
68
72
 
69
73
  ```js
74
+ file(.eslintrc.js)
75
+
76
+ module.exports = {
77
+ ...(any other options)
78
+ //if you use typescript, needs "@typescript-eslint/parser", "@typescript-eslint" install and setup plz..
79
+ parser: "@typescript-eslint/parser",
80
+ plugins: ["@typescript-eslint", "barrel-rules"],
81
+ rules: {
82
+ "barrel-rules/enforce-barrel-pattern": [
83
+ "error",
84
+ {
85
+ // The path to the directory that should be protected by using a barrel file. This path is relative to baseDir.
86
+ paths: ["src/typescript/barrel/*", "src/javascript/barrel/*"],
87
+ // Optional config. The default value is the directory where ESLint is executed.
88
+ // For example, if you run `npx eslint .`, the default will be the current working directory at the time of execution.
89
+ baseDir: __dirname,
90
+ },
91
+ ],
92
+ },
93
+ };
94
+ ```
95
+
96
+ ---
97
+
98
+ ## Eslint9 Usage
99
+
100
+ ```js
101
+ file(eslintrc.config.js);
102
+
103
+ import js from "@eslint/js";
104
+ import tseslint from "typescript-eslint";
105
+ import { globalIgnores } from "eslint/config";
106
+ import barrelRules from "eslint-plugin-barrel-rules";
107
+ //for __dirname in ESM
70
108
  import { fileURLToPath } from "url";
71
109
  import path from "path";
72
- import { enforceBarrelPattern } from "eslint-plugin-barrel-rules";
73
-
74
- //ESM not support __dirname(custom __dirname)
110
+ //custom __dirname
75
111
  const __filename = fileURLToPath(import.meta.url);
76
112
  const __dirname = path.dirname(__filename);
77
-
78
- export default [
113
+ //typescript-config (if you use typescript, needs it)
114
+ export default tseslint.config([
115
+ globalIgnores(["dist"]),
79
116
  {
117
+ ...(any other options)
118
+ files: ["**/*.{ts,tsx}"],
119
+ extends: [js.configs.recommended, tseslint.configs.recommended],
120
+ languageOptions: {
121
+ ecmaVersion: 2020,
122
+ },
123
+ //just set barrle-rules plugin
80
124
  plugins: {
81
- "barrel-rules": {
82
- rules: {
83
- "enforce-barrel-pattern": enforceBarrelPattern,
84
- },
85
- },
125
+ "barrel-rules": barrelRules,
86
126
  },
127
+ //just set your setting for barrel-rules
87
128
  rules: {
88
129
  "barrel-rules/enforce-barrel-pattern": [
89
130
  "error",
90
131
  {
91
- //Enforced directories
92
- paths: ["src/domains/*"],
93
- //BaseDir(root path, mutable)
132
+ // The path to the directory that should be protected by using a barrel file. This path is relative to baseDir.
133
+ paths: ["src/typescript/barrel/*"],
134
+ // Optional config. The default value is the directory where ESLint is executed.
135
+ // For example, if you run `npx eslint .`, the default will be the current working directory at the time of execution.
94
136
  baseDir: __dirname,
95
137
  },
96
138
  ],
97
139
  },
98
140
  },
99
- ];
141
+ ]);
100
142
  ```
101
143
 
102
144
  ---
@@ -120,11 +162,15 @@ import { Test } from "../domains/foo";
120
162
  - **Alias/tsconfig Support**
121
163
  Fully supports TypeScript `paths`, Vite `resolve.alias`, and other custom path mappings
122
164
 
123
- - **CJS Support**
165
+ - **CJS Support** (OK)
166
+ - **Eslint8 Support** (OK)
167
+ - **Bundle Plugin(capsure any features in plugin)**
168
+ (OK)
169
+ - **Wrong Path Setup Validator** (OK)
124
170
 
125
171
  ---
126
172
 
127
173
  ## Contact
128
174
 
129
175
  Questions, suggestions, bug reports, and contributions are welcome!
130
- [[📬 send mail]](mailto:lhsung98@naver.com)
176
+ [[📬 send mail lhsung98@naver.com]](mailto:lhsung98@naver.com)
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
- enforceBarrelPattern: () => enforceBarrelPattern
33
+ default: () => index_default
34
34
  });
35
35
  module.exports = __toCommonJS(index_exports);
36
36
 
@@ -52,6 +52,7 @@ var enforceBarrelPattern = {
52
52
  paths: { type: "array", items: { type: "string" } },
53
53
  baseDir: { type: "string" }
54
54
  },
55
+ required: ["paths"],
55
56
  additionalProperties: false
56
57
  }
57
58
  ],
@@ -131,7 +132,10 @@ var enforceBarrelPattern = {
131
132
  };
132
133
  }
133
134
  };
134
- // Annotate the CommonJS export names for ESM import in node:
135
- 0 && (module.exports = {
136
- enforceBarrelPattern
137
- });
135
+
136
+ // src/index.ts
137
+ var rules = {
138
+ "enforce-barrel-pattern": enforceBarrelPattern
139
+ };
140
+ var index_default = { rules };
141
+ module.exports = { rules };
package/dist/index.d.cts CHANGED
@@ -1,10 +1,12 @@
1
- import { RuleModule } from '@typescript-eslint/utils/ts-eslint';
1
+ import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
2
2
 
3
- type Option = {
4
- paths: string[];
5
- baseDir: string;
3
+ declare const _default: {
4
+ rules: {
5
+ "enforce-barrel-pattern": _typescript_eslint_utils_ts_eslint.RuleModule<"DirectImportDisallowed", {
6
+ paths: string[];
7
+ baseDir: string;
8
+ }[], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
9
+ };
6
10
  };
7
- type MessageIds = "DirectImportDisallowed";
8
- declare const enforceBarrelPattern: RuleModule<MessageIds, Option[]>;
9
11
 
10
- export { enforceBarrelPattern };
12
+ export { _default as default };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
- import { RuleModule } from '@typescript-eslint/utils/ts-eslint';
1
+ import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
2
2
 
3
- type Option = {
4
- paths: string[];
5
- baseDir: string;
3
+ declare const _default: {
4
+ rules: {
5
+ "enforce-barrel-pattern": _typescript_eslint_utils_ts_eslint.RuleModule<"DirectImportDisallowed", {
6
+ paths: string[];
7
+ baseDir: string;
8
+ }[], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
9
+ };
6
10
  };
7
- type MessageIds = "DirectImportDisallowed";
8
- declare const enforceBarrelPattern: RuleModule<MessageIds, Option[]>;
9
11
 
10
- export { enforceBarrelPattern };
12
+ export { _default as default };
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ var enforceBarrelPattern = {
16
16
  paths: { type: "array", items: { type: "string" } },
17
17
  baseDir: { type: "string" }
18
18
  },
19
+ required: ["paths"],
19
20
  additionalProperties: false
20
21
  }
21
22
  ],
@@ -95,6 +96,13 @@ var enforceBarrelPattern = {
95
96
  };
96
97
  }
97
98
  };
99
+
100
+ // src/index.ts
101
+ var rules = {
102
+ "enforce-barrel-pattern": enforceBarrelPattern
103
+ };
104
+ var index_default = { rules };
105
+ module.exports = { rules };
98
106
  export {
99
- enforceBarrelPattern
107
+ index_default as default
100
108
  };
package/package.json CHANGED
@@ -23,7 +23,7 @@
23
23
  "encapsulation directory",
24
24
  "enforce barrel pattern"
25
25
  ],
26
- "version": "1.0.3",
26
+ "version": "1.1.0",
27
27
  "type": "module",
28
28
  "main": "dist/index.cjs",
29
29
  "module": "dist/index.js",