-
Notifications
You must be signed in to change notification settings - Fork 12
/
.eslintrc.js
202 lines (191 loc) · 7.13 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
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
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
// airbnb规范
// https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb
'airbnb',
// 兼容typescript的airbnb规范
// https://github.com/iamturns/eslint-config-airbnb-typescript
'airbnb-typescript',
// react hooks的airbnb规范
'airbnb/hooks',
// typescript的eslint插件
// https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/README.md
// https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
// jest测试插件
// https://github.com/jest-community/eslint-plugin-jest
'plugin:jest/recommended',
// 使用prettier格式化代码
// https://github.com/prettier/eslint-config-prettier#readme
'prettier',
// 整合typescript-eslint与prettier
// https://github.com/prettier/eslint-plugin-prettier
'plugin:prettier/recommended',
],
parserOptions: {
// 指定ESLint可以解析JSX语法
ecmaVersion: '2020',
sourceType: 'module',
project: './tsconfig.eslint.json',
// React启用jsx
ecmaFeatures: {
jsx: true,
},
},
env: {
es6: true,
browser: true,
jest: true,
node: true,
},
plugins: ['@typescript-eslint', 'import', 'jest', 'unused-imports'],
rules: {
/* ********************************** ES6+ ********************************** */
'no-console': 0,
'no-var-requires': 0,
'no-restricted-syntax': 0,
'no-continue': 0,
'no-await-in-loop': 0,
'no-return-await': 0,
'no-multi-assign': 0,
'no-param-reassign': [2, { props: false }],
'max-classes-per-file': 0,
'class-methods-use-this': 0,
'guard-for-in': 0,
'no-underscore-dangle': 0,
'no-plusplus': 0,
'no-lonely-if': 0,
'no-bitwise': ['error', { allow: ['~'] }],
/* ********************************** Module Import ********************************** */
'import/prefer-default-export': 0,
'import/no-cycle': 0,
'import/no-dynamic-require': 0,
'import/no-absolute-path': 0,
'import/extensions': 0,
// 一部分文件在导入devDependencies的依赖时不报错
'import/no-extraneous-dependencies': [
1,
{
devDependencies: [
'**/*.test.{ts,js}',
'**/*.spec.{ts,js}',
'build/**/*.{ts,js}',
'mock/**/*.{ts,js}',
'**.{ts,js}',
],
},
],
// 模块导入顺序规则
'import/order': [
1,
{
pathGroups: [
{
pattern: '@/**',
group: 'external',
position: 'after',
},
],
'newlines-between': 'always-and-inside-groups',
warnOnUnassignedImports: true,
},
],
// 自动删除未使用的导入
// https://github.com/sweepline/eslint-plugin-unused-imports
'no-unused-vars': 0,
'@typescript-eslint/no-unused-vars': 0,
'unused-imports/no-unused-imports': 1,
'unused-imports/no-unused-vars': [
'error',
{
vars: 'all',
args: 'none',
ignoreRestSiblings: true,
},
],
// 自动删除未使用导入(另一种方案)
// https://github.com/aladdin-add/eslint-plugin/tree/master/packages/autofix
// 'no-unused-vars': [
// 'error',
// {
// vars: 'all',
// args: 'none',
// ignoreRestSiblings: true,
// },
// ],
// 'autofix/no-unused-vars': [
// 'error',
// {
// vars: 'all',
// args: 'none',
// ignoreRestSiblings: true,
// },
// ],
// '@typescript-eslint/no-unused-vars': [
// 'error',
// {
// vars: 'all',
// args: 'none',
// ignoreRestSiblings: true,
// },
// ],
/* ********************************** Typescript ********************************** */
'@typescript-eslint/no-empty-interface': 0,
'@typescript-eslint/no-this-alias': 0,
'@typescript-eslint/no-var-requires': 0,
'@typescript-eslint/no-use-before-define': 0,
'@typescript-eslint/explicit-member-accessibility': 0,
'@typescript-eslint/no-non-null-assertion': 0,
'@typescript-eslint/no-unnecessary-type-assertion': 0,
'@typescript-eslint/require-await': 0,
'@typescript-eslint/no-for-in-array': 0,
'@typescript-eslint/interface-name-prefix': 0,
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/no-floating-promises': 0,
'@typescript-eslint/restrict-template-expressions': 0,
'@typescript-eslint/no-unsafe-assignment': 0,
'@typescript-eslint/no-unsafe-return': 0,
'@typescript-eslint/no-unused-expressions': 0,
'@typescript-eslint/no-misused-promises': 0,
'@typescript-eslint/no-unsafe-member-access': 0,
'@typescript-eslint/no-unsafe-call': 0,
'@typescript-eslint/no-unsafe-argument': 0,
/* ********************************** React and Hooks ********************************** */
'react/jsx-uses-react': 1,
'react/jsx-uses-vars': 1,
'react/jsx-no-useless-fragment': 0,
'react/display-name': 0,
'react/button-has-type': 0,
'react/prop-types': 0,
'react/jsx-props-no-spreading': 0,
'react/destructuring-assignment': 0,
'react/static-property-placement': 0,
'react/react-in-jsx-scope': 0,
'react/require-default-props': 0,
'react/jsx-filename-extension': [1, { extensions: ['.jsx', '.tsx'] }],
'react/function-component-definition': [
2,
{ namedComponents: 'arrow-function', unnamedComponents: 'arrow-function' },
],
'react-hooks/exhaustive-deps': 0,
/* ********************************** jax-a11y ********************************** */
'jsx-a11y/anchor-is-valid': 0,
'jsx-a11y/no-static-element-interactions': 0,
'jsx-a11y/click-events-have-key-events': 0,
'jsx-a11y/label-has-associated-control': [
'error',
{
required: {
some: ['nesting', 'id'],
},
},
],
},
settings: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts', '.json'],
},
};