forked from liliMozi/openhanako
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
108 lines (99 loc) · 2.87 KB
/
Copy patheslint.config.js
File metadata and controls
108 lines (99 loc) · 2.87 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
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/', 'dist-renderer/', '**/*.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,
},
},
},
// Server-side JS files
{
files: ['server/**/*.js'],
languageOptions: {
globals: {
...globals.node,
fetch: 'readonly',
AbortSignal: 'readonly',
},
},
},
// TypeScript/React frontend files
{
files: ['desktop/src/**/*.{ts,tsx}'],
plugins: {
'react-hooks': reactHooks,
},
rules: {
// Prevent document.createElement in React components
'no-restricted-syntax': [
'error',
{
selector:
"CallExpression[callee.object.name='document'][callee.property.name='createElement']",
message:
'React 组件中不要用 document.createElement,用 JSX。如确需操作 DOM(canvas/resize),加 eslint-disable 注释说明原因。',
},
],
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
},
},
// Downgrade noisy recommended rules to warnings (non-architectural, fix incrementally)
{
rules: {
'no-empty': 'warn',
'prefer-const': 'warn',
'no-useless-escape': 'warn',
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
},
},
// 禁止绕过 adapter 直接导入 PI SDK(后端全覆盖)
{
files: ['core/**/*.js', 'lib/**/*.js', 'hub/**/*.js', 'server/**/*.js'],
ignores: ['lib/pi-sdk/**'],
rules: {
'no-restricted-imports': ['error', {
patterns: [{
group: ['@mariozechner/*'],
message: '请从 lib/pi-sdk/index.js 导入,不要直接引用 PI SDK 包。',
}],
}],
},
},
// Prevent engine._ access in server routes
{
files: ['server/routes/**/*.js'],
rules: {
'no-restricted-syntax': [
'error',
{
selector: "MemberExpression[object.name='engine'][property.name=/^_/]",
message: '不要访问 engine 的私有方法。通过 engine 公开 API 访问。',
},
],
},
},
];