/
.eslintrc.json
executable file
·68 lines (68 loc) · 2.79 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
{
"env": {
"browser": true,
"es6": true
},
"plugins": ["@typescript-eslint", "prettier"],
"extends": [
// 启用 `prettier` 基础设置,不要使用 `plugin:prettier/recommended` 的推荐设置,会与以下冲突
"prettier",
// 启用 `eslint` 默认检查项
"eslint:recommended",
// 启用 `eslint` 默认检查项(如果文件经过 typescript 编译的话)
"plugin:@typescript-eslint/eslint-recommended",
// 启用 `eslint` 默认检查项(如果文件经过 typescript 编译的话)
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"rules": {
// ✅ 启用格式化验证,这里只进行警告,警告是会被 --fix 修复的,请勿使用 error,不然写代码时会有红色波浪线提示错误
"prettier/prettier": "warn",
// ✅ 允许空格与 `tab` 一起混用,必须是 `off`,因为 `prettier` 会格式化,所以不存在该情况
"no-mixed-spaces-and-tabs": "off",
// ✅ 允许多个无用行,必须是 `off`,因为 `prettier` 会格式化,所以不存在该情况
"no-unexpected-multiline": "off",
// ✅ 允许连续的 `case` 语句,即可以缺少 `break`
"no-fallthrough": "off",
// ❌ 不允许使用 `undefined`
"no-undefined": "error",
// ✅ 允许常量判断条件
"no-constant-condition": "off",
// ❌ 不允许简写箭头函数: `a => 123;` -> `a => { return 123; }`
"arrow-body-style": "off",
// ⚠️ 不允许没有 `yield` 的 `generator` 函数
"require-yield": "warn",
// ✅ 允许无用的分号,必须是 `off`,因为 `prettier` 会格式化,所以不存在该情况
"@typescript-eslint/no-extra-semi": "off",
// ✅ 允许空函数
"@typescript-eslint/no-empty-function": "off",
// ❌ 不允许代码上下文中重复定义变量名
"@typescript-eslint/no-shadow": "error",
// ⚠️ 不允许未使用的变量
"@typescript-eslint/no-unused-vars": ["warn", { "ignoreRestSiblings": true, "caughtErrors": "none" }],
// ✅ 允许空的 `interface`,便于 `interface A extends B {}` 的写法
"@typescript-eslint/no-empty-interface": "off",
// ❌ 不允许函数没有返回类型: `() => {}` -> `(): void => {}`
"@typescript-eslint/explicit-function-return-type": [
"error",
{
"allowTypedFunctionExpressions": false,
"allowDirectConstAssertionInArrowFunctions": false,
"allowHigherOrderFunctions": false
}
],
// ❌ 不允许 `any`
"@typescript-eslint/no-explicit-any": "error"
},
"overrides": [
{
"files": ["**.test.{t,j}s{x,}"],
"plugins": ["jest"],
"extends": ["plugin:jest/recommended"]
}
]
}