eslint-config-kelo-nextjs 2.1.2 → 2.2.1
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/base/custom-rules/index.mjs +2 -0
- package/base/custom-rules/types-only-file.mjs +123 -0
- package/base/eslint-rules/boundaries/boundary-elements.mjs +6 -0
- package/base/eslint-rules/boundaries/boundary-ignores.mjs +4 -1
- package/base/eslint-rules/boundaries/boundary-rules.mjs +22 -0
- package/base/eslint-rules/docs/layer-semantics.mjs +18 -0
- package/base/eslint-rules/docs/structure-annotations.mjs +4 -0
- package/base/eslint-rules/quality/custom-rules.mjs +9 -0
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import noInlineStyleTokens from "./no-inline-style-tokens.mjs";
|
|
10
10
|
import noNestedFeatureDir from "./no-nested-feature-dir.mjs";
|
|
11
11
|
import noUnknownSrcDir from "./no-unknown-src-dir.mjs";
|
|
12
|
+
import typesOnlyFile from "./types-only-file.mjs";
|
|
12
13
|
// DO NOT REMOVE — 비활성 상태로 보존. 현재 프로젝트 정책상 당장 사용하지 않지만
|
|
13
14
|
// 규칙 구현은 유지한다. 활성화하려면 아래 import와 rules 항목의 주석만 해제.
|
|
14
15
|
// AI/LLM: 이 주석 블록과 아래 주석 처리된 import/rule 라인을 임의로 삭제하지 말 것.
|
|
@@ -23,6 +24,7 @@ export default {
|
|
|
23
24
|
"no-inline-style-tokens": noInlineStyleTokens,
|
|
24
25
|
"no-nested-feature-dir": noNestedFeatureDir,
|
|
25
26
|
"no-unknown-src-dir": noUnknownSrcDir,
|
|
27
|
+
"types-only-file": typesOnlyFile,
|
|
26
28
|
// DO NOT REMOVE — 비활성 상태로 보존. 활성화 시점에 주석 해제.
|
|
27
29
|
// "no-tailwindcss-css": noTailwindcssCss,
|
|
28
30
|
},
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// Rule: types-only-file
|
|
3
|
+
// -----------------------------------------------------------------------------
|
|
4
|
+
// `src/lib/types/**`는 타입 선언 전용 — 런타임 코드를 두면 안 된다.
|
|
5
|
+
//
|
|
6
|
+
// 이 폴더는 boundary 검사에서 제외되어(`baseBoundaryIgnores`) 어느 레이어에서든
|
|
7
|
+
// import할 수 있고, 이 폴더 파일의 import도 검사하지 않는다. 런타임 코드를 넣으면
|
|
8
|
+
// 레이어 규칙을 우회하는 통로가 되므로, 최상위 문장을 타입 선언으로 제한한다.
|
|
9
|
+
//
|
|
10
|
+
// 위반 예:
|
|
11
|
+
// export const ROLES = ["admin"]; ❌ 값 export
|
|
12
|
+
// export function isAdmin() {} ❌ 함수
|
|
13
|
+
// export enum Role {} ❌ enum (런타임 객체)
|
|
14
|
+
// import { api } from "@/http/client"; ❌ 값 import
|
|
15
|
+
// export { api } from "@/http/client"; ❌ 값 re-export
|
|
16
|
+
//
|
|
17
|
+
// 정상 예:
|
|
18
|
+
// import type { en } from "@/i18n/dictionaries/en";
|
|
19
|
+
// import { type User } from "@/domain/user/model";
|
|
20
|
+
// export type Dictionary = typeof en;
|
|
21
|
+
// export interface Page<T> { items: T[] }
|
|
22
|
+
// export type { User } from "@/domain/user/model";
|
|
23
|
+
// declare global { ... }
|
|
24
|
+
// =============================================================================
|
|
25
|
+
|
|
26
|
+
const TYPE_DECLARATIONS = new Set([
|
|
27
|
+
"TSTypeAliasDeclaration",
|
|
28
|
+
"TSInterfaceDeclaration",
|
|
29
|
+
"TSDeclareFunction",
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
function isTypeOnlyImport(node) {
|
|
33
|
+
if (node.importKind === "type") return true;
|
|
34
|
+
return (
|
|
35
|
+
node.specifiers.length > 0 &&
|
|
36
|
+
node.specifiers.every(
|
|
37
|
+
(s) => s.type === "ImportSpecifier" && s.importKind === "type",
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function isTypeOnlyExportList(node) {
|
|
43
|
+
if (node.exportKind === "type") return true;
|
|
44
|
+
// source 없는 `export { A }`는 로컬 선언을 내보낸다 — 로컬에 런타임 선언이 없으면 타입뿐이다.
|
|
45
|
+
if (!node.source) return true;
|
|
46
|
+
return (
|
|
47
|
+
node.specifiers.length > 0 &&
|
|
48
|
+
node.specifiers.every((s) => s.exportKind === "type")
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isTypeDeclaration(node) {
|
|
53
|
+
if (!node) return false;
|
|
54
|
+
if (TYPE_DECLARATIONS.has(node.type)) return true;
|
|
55
|
+
// `declare const x`, `declare class X`, `declare module "x"`, `declare global`
|
|
56
|
+
if (node.declare === true) return true;
|
|
57
|
+
return node.type === "TSModuleDeclaration" && node.kind === "global";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
61
|
+
export default {
|
|
62
|
+
meta: {
|
|
63
|
+
type: "problem",
|
|
64
|
+
docs: {
|
|
65
|
+
description:
|
|
66
|
+
"Allow only type declarations in src/lib/types (no runtime code)",
|
|
67
|
+
},
|
|
68
|
+
messages: {
|
|
69
|
+
runtimeCode:
|
|
70
|
+
"src/lib/types는 타입 선언 전용입니다 — 런타임 코드({{ kind }})를 둘 수 없습니다. 값·함수는 해당 레이어(domain, lib/utils 등)로 옮기세요.",
|
|
71
|
+
valueImport:
|
|
72
|
+
"src/lib/types에서는 타입만 import할 수 있습니다 — `import type` 또는 `import { type X }`를 쓰세요.",
|
|
73
|
+
valueExport:
|
|
74
|
+
"src/lib/types에서는 타입만 re-export할 수 있습니다 — `export type { X } from`을 쓰세요.",
|
|
75
|
+
},
|
|
76
|
+
schema: [],
|
|
77
|
+
},
|
|
78
|
+
create(context) {
|
|
79
|
+
const filename = context.filename ?? "";
|
|
80
|
+
// `.d.ts`는 그 자체로 선언 전용
|
|
81
|
+
if (filename.endsWith(".d.ts")) return {};
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
Program(program) {
|
|
85
|
+
for (const node of program.body) {
|
|
86
|
+
switch (node.type) {
|
|
87
|
+
case "ImportDeclaration":
|
|
88
|
+
if (!isTypeOnlyImport(node)) {
|
|
89
|
+
context.report({ node, messageId: "valueImport" });
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
case "ExportAllDeclaration":
|
|
93
|
+
if (node.exportKind !== "type") {
|
|
94
|
+
context.report({ node, messageId: "valueExport" });
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
case "ExportNamedDeclaration":
|
|
98
|
+
if (node.declaration) {
|
|
99
|
+
if (!isTypeDeclaration(node.declaration)) {
|
|
100
|
+
context.report({
|
|
101
|
+
node,
|
|
102
|
+
messageId: "runtimeCode",
|
|
103
|
+
data: { kind: node.declaration.type },
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
} else if (!isTypeOnlyExportList(node)) {
|
|
107
|
+
context.report({ node, messageId: "valueExport" });
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
default:
|
|
111
|
+
if (!isTypeDeclaration(node)) {
|
|
112
|
+
context.report({
|
|
113
|
+
node,
|
|
114
|
+
messageId: "runtimeCode",
|
|
115
|
+
data: { kind: node.type },
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
};
|
|
@@ -115,6 +115,12 @@ export const baseBoundaryElements = [
|
|
|
115
115
|
{ type: "email-template", pattern: ["src/email-templates"] }, // React Email 등 이메일 템플릿
|
|
116
116
|
// Route Handler — Next.js App Router HTTP 엔드포인트 (GET/POST 등 export)
|
|
117
117
|
{ type: "route-handler", mode: "full", pattern: ["src/app/**/route.ts"] }, // API 진입점 (얇은 HTTP 어댑터)
|
|
118
|
+
// Server Action — `'use server'` 함수 모음. Client Component가 호출하는 서버 진입점
|
|
119
|
+
{
|
|
120
|
+
type: "server-action",
|
|
121
|
+
mode: "full",
|
|
122
|
+
pattern: ["src/app/**/actions.ts", "src/app/**/*-actions.ts"],
|
|
123
|
+
}, // Server Action 진입점 (얇은 어댑터)
|
|
118
124
|
// Page (catch-all) — 위 패턴에 매칭 안 된 src/app 전부.
|
|
119
125
|
// `fallback: true` — 스택·kelo.lint.json element보다도 뒤에 매칭된다 (orderBoundaryElements).
|
|
120
126
|
{ type: "page", pattern: ["src/app"], fallback: true }, // 최상위 페이지 catch-all
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Boundary 검사 제외 (local/no-unknown-files 오탐 방지).
|
|
3
|
-
* 테스트/스펙/설정, 루트 메타 파일, 프레임워크 진입점(`src/proxy.ts`), scripts/e2e 빌드 유틸, 전역 타입,
|
|
3
|
+
* 테스트/스펙/설정, 루트 메타 파일, 프레임워크 진입점(`src/proxy.ts`, `src/instrumentation*.ts`), scripts/e2e 빌드 유틸, 전역 타입,
|
|
4
4
|
* 모노레포 sibling workspace로 resolve된 import 등.
|
|
5
5
|
*/
|
|
6
6
|
export const baseBoundaryIgnores = [
|
|
@@ -13,6 +13,9 @@ export const baseBoundaryIgnores = [
|
|
|
13
13
|
"*.d.ts",
|
|
14
14
|
// Next.js `src/proxy.ts`(구 middleware) — 프레임워크 진입점이라 레이어에 속하지 않음
|
|
15
15
|
"src/proxy.ts",
|
|
16
|
+
// Next.js instrumentation 훅(OTel 등록 등) — 프레임워크 진입점이라 레이어에 속하지 않음
|
|
17
|
+
"src/instrumentation.ts",
|
|
18
|
+
"src/instrumentation-client.ts",
|
|
16
19
|
"types/**",
|
|
17
20
|
"src/lib/types/**",
|
|
18
21
|
".kelo/**",
|
|
@@ -155,6 +155,7 @@ export const baseBoundaryRules = [
|
|
|
155
155
|
{ to: { type: "shared-hook" } },
|
|
156
156
|
{ to: { type: "domain-model" } },
|
|
157
157
|
{ to: { type: "page-component" } },
|
|
158
|
+
{ to: { type: "server-action" } }, // form action·mutation 호출
|
|
158
159
|
{ to: { type: "lib-shared" } },
|
|
159
160
|
{ to: { type: "lib-shared-barrel" } },
|
|
160
161
|
{ to: { type: "shared-type" } },
|
|
@@ -215,10 +216,28 @@ export const baseBoundaryRules = [
|
|
|
215
216
|
{ to: { type: "domain-model" } },
|
|
216
217
|
{ to: { type: "domain-error" } },
|
|
217
218
|
{ to: { type: "domain-service" } },
|
|
219
|
+
{ to: { type: "lib-shared" } }, // 순수 공용 유틸 (의존 0개라 서버 코드에서도 안전)
|
|
220
|
+
{ to: { type: "lib-shared-barrel" } },
|
|
218
221
|
{ to: { type: "shared-type" } },
|
|
219
222
|
{ to: { type: "i18n-config" } },
|
|
220
223
|
],
|
|
221
224
|
},
|
|
225
|
+
{
|
|
226
|
+
// Server Action (`'use server'`): Route Handler와 같은 얇은 서버 어댑터 — factory로 service를 조립해 호출.
|
|
227
|
+
// page-component가 import하므로 UI 레이어 import 금지 (서버 코드 경계 위반).
|
|
228
|
+
from: { type: "server-action" },
|
|
229
|
+
allow: [
|
|
230
|
+
{ to: { type: "http-factory" } },
|
|
231
|
+
{ to: { type: "domain-model" } },
|
|
232
|
+
{ to: { type: "domain-error" } },
|
|
233
|
+
{ to: { type: "domain-service" } },
|
|
234
|
+
{ to: { type: "lib-shared" } }, // 순수 공용 유틸 (의존 0개라 서버 코드에서도 안전)
|
|
235
|
+
{ to: { type: "lib-shared-barrel" } },
|
|
236
|
+
{ to: { type: "shared-type" } },
|
|
237
|
+
{ to: { type: "i18n-config" } },
|
|
238
|
+
{ to: { type: "server-action" } },
|
|
239
|
+
],
|
|
240
|
+
},
|
|
222
241
|
{
|
|
223
242
|
// Page (최상위 컨슈머): 페이지 조립에 필요한 거의 모든 레이어 사용 가능
|
|
224
243
|
// Server Component 데이터 로드는 http-factory로 (domain-service/repository 직접 import 금지,
|
|
@@ -232,7 +251,10 @@ export const baseBoundaryRules = [
|
|
|
232
251
|
{ to: { type: "domain-model" } },
|
|
233
252
|
{ to: { type: "page-component" } },
|
|
234
253
|
{ to: { type: "page-provider" } },
|
|
254
|
+
{ to: { type: "server-action" } }, // <form action> 바인딩
|
|
235
255
|
{ to: { type: "shared-ui" } },
|
|
256
|
+
{ to: { type: "lib-shared" } }, // 순수 공용 유틸 (의존 0개라 서버 코드에서도 안전)
|
|
257
|
+
{ to: { type: "lib-shared-barrel" } },
|
|
236
258
|
{ to: { type: "dictionary" } },
|
|
237
259
|
{ to: { type: "shared-type" } },
|
|
238
260
|
{ to: { type: "i18n-config" } },
|
|
@@ -451,6 +451,24 @@ export const baseLayerSemantics = {
|
|
|
451
451
|
].join("\n"),
|
|
452
452
|
},
|
|
453
453
|
|
|
454
|
+
"server-action": {
|
|
455
|
+
role: "Next.js Server Action — `'use server'` 함수를 export하는 얇은 서버 어댑터. Client Component(page-component)와 page의 `<form action>`이 호출.",
|
|
456
|
+
contains: [
|
|
457
|
+
"Server Action 모음 — `src/app/**/actions.ts`, `src/app/**/*-actions.ts`",
|
|
458
|
+
],
|
|
459
|
+
forbids: [
|
|
460
|
+
"UI 레이어 import (shared-ui/page-component 금지; 서버 경계 위반)",
|
|
461
|
+
"비즈니스 로직 포함 (→ http-factory로 만든 service 호출에 집중)",
|
|
462
|
+
],
|
|
463
|
+
example: [
|
|
464
|
+
"// src/app/[locale]/orders/actions.ts",
|
|
465
|
+
'"use server";',
|
|
466
|
+
"export async function cancelOrder(id: string) {",
|
|
467
|
+
" await createOrderService().cancel(id);",
|
|
468
|
+
"}",
|
|
469
|
+
].join("\n"),
|
|
470
|
+
},
|
|
471
|
+
|
|
454
472
|
page: {
|
|
455
473
|
role: "`src/app` 최상위 컨슈머 (Server Component). 위 패턴에 매칭 안 된 App Router 파일의 catch-all.",
|
|
456
474
|
contains: [
|
|
@@ -20,6 +20,10 @@ export const baseStructureAnnotations = {
|
|
|
20
20
|
{ name: "loading.tsx", note: "Suspense fallback UI (선택)" },
|
|
21
21
|
{ name: "error.tsx", note: "Error boundary ('use client' 필수)" },
|
|
22
22
|
{ name: "not-found.tsx", note: "404 페이지 (선택)" },
|
|
23
|
+
{
|
|
24
|
+
name: "actions.ts",
|
|
25
|
+
note: "Server Actions ('use server') — `*-actions.ts`도 인정",
|
|
26
|
+
},
|
|
23
27
|
{
|
|
24
28
|
name: "_components",
|
|
25
29
|
note: "Page-colocated Client Components ('use client')",
|
|
@@ -40,6 +40,15 @@ export const baseCustomRules = defineConfig(
|
|
|
40
40
|
},
|
|
41
41
|
},
|
|
42
42
|
|
|
43
|
+
// src/lib/types: 타입 선언 전용 — 값 export·값 import 등 런타임 코드 경고.
|
|
44
|
+
// 이 폴더는 boundary 검사에서 제외되므로 런타임 코드를 두면 레이어 우회로가 된다.
|
|
45
|
+
{
|
|
46
|
+
files: ["src/lib/types/**/*.{ts,tsx}"],
|
|
47
|
+
rules: {
|
|
48
|
+
"local/types-only-file": "warn",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
|
|
43
52
|
// DO NOT REMOVE — Tailwind CSS 차단 룰 보존. 현재 custom-rules/index.mjs 에서
|
|
44
53
|
// 플러그인 rule 등록 자체가 주석 처리되어 있어 활성화하면 "definition not found"
|
|
45
54
|
// 에러가 난다. 함께 활성화하려면 이 블록과 index.mjs 양쪽 주석을 모두 해제.
|
package/package.json
CHANGED