-
Notifications
You must be signed in to change notification settings - Fork 561
Expand file tree
/
Copy patheslint.config.js
More file actions
175 lines (163 loc) · 4.63 KB
/
Copy patheslint.config.js
File metadata and controls
175 lines (163 loc) · 4.63 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
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import reactHooks from 'eslint-plugin-react-hooks';
import globals from 'globals';
export default [
// Global ignores — must be a standalone config object with only `ignores`
{
ignores: [
'node_modules/',
'**/dist/**',
// Build scripts emit several sibling directories such as dist-server,
// dist-server-artifact, dist-renderer-artifact, and dist-computer-use.
// Keep the naming contract here instead of chasing every new output.
'dist-*/**',
// Desktop Vite builds use the same family for dist-renderer and
// dist-splash; both contain bundled JavaScript that must not be linted.
'desktop/dist-*/**',
'desktop/native/**/.build/**',
'.claude/**',
'.cache/**',
// .docs/ 不入版本控制、CI 不可见;lint 覆盖它会造成本地/CI 语义不对称
'.docs/**',
'**/*.cjs',
],
},
js.configs.recommended,
...tseslint.configs.recommended,
// Browser JS files (pre-React bootstrap layer: i18n, theme, platform)
{
files: ['desktop/src/**/*.js'],
languageOptions: {
globals: {
...globals.browser,
},
},
},
// Shared CJS-style JS (loaded via require from preload.cjs; runs in preload context)
{
files: ['desktop/src/shared/**/*.js'],
languageOptions: {
globals: {
...globals.node,
},
},
},
// Node-side JS files
{
files: [
'cli/**/*.{js,ts}',
'core/**/*.{js,ts}',
'hub/**/*.{js,ts}',
'index.js',
'lib/**/*.{js,ts}',
'plugins/**/*.{js,ts}',
'scripts/**/*.{js,mjs,ts}',
'tools/npm-ea/**/*.mjs',
'server/**/*.{js,ts}',
'shared/**/*.{js,ts}',
'tests/**/*.{js,ts,tsx}',
],
languageOptions: {
globals: {
...globals.node,
fetch: 'readonly',
AbortSignal: 'readonly',
},
},
},
// Vitest files mix Node helpers with jsdom/browser primitives.
{
files: ['tests/**/*.{js,ts,tsx}'],
languageOptions: {
globals: {
...globals.node,
...globals.browser,
},
},
},
// Browser package TypeScript files
{
files: [
'packages/plugin-sdk/src/**/*.ts',
'packages/plugin-components/src/**/*.{ts,tsx}',
],
languageOptions: {
globals: {
...globals.browser,
},
},
},
// TypeScript/React frontend files
{
files: [
'desktop/src/**/*.{ts,tsx}',
'packages/plugin-components/src/**/*.{ts,tsx}',
],
plugins: {
'react-hooks': reactHooks,
},
rules: {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
},
},
// React components should render with JSX. DOM utilities, CodeMirror widgets,
// and tests may create DOM nodes directly.
{
files: ['desktop/src/react/**/*.tsx'],
ignores: [
'desktop/src/react/**/__tests__/**',
'desktop/src/react/**/*.test.tsx',
],
rules: {
'no-restricted-syntax': [
'error',
{
selector:
"CallExpression[callee.object.name='document'][callee.property.name='createElement']",
message:
'React 组件中不要用 document.createElement,用 JSX。如确需操作 DOM(canvas/resize),加 eslint-disable 注释说明原因。',
},
],
},
},
// Downgrade noisy recommended rules to warnings (non-architectural, fix incrementally)
{
rules: {
'no-empty': 'warn',
'prefer-const': 'warn',
'no-useless-escape': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
},
},
// 禁止绕过 adapter 直接导入 PI SDK(后端全覆盖)
{
files: ['core/**/*.{js,ts}', 'lib/**/*.{js,ts}', 'hub/**/*.{js,ts}', 'server/**/*.{js,ts}'],
ignores: ['lib/pi-sdk/**'],
rules: {
'no-restricted-imports': ['error', {
patterns: [{
group: ['@mariozechner/*', '@earendil-works/*'],
message: '请从 lib/pi-sdk/index.js 导入,不要直接引用 PI SDK 包。',
}],
}],
},
},
// Prevent engine._ access in server routes
{
files: ['server/routes/**/*.{js,ts}'],
rules: {
'no-restricted-syntax': [
'error',
{
selector: "MemberExpression[object.name='engine'][property.name=/^_/]",
message: '不要访问 engine 的私有方法。通过 engine 公开 API 访问。',
},
],
},
},
];