@zpcscc/configs 3.0.5 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -27
- package/eslint-config/index.js +277 -249
- package/eslint-config/react/index.js +65 -51
- package/package.json +15 -14
- package/tsconfig/tsconfig.json +3 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @zpcscc/configs
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@zpcscc/configs)
|
|
3
|
+
[](https://www.npmjs.com/package/@zpcscc/configs)
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@zpcscc/configs)
|
|
6
6
|
|
|
@@ -17,46 +17,44 @@ npm install --save-dev @zpcscc/configs
|
|
|
17
17
|
|
|
18
18
|
## 使用
|
|
19
19
|
|
|
20
|
-
### eslint
|
|
20
|
+
### eslint(ESLint 9 Flat Config)
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
`eslint.config.mjs`
|
|
23
23
|
|
|
24
24
|
#### 基础配置
|
|
25
25
|
|
|
26
26
|
```javascript
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
import baseConfig from '@zpcscc/configs/eslint-config';
|
|
28
|
+
|
|
29
|
+
export default [...baseConfig];
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
#### react的eslint配置
|
|
32
|
+
#### react 的 eslint 配置
|
|
33
33
|
|
|
34
34
|
```javascript
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
import reactConfig from '@zpcscc/configs/eslint-config/react';
|
|
36
|
+
|
|
37
|
+
export default [...reactConfig];
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
####
|
|
40
|
+
#### 自定义覆盖
|
|
41
41
|
|
|
42
42
|
```javascript
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
import baseConfig from '@zpcscc/configs/eslint-config';
|
|
44
|
+
|
|
45
|
+
export default [
|
|
46
|
+
...baseConfig,
|
|
47
|
+
// 自定义规则覆盖
|
|
48
|
+
{
|
|
49
|
+
rules: {
|
|
50
|
+
'no-console': 'warn',
|
|
51
|
+
},
|
|
48
52
|
},
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
tsconfig.json 文件中,也需要在 include 中引入.eslintrc.js 文件
|
|
55
|
-
|
|
56
|
-
```json
|
|
57
|
-
{
|
|
58
|
-
"include": [".eslintrc.js"]
|
|
59
|
-
}
|
|
53
|
+
// 忽略文件
|
|
54
|
+
{
|
|
55
|
+
ignores: ['dist/**', 'coverage/**'],
|
|
56
|
+
},
|
|
57
|
+
];
|
|
60
58
|
```
|
|
61
59
|
|
|
62
60
|
|
package/eslint-config/index.js
CHANGED
|
@@ -1,256 +1,284 @@
|
|
|
1
|
-
//
|
|
1
|
+
// ESLint 9 Flat Config
|
|
2
|
+
// 官方文档 https://eslint.org/docs/latest/use/configure/configuration-files
|
|
2
3
|
// @ts-check
|
|
4
|
+
const js = require('@eslint/js');
|
|
5
|
+
const tseslint = require('typescript-eslint');
|
|
6
|
+
const importXPlugin = require('eslint-plugin-import-x');
|
|
7
|
+
const unicornPlugin = require('eslint-plugin-unicorn').default;
|
|
8
|
+
const promisePlugin = require('eslint-plugin-promise');
|
|
9
|
+
const eslintCommentsPlugin = require('@eslint-community/eslint-plugin-eslint-comments');
|
|
10
|
+
const globals = require('globals');
|
|
11
|
+
|
|
3
12
|
/**
|
|
4
|
-
*
|
|
13
|
+
* 基础 ESLint Flat Config
|
|
14
|
+
* 适用于所有项目(纯 JS/TS,非 React)
|
|
15
|
+
*
|
|
16
|
+
* 使用方式(eslint.config.mjs):
|
|
17
|
+
* import baseConfig from '@zpcscc/configs/eslint-config';
|
|
18
|
+
* export default [...baseConfig];
|
|
19
|
+
*
|
|
20
|
+
* 或带自定义覆盖:
|
|
21
|
+
* import baseConfig from '@zpcscc/configs/eslint-config';
|
|
22
|
+
* export default [...baseConfig, { rules: { 'no-console': 'warn' } }];
|
|
5
23
|
*/
|
|
6
|
-
module.exports =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* 用于关闭eslint中的所有格式化配置,全部在.prettierrc中进行格式化配置
|
|
27
|
-
*/
|
|
28
|
-
'plugin:prettier/recommended'],
|
|
29
|
-
// 如果要在rules中针对某个插件做具体配置,则需要在plugins里先引入对应插件
|
|
30
|
-
plugins: ['@typescript-eslint', 'unicorn', 'promise', 'import'],
|
|
31
|
-
parserOptions: {
|
|
32
|
-
ecmaVersion: 'latest'
|
|
24
|
+
module.exports = tseslint.config(
|
|
25
|
+
// ===== 基础推荐规则 =====
|
|
26
|
+
js.configs.recommended,
|
|
27
|
+
|
|
28
|
+
// ===== TypeScript =====
|
|
29
|
+
...tseslint.configs.recommended,
|
|
30
|
+
{
|
|
31
|
+
languageOptions: {
|
|
32
|
+
ecmaVersion: 'latest',
|
|
33
|
+
sourceType: 'module',
|
|
34
|
+
parserOptions: {
|
|
35
|
+
ecmaFeatures: { jsx: true },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
settings: {
|
|
39
|
+
'import-x/resolver': {
|
|
40
|
+
typescript: true,
|
|
41
|
+
node: true,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
33
44
|
},
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
|
|
46
|
+
// ===== Import-X =====
|
|
47
|
+
importXPlugin.flatConfigs.recommended,
|
|
48
|
+
importXPlugin.flatConfigs.typescript,
|
|
49
|
+
|
|
50
|
+
// ===== Unicorn =====
|
|
51
|
+
unicornPlugin.configs['flat/recommended'],
|
|
52
|
+
|
|
53
|
+
// ===== Promise =====
|
|
54
|
+
promisePlugin.configs['flat/recommended'],
|
|
55
|
+
|
|
56
|
+
// ===== ESLint Comments =====
|
|
57
|
+
// eslintCommentsPlugin.configs.recommended 是旧格式,手动配置 flat config 版本
|
|
58
|
+
{
|
|
59
|
+
plugins: {
|
|
60
|
+
'@eslint-community/eslint-comments': eslintCommentsPlugin,
|
|
61
|
+
},
|
|
62
|
+
rules: {
|
|
63
|
+
'@eslint-community/eslint-comments/disable-enable-pair': 'error',
|
|
64
|
+
'@eslint-community/eslint-comments/no-aggregating-enable': 'error',
|
|
65
|
+
'@eslint-community/eslint-comments/no-duplicate-disable': 'error',
|
|
66
|
+
'@eslint-community/eslint-comments/no-unlimited-disable': 'error',
|
|
67
|
+
'@eslint-community/eslint-comments/no-unused-enable': 'error',
|
|
68
|
+
},
|
|
41
69
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
70
|
+
|
|
71
|
+
// ===== 全局变量 + 环境 =====
|
|
72
|
+
{
|
|
73
|
+
languageOptions: {
|
|
74
|
+
globals: {
|
|
75
|
+
...globals.browser,
|
|
76
|
+
...globals.commonjs,
|
|
77
|
+
...globals.jest,
|
|
78
|
+
// 自定义全局类型
|
|
79
|
+
Any: 'readonly',
|
|
80
|
+
AnyArray: 'readonly',
|
|
81
|
+
AnyObject: 'readonly',
|
|
82
|
+
AnyFunction: 'readonly',
|
|
83
|
+
NodeJS: 'readonly',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
48
86
|
},
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
87
|
+
|
|
88
|
+
// ===== 自定义 Rules =====
|
|
89
|
+
{
|
|
90
|
+
rules: {
|
|
91
|
+
// --- TypeScript 规则 ---
|
|
92
|
+
// 数组类型。不限制写法
|
|
93
|
+
'@typescript-eslint/array-type': 'off',
|
|
94
|
+
// 强制要求注释描述,关闭
|
|
95
|
+
'@typescript-eslint/ban-ts-comment': 'off',
|
|
96
|
+
// 强制使用一致性类型断言。关闭,两种语法都允许
|
|
97
|
+
'@typescript-eslint/consistent-type-assertions': 'off',
|
|
98
|
+
// 强制 ts 类型使用 type 关键字
|
|
99
|
+
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
|
|
100
|
+
// import 类型时,需要加 type,使用内联方式
|
|
101
|
+
'@typescript-eslint/consistent-type-imports': [
|
|
102
|
+
'error',
|
|
103
|
+
{ fixStyle: 'inline-type-imports' },
|
|
104
|
+
],
|
|
105
|
+
// 显示函数返回类型。关闭
|
|
106
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
107
|
+
// 无混淆空表达式。关闭(需要 type-aware linting,由消费者自行配置)
|
|
108
|
+
'@typescript-eslint/no-confusing-void-expression': 'off',
|
|
109
|
+
// 不允许有 any 类型。关闭,特殊情况需要
|
|
110
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
111
|
+
// 禁止 require() 导入。关闭,部分场景需要 CJS
|
|
112
|
+
'@typescript-eslint/no-require-imports': 'off',
|
|
113
|
+
// 无浮动的 promise。关闭
|
|
114
|
+
'@typescript-eslint/no-floating-promises': 'off',
|
|
115
|
+
// 不得滥用 promise。关闭
|
|
116
|
+
'@typescript-eslint/no-misused-promises': 'off',
|
|
117
|
+
// 禁止变量重新声明
|
|
118
|
+
'@typescript-eslint/no-redeclare': 'error',
|
|
119
|
+
// 禁止未使用的表达式
|
|
120
|
+
'@typescript-eslint/no-unused-expressions': [
|
|
121
|
+
'error',
|
|
122
|
+
{ allowShortCircuit: true, allowTernary: true },
|
|
123
|
+
],
|
|
124
|
+
// 禁止使用类型断言。关闭
|
|
125
|
+
'@typescript-eslint/non-nullable-type-assertion-style': 'off',
|
|
126
|
+
// 限制命名规则。关闭,命名希望灵活些
|
|
127
|
+
'@typescript-eslint/naming-convention': 'off',
|
|
128
|
+
// 使用 ?? 替换 ||。关闭,部分场景需要手动选择
|
|
129
|
+
'@typescript-eslint/prefer-nullish-coalescing': 'off',
|
|
130
|
+
// promise 函数都需要使用 async。关闭
|
|
131
|
+
'@typescript-eslint/promise-function-async': 'off',
|
|
132
|
+
// 限制 + 操作符。关闭
|
|
133
|
+
'@typescript-eslint/restrict-plus-operands': 'off',
|
|
134
|
+
// 限制模板表达式。关闭
|
|
135
|
+
'@typescript-eslint/restrict-template-expressions': 'off',
|
|
136
|
+
// async 函数返回值需要有 await。关闭(需要 type-aware linting)
|
|
137
|
+
'@typescript-eslint/return-await': 'off',
|
|
138
|
+
// 严格的逻辑表达式。关闭
|
|
139
|
+
'@typescript-eslint/strict-boolean-expressions': 'off',
|
|
140
|
+
// 禁止三斜杠指令
|
|
141
|
+
'@typescript-eslint/triple-slash-reference': 'off',
|
|
142
|
+
|
|
143
|
+
// --- Import-X 规则 ---
|
|
144
|
+
'import-x/named': 'off',
|
|
145
|
+
'import-x/export': 'off',
|
|
146
|
+
'import-x/extensions': 'off',
|
|
147
|
+
'import-x/no-cycle': 'off',
|
|
148
|
+
'import-x/no-extraneous-dependencies': 'off',
|
|
149
|
+
'import-x/no-named-as-default': 'off',
|
|
150
|
+
'import-x/no-relative-packages': 'off',
|
|
151
|
+
'import-x/no-unresolved': 'off',
|
|
152
|
+
'import-x/prefer-default-export': 'off',
|
|
153
|
+
'import-x/no-duplicates': 'error',
|
|
154
|
+
|
|
155
|
+
// --- Unicorn 规则 ---
|
|
156
|
+
'unicorn/consistent-destructuring': 'off',
|
|
157
|
+
'unicorn/consistent-function-scoping': 'off',
|
|
158
|
+
'unicorn/prevent-abbreviations': 'off',
|
|
159
|
+
'unicorn/new-for-builtins': 'off',
|
|
160
|
+
'unicorn/no-array-callback-reference': 'off',
|
|
161
|
+
'unicorn/no-array-for-each': 'off',
|
|
162
|
+
'unicorn/no-array-reduce': 'off',
|
|
163
|
+
'unicorn/no-new-array': 'off',
|
|
164
|
+
'unicorn/no-null': 'off',
|
|
165
|
+
'unicorn/numeric-separators-style': 'off',
|
|
166
|
+
'unicorn/prefer-module': 'off',
|
|
167
|
+
'unicorn/filename-case': 'off',
|
|
168
|
+
|
|
169
|
+
// --- ESLint Comments 规则 ---
|
|
170
|
+
'eslint-comments/disable-enable-pair': 'off',
|
|
171
|
+
|
|
172
|
+
// --- Promise 规则 ---
|
|
173
|
+
'promise/always-return': 'off',
|
|
174
|
+
'promise/catch-or-return': 'off',
|
|
175
|
+
|
|
176
|
+
// --- 基础规则 ---
|
|
177
|
+
// 箭头函数体是否强制使用大括号。关闭
|
|
178
|
+
'arrow-body-style': 'off',
|
|
179
|
+
// if 语句是否需要加括号。多行加括号,单行不需要
|
|
180
|
+
curly: ['error', 'multi-line'],
|
|
181
|
+
'default-param-last': 'off',
|
|
182
|
+
// 禁止 console。关闭
|
|
183
|
+
'no-console': 'off',
|
|
184
|
+
// 禁止 continue。关闭
|
|
185
|
+
'no-continue': 'off',
|
|
186
|
+
// 禁止速记类型转换
|
|
187
|
+
'no-implicit-coercion': ['error'],
|
|
188
|
+
// async 返回值需要 await。关闭,使用 TS 的同名规则
|
|
189
|
+
'no-return-await': 'off',
|
|
190
|
+
// 禁止未使用的表达式。关闭,使用 TS 版本
|
|
191
|
+
'no-unused-expressions': 'off',
|
|
192
|
+
// 函数名称后需要跟一个空格。关闭
|
|
193
|
+
'space-before-function-paren': 'off',
|
|
194
|
+
|
|
195
|
+
// --- 以下规则已整理 ---
|
|
196
|
+
'array-bracket-spacing': ['error', 'never'],
|
|
197
|
+
'arrow-parens': ['error', 'always'],
|
|
198
|
+
'arrow-spacing': ['error', { after: true, before: true }],
|
|
199
|
+
camelcase: 'off',
|
|
200
|
+
'consistent-return': 'off',
|
|
201
|
+
'class-methods-use-this': 'off',
|
|
202
|
+
'default-case-last': ['error'],
|
|
203
|
+
'eol-last': ['error'],
|
|
204
|
+
eqeqeq: 'error',
|
|
205
|
+
'func-names': ['warn', 'never', { generators: 'as-needed' }],
|
|
206
|
+
'func-style': ['error'],
|
|
207
|
+
'keyword-spacing': ['error'],
|
|
208
|
+
'lines-between-class-members': 'off',
|
|
209
|
+
'max-classes-per-file': 'off',
|
|
210
|
+
'max-len': 'off',
|
|
211
|
+
'no-bitwise': ['error'],
|
|
212
|
+
'no-class-assign': ['error'],
|
|
213
|
+
'no-cond-assign': ['error', 'except-parens'],
|
|
214
|
+
'no-const-assign': ['error'],
|
|
215
|
+
'no-constructor-return': ['error'],
|
|
216
|
+
'no-dupe-class-members': ['error'],
|
|
217
|
+
'no-else-return': ['error'],
|
|
218
|
+
'no-eval': ['error'],
|
|
219
|
+
'no-inner-declarations': 'off',
|
|
220
|
+
'no-labels': ['error'],
|
|
221
|
+
'no-lonely-if': ['error'],
|
|
222
|
+
'no-new': ['error'],
|
|
223
|
+
'no-promise-executor-return': ['error'],
|
|
224
|
+
'no-param-reassign': ['error', { props: false }],
|
|
225
|
+
'no-plusplus': 'off',
|
|
226
|
+
'no-return-assign': ['error', 'except-parens'],
|
|
227
|
+
'no-shadow': 'off',
|
|
228
|
+
'no-mixed-spaces-and-tabs': ['error'],
|
|
229
|
+
'no-multi-assign': 'off',
|
|
230
|
+
'no-multiple-empty-lines': ['error'],
|
|
231
|
+
'no-nested-ternary': 'off',
|
|
232
|
+
'no-spaced-func': 'error',
|
|
233
|
+
'no-trailing-spaces': ['error'],
|
|
234
|
+
'no-use-before-define': 'off',
|
|
235
|
+
'no-useless-computed-key': ['error'],
|
|
236
|
+
'no-useless-concat': ['error'],
|
|
237
|
+
'no-useless-constructor': 'off',
|
|
238
|
+
'no-useless-return': ['error'],
|
|
239
|
+
'no-useless-rename': ['error'],
|
|
240
|
+
'no-undef': ['error'],
|
|
241
|
+
'no-unexpected-multiline': ['error'],
|
|
242
|
+
'no-unreachable-loop': ['error'],
|
|
243
|
+
'no-unneeded-ternary': ['error'],
|
|
244
|
+
'no-unused-vars': [
|
|
245
|
+
'error',
|
|
246
|
+
{ args: 'none', vars: 'all' },
|
|
247
|
+
],
|
|
248
|
+
'no-var': ['error'],
|
|
249
|
+
'no-void': ['error'],
|
|
250
|
+
'object-shorthand': [
|
|
251
|
+
'error',
|
|
252
|
+
'always',
|
|
253
|
+
{ avoidQuotes: true, ignoreConstructors: false },
|
|
254
|
+
],
|
|
255
|
+
'prefer-arrow-callback': [
|
|
256
|
+
'error',
|
|
257
|
+
{ allowNamedFunctions: false, allowUnboundThis: true },
|
|
258
|
+
],
|
|
259
|
+
'prefer-const': ['error'],
|
|
260
|
+
'prefer-destructuring': 'off',
|
|
261
|
+
'prefer-rest-params': ['error'],
|
|
262
|
+
'prefer-template': ['error'],
|
|
263
|
+
quotes: ['error', 'single'],
|
|
264
|
+
'require-atomic-updates': ['error'],
|
|
265
|
+
semi: ['error', 'always'],
|
|
266
|
+
'space-before-blocks': ['error', 'always'],
|
|
267
|
+
'space-in-parens': ['error', 'never'],
|
|
268
|
+
'space-unary-ops': ['error', { nonwords: false, overrides: {} }],
|
|
269
|
+
'symbol-description': ['error'],
|
|
270
|
+
'template-curly-spacing': ['error', 'never'],
|
|
271
|
+
},
|
|
55
272
|
},
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}],
|
|
69
|
-
// 显示函数返回类型。关闭此校验,部分函数没有返回值。无需每个都显示类型
|
|
70
|
-
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
71
|
-
/**
|
|
72
|
-
* 无混淆空表达式。默认所有void都不能直接返回,需要用{}包裹。这里排除掉箭头函数。
|
|
73
|
-
* 可以直接写成 onchange={(value)=> onChange(value) }
|
|
74
|
-
* 而不是 onchange={(value)=>{ onChange(value) }}
|
|
75
|
-
*/
|
|
76
|
-
'@typescript-eslint/no-confusing-void-expression': ['error', {
|
|
77
|
-
ignoreArrowShorthand: true
|
|
78
|
-
}],
|
|
79
|
-
// ts不允许有any类型。关闭此校验,特殊情况,需要any类型
|
|
80
|
-
'@typescript-eslint/no-explicit-any': 'off',
|
|
81
|
-
// 无浮动的promise,要求处理每个promise的then和catch。
|
|
82
|
-
'@typescript-eslint/no-floating-promises': 'off',
|
|
83
|
-
// 不得滥用promise,这里关闭
|
|
84
|
-
'@typescript-eslint/no-misused-promises': 'off',
|
|
85
|
-
// 禁止变量重新声明
|
|
86
|
-
'@typescript-eslint/no-redeclare': 'error',
|
|
87
|
-
// 禁止未使用的表达式
|
|
88
|
-
'@typescript-eslint/no-unused-expressions': ['error', {
|
|
89
|
-
allowShortCircuit: true,
|
|
90
|
-
allowTernary: true
|
|
91
|
-
}],
|
|
92
|
-
// 禁止使用类型断言,应使用 !进行断言,这里关闭。类型断言更语意化,会好些。
|
|
93
|
-
'@typescript-eslint/non-nullable-type-assertion-style': 'off',
|
|
94
|
-
// 限制命名规则。这里关闭。命名希望灵活些
|
|
95
|
-
'@typescript-eslint/naming-convention': 'off',
|
|
96
|
-
// 为了安全使用 ?? 替换 ||。关闭此选项,部分场景,需要手动选择??还是||; ??会把空字符串也认为是true
|
|
97
|
-
'@typescript-eslint/prefer-nullish-coalescing': 'off',
|
|
98
|
-
// promise函数都需要使用async。这里关闭。
|
|
99
|
-
'@typescript-eslint/promise-function-async': 'off',
|
|
100
|
-
// 限制 + 操作符,两边必须相同。这里关闭
|
|
101
|
-
'@typescript-eslint/restrict-plus-operands': 'off',
|
|
102
|
-
// 限制模板表达式。关闭此校验,希望模板表达式更加灵活
|
|
103
|
-
'@typescript-eslint/restrict-template-expressions': 'off',
|
|
104
|
-
// 若函数是async,则返回值需要有await
|
|
105
|
-
'@typescript-eslint/return-await': ['error'],
|
|
106
|
-
// 严格的逻辑表达式。关闭此选项,可以使用 !value 的方式来进行判断;
|
|
107
|
-
'@typescript-eslint/strict-boolean-expressions': 'off',
|
|
108
|
-
// 禁止某些支持 ES6 样式导入声明的三重斜杠指令
|
|
109
|
-
'@typescript-eslint/triple-slash-reference': 'off',
|
|
110
|
-
// 函数体周围是否强制使用大括号。这里关闭,不强制。部分小函数,单行可以实现时,无需大括号限制
|
|
111
|
-
'arrow-body-style': 'off',
|
|
112
|
-
// if语句是否需要加括号。设置为多行加括号,单行不需要加括号
|
|
113
|
-
curly: ['error', 'multi-line'],
|
|
114
|
-
'default-param-last': 'off',
|
|
115
|
-
// 禁止整个文件的注释,只允许注释文件块。这里关闭。
|
|
116
|
-
'eslint-comments/disable-enable-pair': 'off',
|
|
117
|
-
// 名称校验,这里关闭
|
|
118
|
-
'import/named': 'off',
|
|
119
|
-
// 禁止console输入。这里关闭
|
|
120
|
-
'no-console': 'off',
|
|
121
|
-
// 禁止使用continue跳出循环。这里关闭
|
|
122
|
-
'no-continue': 'off',
|
|
123
|
-
// 禁止速记类型转换
|
|
124
|
-
'no-implicit-coercion': ['error'],
|
|
125
|
-
// 若函数是async,则返回值需要有await,这里关闭,使用typescript的同名规则;
|
|
126
|
-
'no-return-await': 'off',
|
|
127
|
-
// 禁止未使用的表达式
|
|
128
|
-
'no-unused-expressions': 'off',
|
|
129
|
-
// 函数名称后需要跟一个空格。这里关闭
|
|
130
|
-
'space-before-function-paren': 'off',
|
|
131
|
-
// 在属性上使用析构函数变量。这里关闭
|
|
132
|
-
'unicorn/consistent-destructuring': 'off',
|
|
133
|
-
// 箭头函数移动到外部作用于。这里关闭。在react组件内,经常会使用到箭头函数
|
|
134
|
-
'unicorn/consistent-function-scoping': 'off',
|
|
135
|
-
// 使用更具有描述性的名称。这里关闭
|
|
136
|
-
'unicorn/prevent-abbreviations': 'off',
|
|
137
|
-
// 不允许使用 新的特性。这里关闭
|
|
138
|
-
'unicorn/new-for-builtins': 'off',
|
|
139
|
-
// 禁止将函数直接传给方法。这里关闭。
|
|
140
|
-
'unicorn/no-array-callback-reference': 'off',
|
|
141
|
-
// 不允许使用 array的forEach。这里管理
|
|
142
|
-
'unicorn/no-array-for-each': 'off',
|
|
143
|
-
// 不允许使用 array的reduce方法。这里关闭
|
|
144
|
-
'unicorn/no-array-reduce': 'off',
|
|
145
|
-
// 不允许使用 new Array()声明数组。这里关闭
|
|
146
|
-
'unicorn/no-new-array': 'off',
|
|
147
|
-
// 不使用 null。这里关闭。实际上,与后台交互时,经常需要用到null。也更有语义化。
|
|
148
|
-
'unicorn/no-null': 'off',
|
|
149
|
-
// 强制使用数字分隔符。这里关闭。
|
|
150
|
-
'unicorn/numeric-separators-style': 'off',
|
|
151
|
-
// 使用esm的格式,而不是commonjs。这里关闭。部分模块还是需要使用commonjs保证兼容性
|
|
152
|
-
'unicorn/prefer-module': 'off',
|
|
153
|
-
// 以下配置待整理完善,以上配置已整理,尽量不要动了。
|
|
154
|
-
'array-bracket-spacing': ['error', 'never'],
|
|
155
|
-
'arrow-parens': ['error', 'always'],
|
|
156
|
-
'arrow-spacing': ['error', {
|
|
157
|
-
after: true,
|
|
158
|
-
before: true
|
|
159
|
-
}],
|
|
160
|
-
camelcase: 'off',
|
|
161
|
-
'consistent-return': 'off',
|
|
162
|
-
'class-methods-use-this': 'off',
|
|
163
|
-
'default-case-last': ['error'],
|
|
164
|
-
'eol-last': ['error'],
|
|
165
|
-
eqeqeq: 'error',
|
|
166
|
-
'func-names': ['warn', 'never', {
|
|
167
|
-
generators: 'as-needed'
|
|
168
|
-
}],
|
|
169
|
-
'func-style': ['error'],
|
|
170
|
-
'import/export': 'off',
|
|
171
|
-
'import/extensions': 'off',
|
|
172
|
-
'import/no-cycle': 'off',
|
|
173
|
-
'import/no-extraneous-dependencies': 'off',
|
|
174
|
-
'import/no-named-as-default': 'off',
|
|
175
|
-
'import/no-relative-packages': 'off',
|
|
176
|
-
'import/no-unresolved': 'off',
|
|
177
|
-
'import/prefer-default-export': 'off',
|
|
178
|
-
'keyword-spacing': ['error'],
|
|
179
|
-
'lines-between-class-members': 'off',
|
|
180
|
-
'max-classes-per-file': 'off',
|
|
181
|
-
'max-len': ['error', {
|
|
182
|
-
code: 180,
|
|
183
|
-
ignoreComments: true,
|
|
184
|
-
ignoreRegExpLiterals: true
|
|
185
|
-
}],
|
|
186
|
-
'no-bitwise': ['error'],
|
|
187
|
-
'no-class-assign': ['error'],
|
|
188
|
-
'no-cond-assign': ['error', 'except-parens'],
|
|
189
|
-
'no-const-assign': ['error'],
|
|
190
|
-
'no-constructor-return': ['error'],
|
|
191
|
-
'no-dupe-class-members': ['error'],
|
|
192
|
-
'no-duplicate-imports': ['error'],
|
|
193
|
-
'no-else-return': ['error'],
|
|
194
|
-
'no-eval': ['error'],
|
|
195
|
-
'no-inner-declarations': 'off',
|
|
196
|
-
'no-labels': ['error'],
|
|
197
|
-
'no-lonely-if': ['error'],
|
|
198
|
-
'no-new': ['error'],
|
|
199
|
-
'no-promise-executor-return': ['error'],
|
|
200
|
-
'no-param-reassign': ['error', {
|
|
201
|
-
props: false
|
|
202
|
-
}],
|
|
203
|
-
'no-plusplus': 'off',
|
|
204
|
-
'no-return-assign': ['error', 'except-parens'],
|
|
205
|
-
'no-shadow': 'off',
|
|
206
|
-
'no-mixed-spaces-and-tabs': ['error'],
|
|
207
|
-
'no-multi-assign': 'off',
|
|
208
|
-
'no-multiple-empty-lines': ['error'],
|
|
209
|
-
'no-nested-ternary': 'off',
|
|
210
|
-
'no-new-symbol': ['error'],
|
|
211
|
-
'no-spaced-func': ['error'],
|
|
212
|
-
'no-trailing-spaces': ['error'],
|
|
213
|
-
'no-use-before-define': 'off',
|
|
214
|
-
'no-useless-computed-key': ['error'],
|
|
215
|
-
'no-useless-concat': ['error'],
|
|
216
|
-
'no-useless-constructor': 'off',
|
|
217
|
-
'no-useless-return': ['error'],
|
|
218
|
-
'no-useless-rename': ['error'],
|
|
219
|
-
'no-undef': ['error'],
|
|
220
|
-
'no-unexpected-multiline': ['error'],
|
|
221
|
-
'no-unreachable-loop': ['error'],
|
|
222
|
-
'no-unneeded-ternary': ['error'],
|
|
223
|
-
'no-unused-vars': ['error', {
|
|
224
|
-
args: 'none',
|
|
225
|
-
vars: 'all'
|
|
226
|
-
}],
|
|
227
|
-
'no-var': ['error'],
|
|
228
|
-
'no-void': ['error'],
|
|
229
|
-
'object-shorthand': ['error', 'always', {
|
|
230
|
-
avoidQuotes: true,
|
|
231
|
-
ignoreConstructors: false
|
|
232
|
-
}],
|
|
233
|
-
'prefer-arrow-callback': ['error', {
|
|
234
|
-
allowNamedFunctions: false,
|
|
235
|
-
allowUnboundThis: true
|
|
236
|
-
}],
|
|
237
|
-
'prefer-const': ['error'],
|
|
238
|
-
'prefer-destructuring': 'off',
|
|
239
|
-
'prefer-rest-params': ['error'],
|
|
240
|
-
'prefer-template': ['error'],
|
|
241
|
-
'promise/always-return': 'off',
|
|
242
|
-
'promise/catch-or-return': 'off',
|
|
243
|
-
quotes: ['error'],
|
|
244
|
-
'require-atomic-updates': ['error'],
|
|
245
|
-
semi: ['error', 'always'],
|
|
246
|
-
'space-before-blocks': ['error', 'always'],
|
|
247
|
-
'space-in-parens': ['error', 'never'],
|
|
248
|
-
'space-unary-ops': ['error', {
|
|
249
|
-
nonwords: false,
|
|
250
|
-
overrides: {}
|
|
251
|
-
}],
|
|
252
|
-
'symbol-description': ['error'],
|
|
253
|
-
'template-curly-spacing': ['error', 'never'],
|
|
254
|
-
'unicorn/filename-case': 'off'
|
|
255
|
-
}
|
|
256
|
-
};
|
|
273
|
+
|
|
274
|
+
// ===== 忽略文件 =====
|
|
275
|
+
{
|
|
276
|
+
ignores: [
|
|
277
|
+
'**/node_modules/**',
|
|
278
|
+
'**/dist/**',
|
|
279
|
+
'**/docs-dist/**',
|
|
280
|
+
'**/.dumi/**',
|
|
281
|
+
'**/*.d.ts',
|
|
282
|
+
],
|
|
283
|
+
},
|
|
284
|
+
);
|
|
@@ -1,55 +1,69 @@
|
|
|
1
|
+
// ESLint 9 Flat Config - React 扩展
|
|
1
2
|
// @ts-check
|
|
3
|
+
const tseslint = require('typescript-eslint');
|
|
4
|
+
const reactPlugin = require('eslint-plugin-react');
|
|
5
|
+
const reactHooksPlugin = require('eslint-plugin-react-hooks');
|
|
6
|
+
const jsxA11yPlugin = require('eslint-plugin-jsx-a11y');
|
|
7
|
+
const { FlatCompat } = require('@eslint/eslintrc');
|
|
8
|
+
const baseConfig = require('../index');
|
|
9
|
+
|
|
10
|
+
const compat = new FlatCompat();
|
|
11
|
+
|
|
2
12
|
/**
|
|
3
|
-
*
|
|
13
|
+
* React ESLint Flat Config
|
|
14
|
+
* 在基础配置上增加 React 相关规则
|
|
15
|
+
*
|
|
16
|
+
* 使用方式(eslint.config.mjs):
|
|
17
|
+
* import reactConfig from '@zpcscc/configs/eslint-config/react';
|
|
18
|
+
* export default [...reactConfig];
|
|
4
19
|
*/
|
|
5
|
-
module.exports =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
module.exports = tseslint.config(
|
|
21
|
+
// 继承基础配置
|
|
22
|
+
...baseConfig,
|
|
23
|
+
|
|
24
|
+
// React 插件(原生 flat config)
|
|
25
|
+
reactPlugin.configs.flat.recommended,
|
|
26
|
+
reactPlugin.configs.flat['jsx-runtime'],
|
|
27
|
+
|
|
28
|
+
// React Hooks(使用 FlatCompat 兼容旧格式)
|
|
29
|
+
...compat.config(reactHooksPlugin.configs.recommended),
|
|
30
|
+
|
|
31
|
+
// JSX A11y
|
|
32
|
+
jsxA11yPlugin.flatConfigs.recommended,
|
|
33
|
+
|
|
34
|
+
// React 特定配置
|
|
35
|
+
{
|
|
36
|
+
languageOptions: {
|
|
37
|
+
parserOptions: {
|
|
38
|
+
ecmaFeatures: { jsx: true },
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
settings: {
|
|
42
|
+
react: {
|
|
43
|
+
version: 'detect',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
plugins: {
|
|
47
|
+
react: reactPlugin,
|
|
48
|
+
},
|
|
49
|
+
rules: {
|
|
50
|
+
'react/destructuring-assignment': 'off',
|
|
51
|
+
'react/jsx-uses-react': 'off',
|
|
52
|
+
'react/jsx-props-no-spreading': 'off',
|
|
53
|
+
// props 类型检查,TS 有静态类型检查
|
|
54
|
+
'react/prop-types': 'off',
|
|
55
|
+
'react/react-in-jsx-scope': 'off',
|
|
56
|
+
'react/self-closing-comp': 'warn',
|
|
57
|
+
'react/sort-comp': 'off',
|
|
58
|
+
'react/no-access-state-in-setstate': 'off',
|
|
59
|
+
// 忽略 emotion 的 css 属性报错
|
|
60
|
+
'react/no-unknown-property': ['error', { ignore: ['css'] }],
|
|
61
|
+
// useEffect 依赖数组提示
|
|
62
|
+
'react-hooks/exhaustive-deps': 'off',
|
|
63
|
+
// 非 button 元素点击事件必须有键盘事件。关闭
|
|
64
|
+
'jsx-a11y/click-events-have-key-events': 'off',
|
|
65
|
+
// 交互式元素应是可聚焦的。关闭
|
|
66
|
+
'jsx-a11y/interactive-supports-focus': 'off',
|
|
67
|
+
},
|
|
25
68
|
},
|
|
26
|
-
|
|
27
|
-
// eslint-plugin-react的配置https://github.com/jsx-eslint/eslint-plugin-react#configuration
|
|
28
|
-
react: {
|
|
29
|
-
version: 'detect'
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
rules: {
|
|
33
|
-
'react/destructuring-assignment': 'off',
|
|
34
|
-
// react17之后引入新的jsx转换。不再需要显示引入react。这两项规则需要关闭。
|
|
35
|
-
'react/jsx-uses-react': 'off',
|
|
36
|
-
'react/jsx-props-no-spreading': 'off',
|
|
37
|
-
// props类型检查.关闭此校验,ts有静态类型检查
|
|
38
|
-
'react/prop-types': 'off',
|
|
39
|
-
'react/react-in-jsx-scope': 'off',
|
|
40
|
-
'react/self-closing-comp': 'warn',
|
|
41
|
-
'react/sort-comp': 'off',
|
|
42
|
-
'react/no-access-state-in-setstate': 'off',
|
|
43
|
-
// 禁止未知属性。这里忽略emotion里的css属性报错。将css属性视为正常属性
|
|
44
|
-
'react/no-unknown-property': ['error', {
|
|
45
|
-
ignore: ['css']
|
|
46
|
-
}],
|
|
47
|
-
// useEffect数组的提示
|
|
48
|
-
'react-hooks/exhaustive-deps': 'off',
|
|
49
|
-
// 非button的元素点击事件必须同时有个键盘事件。这里关闭
|
|
50
|
-
'jsx-a11y/click-events-have-key-events': 'off',
|
|
51
|
-
// 交互式元素应是可聚焦的。这里关闭
|
|
52
|
-
'jsx-a11y/interactive-supports-focus': 'off'
|
|
53
|
-
// 强制填写了默认值的参数在最后。需关闭此选项,否则部分函数参数值,无法任意调整位置。
|
|
54
|
-
}
|
|
55
|
-
};
|
|
69
|
+
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zpcscc/configs",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7",
|
|
4
4
|
"description": "项目通用配置",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"commitlint",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"types"
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
|
-
"build": "father build && mkdir -p dist/tsconfig && cp src/tsconfig/tsconfig.json dist/tsconfig/",
|
|
30
|
+
"build": "father build && mkdir -p dist/tsconfig && cp src/tsconfig/tsconfig.json dist/tsconfig/ && rm -rf dist/eslint-config && cp -r src/eslint-config dist/eslint-config",
|
|
31
31
|
"build:watch": "father dev",
|
|
32
32
|
"commit": "git add . && git-cz",
|
|
33
33
|
"deploy": "pnpm run docs:build && pnpm run docs:deploy",
|
|
@@ -43,31 +43,32 @@
|
|
|
43
43
|
"@babel/plugin-syntax-flow": "7.26.0",
|
|
44
44
|
"@babel/plugin-transform-react-jsx": "7.25.9",
|
|
45
45
|
"@babel/runtime": "7.26.10",
|
|
46
|
-
"@commitlint/cz-commitlint": "
|
|
46
|
+
"@commitlint/cz-commitlint": "20.5.0",
|
|
47
|
+
"@eslint-community/eslint-plugin-eslint-comments": "4.7.1",
|
|
48
|
+
"@eslint/eslintrc": "3.3.5",
|
|
49
|
+
"@eslint/js": "9.39.4",
|
|
47
50
|
"@types/node": "22.13.10",
|
|
48
51
|
"@types/react": "19.0.11",
|
|
49
52
|
"@types/react-dom": "19.0.4",
|
|
50
|
-
"@typescript-eslint/eslint-plugin": "8.26.1",
|
|
51
|
-
"@typescript-eslint/parser": "8.26.1",
|
|
52
53
|
"commitizen": "4.3.1",
|
|
53
|
-
"eslint": "
|
|
54
|
+
"eslint": "9.27.0",
|
|
54
55
|
"eslint-config-prettier": "10.1.1",
|
|
55
|
-
"eslint-config-standard": "17.1.0",
|
|
56
56
|
"eslint-import-resolver-typescript": "4.2.0",
|
|
57
|
-
"eslint-plugin-
|
|
58
|
-
"eslint-plugin-import": "2.31.0",
|
|
57
|
+
"eslint-plugin-import-x": "4.16.2",
|
|
59
58
|
"eslint-plugin-jsx-a11y": "6.10.2",
|
|
60
59
|
"eslint-plugin-prettier": "5.2.3",
|
|
61
|
-
"eslint-plugin-promise": "
|
|
62
|
-
"eslint-plugin-react": "7.37.
|
|
60
|
+
"eslint-plugin-promise": "7.2.1",
|
|
61
|
+
"eslint-plugin-react": "7.37.5",
|
|
63
62
|
"eslint-plugin-react-hooks": "5.2.0",
|
|
64
|
-
"eslint-plugin-unicorn": "
|
|
65
|
-
"
|
|
63
|
+
"eslint-plugin-unicorn": "59.0.1",
|
|
64
|
+
"globals": "17.4.0",
|
|
65
|
+
"inquirer": "9.3.8",
|
|
66
66
|
"postcss": "8.5.3",
|
|
67
67
|
"prettier": "3.5.3",
|
|
68
68
|
"prettier-plugin-organize-imports": "4.1.0",
|
|
69
69
|
"prettier-plugin-packagejson": "2.5.10",
|
|
70
|
-
"typescript": "5.8.2"
|
|
70
|
+
"typescript": "5.8.2",
|
|
71
|
+
"typescript-eslint": "8.57.2"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
73
74
|
"dumi": "2.4.18",
|
package/tsconfig/tsconfig.json
CHANGED
|
@@ -34,15 +34,13 @@
|
|
|
34
34
|
"sourceMap": true,
|
|
35
35
|
// 报告未使用的局部变量的错误。建议开启
|
|
36
36
|
"noUnusedLocals": true,
|
|
37
|
-
// 严格的空检查;建议开启,方便提示某字段可能为null,undefined,false等情况
|
|
38
|
-
"strictNullChecks": true,
|
|
39
37
|
// 启用对装饰器的实验性支持
|
|
40
38
|
"experimentalDecorators": true,
|
|
41
39
|
// 允许默认全部导出,而不是 * as newName的形式
|
|
42
40
|
"allowSyntheticDefaultImports": true,
|
|
43
|
-
//
|
|
44
|
-
"isolatedModules":
|
|
45
|
-
//
|
|
41
|
+
// 开启后,所有的文件都应是模块。Vite/esbuild/SWC 等工具链要求开启
|
|
42
|
+
"isolatedModules": true
|
|
43
|
+
// TS 5.0+ 推荐开启,替代 esModuleInterop + allowSyntheticDefaultImports
|
|
46
44
|
// "verbatimModuleSyntax": true
|
|
47
45
|
// 允许在项目中导入js文件
|
|
48
46
|
// "allowJs": true,
|