-
Notifications
You must be signed in to change notification settings - Fork 1
/
.eslintrc.js
130 lines (120 loc) · 3.48 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
const { off } = require('process');
const OFF = 0;
const WARN = 1;
const ERROR = 2;
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
extends: [
'airbnb',
'airbnb/hooks',
'plugin:eslint-comments/recommended',
'plugin:react/recommended',
'plugin:unicorn/recommended',
'plugin:promise/recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/react',
'prettier/unicorn',
'prettier/@typescript-eslint',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
sourceType: 'module',
},
settings: {
'import/resolver': {
node: {
// 指定eslint-plugin-import解析的后缀名,出现频率高的文件类型放在前面
extensions: ['.ts', '.tsx', '.js', '.json'],
},
// 配合eslint-import-resolver-typescript解决ts的import时的路径映射问题
typescript: {},
},
},
plugins: ['react', 'unicorn', 'promise', '@typescript-eslint'],
rules: {
// eslint-plugin-import和typescript搭配不能正确处理后缀名bug
'import/extensions': [
ERROR,
'ignorePackages',
{
ts: 'never',
tsx: 'never',
json: 'never',
js: 'never',
},
],
// 在Windows下忽略换行符号类型
'linebreak-style': [OFF, 'windows'],
'import/no-extraneous-dependencies': [ERROR, { devDependencies: true }],
'import/prefer-default-export': OFF,
'import/no-unresolved': ERROR,
'unicorn/better-regex': ERROR,
'unicorn/prevent-abbreviations': OFF,
'unicorn/filename-case': [
ERROR,
{
cases: {
// 中划线
kebabCase: true,
// 小驼峰
camelCase: true,
// 下划线
snakeCase: false,
// 大驼峰
pascalCase: true,
},
},
],
'unicorn/no-array-instanceof': WARN,
'unicorn/no-for-loop': WARN, // 使用for of和.entries代替传统的for循环
'unicorn/prefer-add-event-listener': [
ERROR,
{
excludedPackages: ['koa', 'sax'],
},
],
'unicorn/prefer-query-selector': ERROR,
'unicorn/no-null': OFF,
'@typescript-eslint/no-useless-constructor': ERROR,
'@typescript-eslint/no-empty-function': WARN,
'@typescript-eslint/no-var-requires': OFF,
'@typescript-eslint/explicit-function-return-type': OFF,
'@typescript-eslint/explicit-modul-boundary-types': OFF,
'@typescript-eslint/no-explicit-any': OFF,
'react/jsx-filename-extension': [
ERROR,
{
extensions: ['.js', 'jsx', '.ts', '.tsx'],
},
],
'react/jsx-indent-props': [ERROR, 2],
'react/jsx-indent': [ERROR, 2],
'react/jsx-one-expression-per-line': OFF,
'react/destructuring-assignment': OFF,
'react/state-in-constructor': OFF,
'react/jsx-props-no-spreading': OFF,
'react/prop-types': OFF,
'jsx-a11y/click-events-have-key-events': OFF,
'jsx-a11y/no-noninteractive-element-interactions': OFF,
'lines-between-class-members': [ERROR, 'always'],
quotes: [ERROR, 'single'],
semi: [ERROR, 'always'],
'no-unused-expressions': WARN,
'no-plusplus': OFF,
'no-console': OFF,
'class-methods-use-this': ERROR,
'global-require': OFF,
// 避免error 'React' was used before it was defined no-use-before-define错误的折衷解决办法
'no-use-before-define': OFF,
'@typescript-eslint/no-use-before-define': OFF,
},
};