Skip to content

Commit 46d3d3f

Browse files
committed
chore: eslint 配置调整优化
1 parent 8d13c7c commit 46d3d3f

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

eslint.config.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,44 @@ export default tseslint.config(
2424
},
2525
rules: {
2626
...reactHooks.configs.recommended.rules,
27-
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
28-
'@typescript-eslint/no-unused-vars': 'off', // 禁用 TypeScript 未使用变量的警告
29-
'react-refresh/only-export-components': 'off', // 禁用 react-refresh 插件中仅导出组件的规则
30-
'@typescript-eslint/no-explicit-any': 'off', // 允许使用any
31-
'@typescript-eslint/no-unused-expressions': 'off', // 关闭对未使用的表达式的检查
27+
28+
// React 相关规则
29+
'react-refresh/only-export-components': 'off',
3230
'@eslint-react/hooks-extra/no-unnecessary-use-prefix': 'off',
33-
// 'react-hooks/exhaustive-deps': 'off' // 关闭依赖项检查规则
31+
32+
// TypeScript 相关规则优化
33+
'@typescript-eslint/no-unused-vars': [
34+
'warn',
35+
{
36+
argsIgnorePattern: '^_',
37+
varsIgnorePattern: '^_',
38+
caughtErrorsIgnorePattern: '^_',
39+
},
40+
],
41+
'@typescript-eslint/no-explicit-any': 'off',
42+
'@typescript-eslint/no-unused-expressions': [
43+
'error',
44+
{
45+
allowShortCircuit: true,
46+
allowTernary: true,
47+
allowTaggedTemplates: true,
48+
},
49+
],
50+
'@typescript-eslint/prefer-nullish-coalescing': 'off',
51+
'@typescript-eslint/prefer-optional-chain': 'off',
52+
'@typescript-eslint/no-non-null-assertion': 'off',
53+
54+
// 代码质量规则
55+
'no-console': ['warn', { allow: ['warn', 'error'] }],
56+
'no-debugger': 'error',
57+
'prefer-const': 'error',
58+
'no-var': 'error',
59+
60+
// React Hooks 规则
61+
'react-hooks/exhaustive-deps': 'warn',
62+
63+
// 导入规则
64+
'no-duplicate-imports': 'error',
3465
},
3566
languageOptions: {
3667
parser: tseslint.parser,

tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"noUnusedParameters": true,
2121
"noFallthroughCasesInSwitch": true,
2222
"noUncheckedSideEffectImports": true,
23+
"exactOptionalPropertyTypes": true,
24+
"noImplicitReturns": true,
25+
"noPropertyAccessFromIndexSignature": false,
26+
"noUncheckedIndexedAccess": false,
2327

2428
/** 别名路径提示 */
2529
"baseUrl": ".",

0 commit comments

Comments
 (0)