-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.ts
More file actions
131 lines (117 loc) · 4.24 KB
/
Copy patheslint.config.ts
File metadata and controls
131 lines (117 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import js from "@eslint/js";
import globals from "globals";
import { configs } from "typescript-eslint";
import { defineConfig, globalIgnores } from "eslint/config";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
import eslintConfigPrettier from "eslint-config-prettier";
import { importX } from "eslint-plugin-import-x";
export default defineConfig([
globalIgnores(["**/.bun/", "**/build/", "**/dist/", "**/node_modules/"]),
js.configs.recommended,
configs.recommendedTypeChecked, // Check cả type
configs.stylisticTypeChecked, // Check type để quyết định phong cách
// eslint-disable-next-line @typescript-eslint/no-explicit-any
importX.flatConfigs.recommended as any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
importX.flatConfigs.typescript as any,
// Tắt các rule xung đột với Prettier
eslintPluginPrettierRecommended,
{
languageOptions: {
// phiên dịch cho eslint hiểu code
parserOptions: {
projectService: {
// cấp "Giấy phép tạm trú" để được check bởi tsconfig.json chính
// allowDefaultProject: ["eslint.config.ts"],
defaultProject: "tsconfig.eslint.json",
},
tsconfigRootDir: import.meta.dirname,
},
globals: globals.node,
},
settings: {
"import-x/resolver": {
typescript: {
alwaysTryTypes: true,
project: "tsconfig.json",
},
},
},
rules: {
...eslintConfigPrettier.rules,
"@typescript-eslint/explicit-member-accessibility": [
"error",
{ accessibility: "explicit" }, // Bắt buộc phải viết public/private
],
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-vars": [
"warn",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
"@typescript-eslint/consistent-type-imports": [
"error",
{
prefer: "type-imports", // Bắt buộc dùng import type
fixStyle: "separate-type-imports", // Tự động fix thành: import type { Metadata } ...
},
],
"prettier/prettier": "warn",
"import-x/no-cycle": ["error", { maxDepth: "∞", ignoreExternal: true }],
"import-x/no-unresolved": "off",
},
},
{
files: ["src/**/*.ts", "!src/modules/**/*.ts"],
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
{
// modules/blog/chat.service chặn
// modules/chat OK cần index.ts
group: ["**/modules/*/*"],
message:
"Private internal access! Please import from the public interface (index.ts) of the module.",
},
],
},
],
},
},
{
files: ["src/modules/**/*.ts"],
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
{
// 🚫 Cấm import kiểu: "@/modules/auth" hoặc "@/modules/auth/"
// Bắt buộc phải trỏ sâu vào file cụ thể
// ^@/modules/ : Bắt đầu bằng @/modules/
// [^/]+ : Sau đó là tên module (không có dấu / tiếp theo)
// /? : Có thể có dấu / thừa ở cuối
// (/index(\.(ts|js))?)? : Hoặc trỏ đích danh vào /index, /index.ts, /index.js
regex: "^@/modules/[^/]+/?(/index(\\.(ts|js))?)?$",
message:
"Please import directly from the specific file to avoid Circular Dependency (e.g., '@/modules/auth/models/User'). Do not import from the module index.",
},
{
// 🚫 Cấm import relative trỏ ngược ra index cha
// VD: import ... from "../index"
group: ["**/index"],
message:
"Do not import from barrel files (index.ts) inside modules.",
},
{
// Ngăn import ngược từ App layer gây Circular Dependency
regex: "^@/(app|server|container)(/.*)?(.(ts|js))?$",
message: "Modules should not import from App layer.",
},
],
},
],
},
},
]);