-
Notifications
You must be signed in to change notification settings - Fork 18
/
.eslintrc.js
134 lines (130 loc) · 3.65 KB
/
.eslintrc.js
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
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
'react',
'react-hooks',
'import',
'jsx-a11y',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'airbnb',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:import/typescript',
'plugin:jsx-a11y/recommended',
],
settings: {
react: {
version: 'detect',
},
},
globals: {
Worker: true,
globalThis: true,
document: true,
JSX: true,
React: 'readonly',
localStorage: true,
HTMLElement: true,
window: true,
// 在这里添加其他全局变量
},
rules: {
// 常用规则
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'no-console': ['warn', { allow: ['warn', 'error'] }],
'no-debugger': 'error',
'prefer-template': 'error',
'@typescript-eslint/ban-ts-comment': 'off',
'func-names': 'off',
'no-use-before-define': 'off',
'import/no-import-module-exports': 'off',
'no-plusplus': 'off',
'prefer-regex-literals': 'off',
'no-await-in-loop': 'off',
'no-restricted-syntax': 'off',
'no-shadow': 'off',
'no-bitwise': 'off',
'class-methods-use-this': 'off',
radix: 'off',
'guard-for-in': 'off',
'max-len': ['error', { code: 250 }],
// TypeScript 相关
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'no-unused-expressions': 'off',
// React 相关
'react/jsx-filename-extension': ['error', { extensions: ['.jsx', '.tsx'] }],
'react/prop-types': 'off',
'react/jsx-props-no-spreading': 'off',
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'react/no-unused-prop-types': 'warn',
'jsx-a11y/click-events-have-key-events': 'warn',
'react/jsx-no-bind': 'off',
'react/require-default-props': 'off',
'react/no-array-index-key': 'off',
'jsx-a11y/no-static-element-interactions': 'off',
// import 相关
'import/prefer-default-export': 'off',
'import/extensions': ['error', 'never', { svg: 'always' }],
'import/order': ['error', {
'newlines-between': 'always',
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
pathGroups: [
{
pattern: 'react',
group: 'external',
position: 'before',
},
],
pathGroupsExcludedImportTypes: ['builtin'],
}],
'import/no-unresolved': [
'error',
{
ignore: ['^@theme-original', '^@docusaurus', '^@theme-init', '^@theme'],
},
],
// 全局变量 相关
'no-restricted-globals': ['error', {
name: 'addEventListener',
message: 'Use `self.addEventListener` instead.',
}, {
name: 'importScripts',
message: 'Use `self.importScripts` instead.',
}, {
name: 'self',
message: 'Use `globalThis` instead.',
}],
},
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
// 在这里添加针对 TypeScript 的规则
},
},
{
files: ['*.jsx', '*.tsx'],
rules: {
// 在这里添加针对 React/JSX 的规则
},
},
{
files: ['next/**/*.js', 'next/**/*.jsx', 'next/**/*.ts', 'next/**/*.tsx'],
rules: {
// 在这里添加针对 Next.js 项目的规则
},
},
],
ignorePatterns: ['dist/', 'build/'],
};