-
Notifications
You must be signed in to change notification settings - Fork 2
/
.eslintrc.json
171 lines (121 loc) · 5.2 KB
/
.eslintrc.json
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
{
"root": true,
"ignorePatterns": ["**/*.d.ts"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": "./tsconfig.json",
"ecmaFeatures": {
"jsx": true
}
},
"plugins": [
"@typescript-eslint",
"react",
"xlint"
],
"settings": {
"react": {
"version": "detect"
}
},
"env": {
"node": true,
"browser": true
},
"rules": {
"xlint/fold-jsdoc-comments": "error",
// 取代 nonblock-statement-body-position
"xlint/nonblock-statement-body-position-with-indentation": "error",
"xlint/empty-bracket-spacing": "error",
// a + b**c
"xlint/space-infix-ops-except-exponentiation": "error",
"xlint/space-in-for-statement": "error",
"xlint/jsx-no-redundant-parenthesis-in-return": "error",
"xlint/keep-indent": "error",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/no-extra-semi": "error",
"semi-style": ["error", "first"],
// 使用 ===
"eqeqeq": "error",
// 父类尽量返回 this 类型
"@typescript-eslint/prefer-return-this-type": "error",
// 尽量使用 . 访问属性而不是 []
"@typescript-eslint/dot-notation": "error",
// 必须 throw Error
"@typescript-eslint/no-throw-literal": "error",
// ------------ async
// 返回 Promise 的函数一定要标记为 async 函数
"@typescript-eslint/promise-function-async": "error",
// 不要 return await promise, 直接 return promise, 除非外面有 try catch
"@typescript-eslint/return-await": "error",
// ------------ 括号
// a => { } 而不是 (a) => { }
"arrow-parens": ["error", "as-needed", { "requireForBlockBody": false }],
// 不要多余的大括号
// if (true)
// console.log()
"curly": ["error", "multi"],
// 简单属性不要冗余的大括号 <Component prop='simple-value' />
"react/jsx-curly-brace-presence": ["error", "never"],
// ------------ 空格
// { a, b } 这样的对象,大括号里面要有空格
"@typescript-eslint/object-curly-spacing": ["error", "always"],
// [a, b, c]
"@typescript-eslint/comma-spacing": "error",
// foo()
"@typescript-eslint/func-call-spacing": "error",
// a => { } 中箭头左右两边空格
"arrow-spacing": ["error"],
// 注释双斜杠后面要有空格
"spaced-comment": ["error", "always", { "markers": ["/"] }],
// 函数声明中,名称后面要有空格
"@typescript-eslint/space-before-function-paren": "error",
// { return true } 这样的 block 大括号里面要有空格
"block-spacing": ["error", "always"],
// aaa: 123
"@typescript-eslint/key-spacing": ["error", { "beforeColon": false, "afterColon": true, "mode": "minimum" }],
// aaa: string
"@typescript-eslint/type-annotation-spacing": "error",
// if ()
"@typescript-eslint/keyword-spacing": ["error", { "before": true, "after": true }],
// if (1) { }
"@typescript-eslint/space-before-blocks": "error",
// case 1: ...
"switch-colon-spacing": "error",
// <Hello name={firstname} />
"react/jsx-equals-spacing": ["error", "never"],
// 不允许使用 tab
"no-tabs": "error",
// 使用 \n 换行
"linebreak-style": ["error", "unix"],
// 文件以 \n 结尾
"eol-last": ["error", "always"],
// ------------ 引号
// 用单引号
"jsx-quotes": ["error", "prefer-single"],
// 用单引号
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": false }],
// 不要冗余的引号包裹属性
"quote-props": ["error", "as-needed", { "keywords": false, "unnecessary": true }],
// ------------ 其它
// boolean 属性不要冗余的 ={true} <Component boolprop />
"react/jsx-boolean-value": ["error", "never"],
// 没有 children 的 Component 写成闭合标签 <Component />
"react/self-closing-comp": "error",
// 单行类型声明用 `,` 分割,多行类型声明结尾不要加分号
"@typescript-eslint/member-delimiter-style": ["error", {
"multiline": {
"delimiter": "none",
"requireLast": false
},
"singleline": {
"delimiter": "comma",
"requireLast": false
}
}],
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-regexp-exec": "error"
}
}