forked from lobehub/lobehub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
343 lines (337 loc) 路 9.68 KB
/
Copy patheslint.config.mjs
File metadata and controls
343 lines (337 loc) 路 9.68 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
import { fileURLToPath } from 'node:url';
import { eslint } from '@lobehub/lint';
import { restrictedImports } from '@lobehub/ui/eslint';
import { flat as mdxFlat } from 'eslint-plugin-mdx';
const tsconfigRootDir = fileURLToPath(new URL('.', import.meta.url));
const baseRestrictedImportOptions = restrictedImports.rules['no-restricted-imports'][1];
const performanceRestrictedImportPaths = [
{
message:
'Import the imperative facade from "@/features/ShareModal" so the modal implementation stays outside initial chunks.',
name: '@/features/ShareModal/Modal',
},
];
const createRestrictedImportRule = ({ paths = [], patterns } = {}) => [
'error',
{
...baseRestrictedImportOptions,
paths: [
...(baseRestrictedImportOptions.paths ?? []),
...performanceRestrictedImportPaths,
...paths,
],
...(patterns?.length
? { patterns: [...(baseRestrictedImportOptions.patterns ?? []), ...patterns] }
: {}),
},
];
export default eslint(
{
ignores: [
// dependencies
'node_modules',
// ci
'coverage',
'.coverage',
// test
'jest*',
'*.test.ts',
'*.test.tsx',
// umi
'.umi',
'.umi-production',
'.umi-test',
'.dumi/tmp*',
// production
'dist',
'es',
'lib',
'logs',
// misc
'.next',
// temporary directories
'tmp',
'temp',
'.temp',
'.local',
'docs/.local',
// cache directories
'.cache',
// AI coding tools directories
'.claude',
'.serena',
'.i18nrc.js',
// vendored code (copied from @microsoft/fetch-event-source)
'packages/utils/src/client/fetchEventSource/parse.ts',
],
next: true,
react: 'next',
},
{
languageOptions: {
parserOptions: {
tsconfigRootDir,
},
},
},
restrictedImports,
// Performance import boundaries. These restrictions preserve real import()
// seams instead of relying on component-level conditional rendering.
{
files: ['src/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': createRestrictedImportRule(),
},
},
{
files: ['src/features/Conversation/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': createRestrictedImportRule({
paths: [
{
message:
'Conversation internals must use stable subpaths such as "./store", "./ConversationProvider", or "./Messages" instead of the root barrel.',
name: '@/features/Conversation',
},
],
}),
},
},
{
files: ['src/features/NavPanel/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': createRestrictedImportRule({
patterns: [
{
group: [
'@/routes/**/_layout/Sidebar',
'@/routes/**/_layout/Sidebar/**',
'@/routes/**/_layout/SideBar',
'@/routes/**/_layout/SideBar/**',
],
message:
'NavPanel must not own route Sidebar implementations. Register route content through NavPanelPortal.',
},
],
}),
},
},
{
files: [
'src/routes/**/_layout/Sidebar.{ts,tsx}',
'src/routes/**/_layout/Sidebar/**/*.{ts,tsx}',
'src/routes/**/_layout/SideBar.{ts,tsx}',
'src/routes/**/_layout/SideBar/**/*.{ts,tsx}',
],
rules: {
'no-restricted-imports': createRestrictedImportRule({
paths: [
{
message:
'Route Sidebars must import NavPanelPortal from its dedicated subpath instead of the NavPanel host barrel.',
name: '@/features/NavPanel',
},
],
}),
},
},
{
files: ['src/features/HomeInbox/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': createRestrictedImportRule({
paths: [
{
message:
'Load RunReplyEditor with import() after reply intent so the editor stays outside the home static closure.',
name: '@/features/AgentTasks/AgentTaskDetail/RunReplyEditor',
},
{
message:
'HomeInbox must not mount TopicChatDrawer; navigate to the topic or load an interaction-owned surface dynamically.',
name: '@/features/AgentTasks/AgentTaskDetail/TopicChatDrawer',
},
{
message:
'HomeInbox must not mount TopicChatDrawer; navigate to the topic or load an interaction-owned surface dynamically.',
name: '@/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index',
},
{
message:
'Use the imperative DocumentModal loader instead of statically importing the implementation.',
name: '@/features/DocumentModal',
},
{
message:
'Use the imperative DocumentModal loader instead of statically importing the implementation.',
name: '@/features/DocumentModal/index',
},
],
}),
},
},
{
files: ['src/features/Home/**/*.{ts,tsx}', 'src/routes/(main)/home/**/*.{ts,tsx}'],
ignores: [
'src/routes/(main)/home/_layout/hooks/useCreateModal.tsx',
'src/features/Home/InputArea/EditorInput.tsx',
],
rules: {
'no-restricted-imports': createRestrictedImportRule({
paths: [
{
message:
'Home cold-path modules must use stable Conversation subpaths instead of the root barrel that exports ChatInput.',
name: '@/features/Conversation',
},
],
patterns: [
{
message:
'Home cold-path modules must not statically import ChatInput. Load an isolated editor entry with import().',
regex:
'^@/features/ChatInput(?:$|/(?!(?:store/initialState|utils/contextSelections)$).+)',
},
],
}),
},
},
{
files: ['src/features/Home/InputArea/index.tsx'],
rules: {
'no-restricted-imports': createRestrictedImportRule({
paths: [
{
message:
'The home input must load EditorInput through useProgressiveEditor instead of adding it to the route static closure.',
name: './EditorInput',
},
],
}),
},
},
// Global rule overrides
{
rules: {
'@eslint-react/hooks-extra/no-direct-set-state-in-use-effect': 0,
'@eslint-react/jsx-key-before-spread': 0,
'@eslint-react/naming-convention/ref-name': 0,
'@eslint-react/naming-convention/use-state': 0,
'@eslint-react/no-array-index-key': 0,
'@next/next/no-img-element': 0,
'@typescript-eslint/no-use-before-define': 0,
'@typescript-eslint/no-useless-constructor': 0,
'no-extra-boolean-cast': 0,
'no-restricted-syntax': 0,
'react-refresh/only-export-components': 0,
'react/no-unknown-property': 0,
'regexp/match-any': 0,
'unicorn/better-regex': 0,
},
},
// TypeScript files - enforce consistent type imports
{
files: ['**/*.{ts,tsx}'],
rules: {
'@typescript-eslint/consistent-type-imports': [
2,
{
fixStyle: 'separate-type-imports',
},
],
},
},
// MDX files
{
...mdxFlat,
files: ['**/*.mdx'],
rules: {
...mdxFlat.rules,
'@typescript-eslint/consistent-type-imports': 0,
'@typescript-eslint/no-unused-vars': 1,
'mdx/remark': 0,
'no-undef': 0,
'react/jsx-no-undef': 0,
'react/no-unescaped-entities': 0,
},
},
// Store/image and types/generation - disable sorting
{
files: ['src/store/image/**/*', 'src/types/generation/**/*'],
rules: {
'perfectionist/sort-interfaces': 0,
'perfectionist/sort-object-types': 0,
'perfectionist/sort-objects': 0,
},
},
// model-bank aiModels - enforce English-only descriptions
{
files: ['packages/model-bank/src/aiModels/**/*'],
rules: {
'no-restricted-syntax': [
'error',
{
message: 'Chinese characters are not allowed in aiModels files. Use English instead.',
selector: 'Literal[value=/[\\u4e00-\\u9fff]/]',
},
],
},
},
// CLI scripts
{
files: ['scripts/**/*'],
rules: {
'unicorn/no-process-exit': 0,
'unicorn/prefer-top-level-await': 0,
},
},
// E2E and test files - allow console.log for debugging
{
files: ['e2e/**/*', '**/*.test.ts', '**/*.test.tsx'],
rules: {
'no-console': 0,
},
},
// agent-tracing CLI - console output is the primary interface
{
files: ['packages/agent-tracing/**/*'],
rules: {
'no-console': 0,
},
},
// lobehub-cli - console output is the primary interface
{
files: ['apps/cli/**/*'],
rules: {
'no-console': 0,
},
},
// model-runtime debug utilities - console output is the primary interface
{
files: ['packages/model-runtime/src/utils/debugStream.ts'],
rules: {
'no-console': 0,
},
},
// Business stubs - keep `use`-prefixed APIs mirroring the cloud implementation,
// even when the OSS fallback doesn't call any hooks
{
files: [
'src/business/client/features/User/useBusinessMenuItems.tsx',
'src/business/client/hooks/useBusinessChatInputSendAreaPrefix.tsx',
'src/business/client/hooks/useBusinessSignup.tsx',
'src/business/client/hooks/useRenderBusinessBatchItem.tsx',
'src/business/client/hooks/useRenderBusinessChatErrorMessageExtra.tsx',
'src/business/client/hooks/useRenderBusinessVideoBatchItem.tsx',
],
rules: {
'@eslint-react/no-unnecessary-use-prefix': 0,
},
},
// CommonJS files rely on `require()` by design
{
files: ['**/*.cjs'],
rules: {
'@typescript-eslint/no-require-imports': 0,
},
},
);