-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheslint.config.js
More file actions
213 lines (209 loc) · 6.97 KB
/
Copy patheslint.config.js
File metadata and controls
213 lines (209 loc) · 6.97 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
import js from '@eslint/js';
import globals from 'globals';
import react from 'eslint-plugin-react';
import ts from 'typescript-eslint';
import prettier from 'eslint-config-prettier';
/** @type {import('eslint').Linter.FlatConfig[]} */
export default [
// 忽略不需要检查的文件和目录
{
ignores: [
'frontend/**',
'lib/**',
'logs/**',
'dist/**',
'node_modules/**',
'**/*.css',
'**/*.jpg',
'**/*.png',
'**/*.yaml',
'**/*.yml',
'.tmp/**',
'*.config.js',
'*.config.ts',
'.puppeteerrc.cjs',
'src/env.d.ts'
]
},
// TypeScript 声明文件配置 - 放宽注释规则
{
files: ['**/*.d.ts'],
rules: {
'spaced-comment': 'off'
}
},
// 基础 JavaScript 推荐规则
js.configs.recommended,
// TypeScript 推荐规则 (包含 parser 与插件)
...ts.configs.recommended,
// 添加更严格的 TypeScript 规则
...ts.configs.strict,
// TypeScript 文件配置 - 指定解析器和项目配置
{
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parser: ts.parser,
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: import.meta.dirname
}
}
},
// React 相关规则配置
{
plugins: { react },
rules: {
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
// 关闭 prop-types 检查,因为使用 TypeScript 类型系统
'react/prop-types': 'off',
'react/display-name': 'off',
'react/jsx-key': 'error',
'react/jsx-no-duplicate-props': 'error',
'react/jsx-no-undef': 'error',
'react/no-array-index-key': 'off',
'react/no-danger': 'off',
'react/no-deprecated': 'error',
'react/no-direct-mutation-state': 'error',
'react/no-find-dom-node': 'error',
'react/no-is-mounted': 'error',
'react/no-render-return-value': 'error',
'react/no-string-refs': 'error',
'react/no-unescaped-entities': 'error',
'react/no-unknown-property': 'error',
'react/no-unsafe': 'off',
'react/self-closing-comp': 'error'
},
settings: {
react: { version: 'detect' }
}
},
// 关闭与 Prettier 冲突的格式化规则
prettier,
// 主要代码质量规则配置
{
languageOptions: {
sourceType: 'module',
globals: {
...globals.browser,
...globals.node,
...globals.es2021
}
},
rules: {
// ===== TypeScript 相关规则 =====
// 未使用变量检查 - 忽略以下划线开头的变量
'@typescript-eslint/no-unused-vars': [
'error',
{
varsIgnorePattern: '^_',
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_'
}
],
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/require-await': 'error',
// ===== 代码质量规则 =====
// 优先使用 const - 解构时也要求使用 const
'prefer-const': ['error', { destructuring: 'all' }],
'no-empty': ['error', { allowEmptyCatch: true }],
'no-unused-expressions': 'error',
'no-console': 'off',
'no-debugger': 'error',
'no-alert': 'off',
'no-eval': 'error',
'no-implied-eval': 'error',
'no-new-func': 'error',
'no-script-url': 'error',
'no-self-compare': 'error',
'no-sequences': 'error',
'no-throw-literal': 'error',
'no-unmodified-loop-condition': 'error',
'no-useless-call': 'error',
'no-useless-concat': 'error',
'no-useless-return': 'error',
'prefer-promise-reject-errors': 'error',
'require-await': 'error',
yoda: 'error',
// ===== 最佳实践规则 =====
// 严格相等比较 - 禁止使用 === 和 !=
eqeqeq: ['error', 'always'],
curly: ['error', 'all'],
'no-multi-spaces': 'error',
'no-trailing-spaces': 'error',
'eol-last': 'error',
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 1 }],
'comma-dangle': ['error', 'never'],
semi: ['error', 'always'],
quotes: ['error', 'single', { avoidEscape: true }],
'object-curly-spacing': ['error', 'always'],
'array-bracket-spacing': ['error', 'never'],
'comma-spacing': ['error', { before: false, after: true }],
'key-spacing': ['error', { beforeColon: false, afterColon: true }],
'space-before-blocks': 'error',
'space-in-parens': ['error', 'never'],
'space-infix-ops': 'error',
'keyword-spacing': 'error',
'arrow-spacing': 'error',
'block-spacing': 'error',
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
camelcase: ['warn', { properties: 'never' }],
'comma-style': ['error', 'last'],
'func-call-spacing': ['error', 'never'],
'function-paren-newline': 'off',
'implicit-arrow-linebreak': ['error', 'beside'],
// 最大行长度限制 - 100字符,忽略URL和字符串
'max-len': ['warn', { code: 160, ignoreUrls: true, ignoreStrings: true }],
// 禁用混合运算符检查 - 与自动格式化工具冲突
'no-mixed-operators': 'off',
// 禁止使用制表符,统一使用空格
'no-tabs': 'error',
// 运算符换行规则 - 运算符放在行首
'operator-linebreak': ['error', 'before'],
// 禁止块级代码前后有空行
'padded-blocks': ['error', 'never'],
// 语句间空行规则
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'return' },
{ blankLine: 'always', prev: ['const', 'let', 'var'], next: '*' },
{
blankLine: 'any',
prev: ['const', 'let', 'var'],
next: ['const', 'let', 'var']
}
],
// 对象属性引号规则 - 只在必要时使用引号
'quote-props': ['error', 'as-needed'],
// 函数括号前空格规则 - 禁止空格
'space-before-function-paren': 'off',
// 一元运算符空格规则
'space-unary-ops': 'error',
// 注释空格规则 - 要求空格,但允许特殊标记
'spaced-comment': [
'error',
'always',
{
line: {
markers: ['/'],
exceptions: ['///']
}
}
],
// 模板标签间距规则
'template-tag-spacing': 'error'
}
}
];