@houheaven/eslint-config-helper 1.4.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +149 -28
- package/lib/format-es5.js +23 -0
- package/lib/format-es6.js +25 -0
- package/lib/format-html.js +23 -0
- package/lib/format-import.js +23 -0
- package/lib/format-typescript.js +28 -0
- package/lib/format-vue2.js +23 -0
- package/lib/format-vue3.js +23 -0
- package/lib/html.js +13 -22
- package/lib/import.js +23 -0
- package/lib/javascript-es5.js +23 -0
- package/lib/javascript-es6.js +25 -0
- package/lib/rules/eslint/_deprecated.js +132 -0
- package/lib/rules/eslint/_removed.js +25 -0
- package/lib/rules/eslint/es6.js +279 -110
- package/lib/rules/eslint/layout-formatting.js +441 -0
- package/lib/rules/eslint/possible-errors.js +140 -131
- package/lib/rules/eslint/suggestions.js +666 -0
- package/lib/rules/html/accessibility.js +47 -23
- package/lib/rules/html/best-practice.js +122 -36
- package/lib/rules/html/seo.js +16 -11
- package/lib/rules/html/style.js +53 -15
- package/lib/rules/import/helpful-warnings.js +23 -18
- package/lib/rules/import/module-systems.js +16 -17
- package/lib/rules/import/static-analysis.js +54 -38
- package/lib/rules/import/style-guide.js +89 -61
- package/lib/rules/typescript/_deprecated.js +57 -0
- package/lib/rules/typescript/conflict.js +16 -0
- package/lib/rules/typescript/deprecated.js +41 -0
- package/lib/rules/typescript/extension.js +207 -0
- package/lib/rules/typescript/fixable.js +215 -0
- package/lib/rules/typescript/other.js +125 -0
- package/lib/rules/typescript/stylistic.js +34 -0
- package/lib/rules/typescript/suggestion.js +53 -0
- package/lib/rules/typescript/type-checked.js +263 -0
- package/lib/rules/vue/_deprecated.js +37 -0
- package/lib/rules/vue/common-base.js +1 -11
- package/lib/rules/vue/common-essential.js +25 -38
- package/lib/rules/vue/common-extension.js +321 -0
- package/lib/rules/vue/common-recommended.js +64 -31
- package/lib/rules/vue/common-strongly-recommended.js +37 -20
- package/lib/rules/vue/{common-extra.js → common-uncategorized.js} +141 -52
- package/lib/rules/vue/vue2-essential.js +16 -14
- package/lib/rules/vue/vue2-uncategorized.js +15 -0
- package/lib/rules/vue/vue3-essential.js +54 -24
- package/lib/rules/vue/vue3-strongly-recommended.js +8 -10
- package/lib/rules/vue/vue3-uncategorized.js +115 -0
- package/lib/support/es5-support.js +29 -0
- package/lib/support/es6-support.js +39 -0
- package/lib/support/html-support.js +38 -0
- package/lib/support/import-bugfix.js +65 -0
- package/lib/support/import-support.js +25 -0
- package/lib/support/typescript-support.js +27 -0
- package/lib/support/vue2-support.js +43 -0
- package/lib/support/vue3-support.js +43 -0
- package/lib/support/vue3-ts-support.js +51 -0
- package/lib/typescript.js +24 -32
- package/lib/utils/utils.js +160 -0
- package/lib/vue2.js +16 -22
- package/lib/vue3-ts.js +31 -0
- package/lib/vue3.js +13 -17
- package/package.json +38 -22
- package/lib/configs/eslint-es5.js +0 -24
- package/lib/configs/eslint.js +0 -23
- package/lib/configs/format-html.js +0 -22
- package/lib/configs/format-js.js +0 -134
- package/lib/configs/format-vue.js +0 -278
- package/lib/configs/html.js +0 -20
- package/lib/configs/import-bugfix.js +0 -36
- package/lib/configs/import.js +0 -44
- package/lib/configs/typescript.js +0 -10
- package/lib/configs/vue2.js +0 -28
- package/lib/configs/vue3.js +0 -28
- package/lib/eslint.js +0 -18
- package/lib/format.js +0 -40
- package/lib/rules/eslint/best-practices.js +0 -422
- package/lib/rules/eslint/node.js +0 -48
- package/lib/rules/eslint/strict-mode.js +0 -12
- package/lib/rules/eslint/stylistic-issues.js +0 -578
- package/lib/rules/eslint/variables.js +0 -73
- package/lib/rules/typescript/all.js +0 -193
- package/lib/rules/typescript/base.js +0 -10
- package/lib/rules/typescript/eslint-recommended.js +0 -36
- package/lib/rules/typescript/recommended-requiring-type-checking.js +0 -26
- package/lib/rules/typescript/recommended.js +0 -36
- package/lib/rules/typescript/strict.js +0 -47
- package/lib/rules/vue/common-eslint.js +0 -220
- package/lib/rules/vue/vue2-recommended.js +0 -17
- package/lib/rules/vue/vue2-strongly-recommended.js +0 -16
- package/lib/rules/vue/vue3-recommended.js +0 -17
|
@@ -5,75 +5,61 @@
|
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
7
|
rules: {
|
|
8
|
-
//
|
|
9
|
-
// https://github.com/
|
|
10
|
-
"import/
|
|
8
|
+
// 一致的导入类型指定符样式
|
|
9
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/consistent-type-specifier-style.md
|
|
10
|
+
"import/consistent-type-specifier-style": ["warn", "prefer-top-level"],
|
|
11
11
|
|
|
12
|
-
//
|
|
13
|
-
// https://github.com/
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
// 动态导入时要求携带 webpackChunkName 注释
|
|
13
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/dynamic-import-chunkname.md
|
|
14
|
+
"import/dynamic-import-chunkname": ["error", {
|
|
15
|
+
importFunctions: [],
|
|
16
|
+
webpackChunknameFormat: "[0-9a-zA-Z-_/.]+",
|
|
17
|
+
allowEmpty: true,
|
|
18
|
+
}],
|
|
16
19
|
|
|
17
20
|
// export 要放在文件最后面
|
|
18
|
-
// https://github.com/
|
|
19
|
-
"import/exports-last": "
|
|
20
|
-
|
|
21
|
-
// 禁止在多个地方重复导入同一模块
|
|
22
|
-
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
|
|
23
|
-
"import/no-duplicates": "off",
|
|
24
|
-
|
|
25
|
-
// 禁止命名空间(又名“通配符” *)导入
|
|
26
|
-
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-namespace.md
|
|
27
|
-
"import/no-namespace": "warn",
|
|
21
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/exports-last.md
|
|
22
|
+
"import/exports-last": "error",
|
|
28
23
|
|
|
29
24
|
// 文件后缀名
|
|
30
|
-
// https://github.com/
|
|
31
|
-
"import/extensions": ["
|
|
25
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/extensions.md
|
|
26
|
+
"import/extensions": ["error", "always", {
|
|
32
27
|
ignorePackages: true,
|
|
28
|
+
pattern: {
|
|
29
|
+
ts: "never",
|
|
30
|
+
},
|
|
33
31
|
}],
|
|
34
32
|
|
|
35
|
-
// import
|
|
36
|
-
// https://github.com/
|
|
37
|
-
"import/
|
|
38
|
-
groups: [
|
|
39
|
-
"builtin",
|
|
40
|
-
["external", "internal"],
|
|
41
|
-
],
|
|
42
|
-
}],
|
|
33
|
+
// import 要放在文件最前面
|
|
34
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/first.md
|
|
35
|
+
"import/first": "warn",
|
|
43
36
|
|
|
44
|
-
//
|
|
45
|
-
// https://github.com/
|
|
46
|
-
"import/
|
|
37
|
+
// 一个文件中保留一个导出出口(易辨识、易维护)
|
|
38
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/group-exports.md
|
|
39
|
+
"import/group-exports": "error",
|
|
47
40
|
|
|
48
|
-
//
|
|
49
|
-
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/
|
|
50
|
-
|
|
41
|
+
// import 要放在文件最前面(已废弃)
|
|
42
|
+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/imports-first.md
|
|
43
|
+
// deprecated: use `import/first`
|
|
44
|
+
// "import/imports-first": "off",
|
|
51
45
|
|
|
52
46
|
// 禁止模块有太多的依赖
|
|
53
|
-
// https://github.com/
|
|
54
|
-
"import/max-dependencies": ["off", {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unassigned-import.md
|
|
58
|
-
// importing for side effects is perfectly acceptable, if you need side effects.
|
|
59
|
-
"import/no-unassigned-import": ["error", {
|
|
60
|
-
allow: ["**/*.css", "**/*.less", "echarts/**/*.*"],
|
|
47
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/max-dependencies.md
|
|
48
|
+
"import/max-dependencies": ["off", {
|
|
49
|
+
max: 10,
|
|
50
|
+
ignoreTypeImports: true,
|
|
61
51
|
}],
|
|
62
52
|
|
|
63
|
-
// import
|
|
64
|
-
// https://github.com/
|
|
65
|
-
"import/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
// 禁止命名导出
|
|
72
|
-
// https://github.com/benmosher/eslint-plugin-import/blob/1ec80fa35fa1819e2d35a70e68fb6a149fb57c5e/docs/rules/no-named-export.md
|
|
73
|
-
"import/no-named-export": "off",
|
|
53
|
+
// 强制在最后一个顶级导入 import 语句或 require 调用之后有一个或多个空行
|
|
54
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/newline-after-import.md
|
|
55
|
+
"import/newline-after-import": ["off", {
|
|
56
|
+
count: 1,
|
|
57
|
+
exactCount: true,
|
|
58
|
+
considerComments: false,
|
|
59
|
+
}],
|
|
74
60
|
|
|
75
61
|
// 要求默认导出的值必须先定义
|
|
76
|
-
// https://github.com/
|
|
62
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-anonymous-default-export.md
|
|
77
63
|
"import/no-anonymous-default-export": ["off", {
|
|
78
64
|
allowArray: false,
|
|
79
65
|
allowArrowFunction: false,
|
|
@@ -83,15 +69,57 @@ module.exports = {
|
|
|
83
69
|
allowObject: false,
|
|
84
70
|
}],
|
|
85
71
|
|
|
86
|
-
//
|
|
87
|
-
// https://github.com/
|
|
88
|
-
"import/
|
|
72
|
+
// 禁止默认导出
|
|
73
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-default-export.md
|
|
74
|
+
"import/no-default-export": "off",
|
|
89
75
|
|
|
90
|
-
//
|
|
91
|
-
// https://github.com/
|
|
92
|
-
"import/
|
|
93
|
-
|
|
94
|
-
|
|
76
|
+
// 禁止在多个地方重复导入同一模块
|
|
77
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-duplicates.md
|
|
78
|
+
"import/no-duplicates": ["warn", {
|
|
79
|
+
"considerQueryString": true,
|
|
80
|
+
"prefer-inline": false,
|
|
81
|
+
}],
|
|
82
|
+
|
|
83
|
+
// import 时不能使用 default 关键字
|
|
84
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-named-default.md
|
|
85
|
+
"import/no-named-default": "error",
|
|
86
|
+
|
|
87
|
+
// 禁止命名导出
|
|
88
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-named-export.md
|
|
89
|
+
"import/no-named-export": "off",
|
|
90
|
+
|
|
91
|
+
// 禁止命名空间(又名“通配符” *)导入
|
|
92
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-namespace.md
|
|
93
|
+
"import/no-namespace": "warn",
|
|
94
|
+
|
|
95
|
+
// 禁止未分配的导入
|
|
96
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-unassigned-import.md
|
|
97
|
+
// importing for side effects is perfectly acceptable, if you need side effects.
|
|
98
|
+
"import/no-unassigned-import": ["error", {
|
|
99
|
+
allow: [
|
|
100
|
+
"**/*.css",
|
|
101
|
+
"**/*.less",
|
|
102
|
+
"**/*.styl",
|
|
103
|
+
"echarts/**/*.*",
|
|
104
|
+
],
|
|
105
|
+
}],
|
|
106
|
+
|
|
107
|
+
// import 导入排序
|
|
108
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/order.md
|
|
109
|
+
"import/order": ["warn", {
|
|
110
|
+
groups: [
|
|
111
|
+
"builtin",
|
|
112
|
+
["external", "internal"],
|
|
113
|
+
// "parent",
|
|
114
|
+
// "sibling",
|
|
115
|
+
// "index",
|
|
116
|
+
// "object",
|
|
117
|
+
// "type",
|
|
118
|
+
],
|
|
95
119
|
}],
|
|
120
|
+
|
|
121
|
+
// 当一个模块只有一个导出时,更喜欢使用默认导出而不是命名导出
|
|
122
|
+
// https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/prefer-default-export.md
|
|
123
|
+
"import/prefer-default-export": "error",
|
|
96
124
|
},
|
|
97
125
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
|
|
2
|
+
module.exports = {
|
|
3
|
+
rules: {
|
|
4
|
+
// 禁止使用 var 导入
|
|
5
|
+
// 替换为 "@typescript-eslint/no-require-imports"
|
|
6
|
+
// https://typescript-eslint.io/rules/no-var-requires
|
|
7
|
+
"@typescript-eslint/no-var-requires": ["error", {
|
|
8
|
+
allow: [],
|
|
9
|
+
}],
|
|
10
|
+
|
|
11
|
+
// 推荐使用 TS 期望错误
|
|
12
|
+
// https://typescript-eslint.io/rules/prefer-ts-expect-error
|
|
13
|
+
"@typescript-eslint/prefer-ts-expect-error": "off",
|
|
14
|
+
|
|
15
|
+
// 排序类型组成部分
|
|
16
|
+
// 取而代之:
|
|
17
|
+
// - perfectionist/sort-intersection-types
|
|
18
|
+
// - perfectionist/sort-union-types
|
|
19
|
+
// https://typescript-eslint.io/rules/sort-type-constituents
|
|
20
|
+
"@typescript-eslint/sort-type-constituents": "off",
|
|
21
|
+
|
|
22
|
+
// 禁止使用某些类型
|
|
23
|
+
// 移除:typescript-eslint v8
|
|
24
|
+
// 替换为
|
|
25
|
+
// - "@typescript-eslint/no-empty-object-type"
|
|
26
|
+
// - "@typescript-eslint/no-unsafe-function-type"
|
|
27
|
+
// - "@typescript-eslint/no-wrapper-object-types"
|
|
28
|
+
// https://typescript-eslint.io/rules/ban-types
|
|
29
|
+
"@typescript-eslint/ban-types": "error",
|
|
30
|
+
|
|
31
|
+
// TypeScript ESLint 宣布弃用所有格式化规则(如缩进、空格、分号等),并推荐用户迁移至 ESLint Stylistic 项目。
|
|
32
|
+
// 此举是响应 ESLint 核心团队对格式化规则的统一管理策略。
|
|
33
|
+
// - 2023 年 12 月 25 日发布的 v6.16.0 版本首次标记这些规则为“弃用”。
|
|
34
|
+
// - 当前版本(v6)仍保留规则功能,仅添加弃用提示(不影响现有项目)。
|
|
35
|
+
// - v7 版本(下一个主版本)将完全删除这些规则。
|
|
36
|
+
"@typescript-eslint/block-spacing": "off",
|
|
37
|
+
"@typescript-eslint/brace-style": "off",
|
|
38
|
+
"@typescript-eslint/comma-dangle": "off",
|
|
39
|
+
"@typescript-eslint/comma-spacing": "off",
|
|
40
|
+
"@typescript-eslint/func-call-spacing": "off",
|
|
41
|
+
"@typescript-eslint/indent": "off",
|
|
42
|
+
"@typescript-eslint/key-spacing": "off",
|
|
43
|
+
"@typescript-eslint/keyword-spacing": "off",
|
|
44
|
+
"@typescript-eslint/lines-around-comment": "off",
|
|
45
|
+
"@typescript-eslint/lines-between-class-members": "off",
|
|
46
|
+
"@typescript-eslint/member-delimiter-style": "off",
|
|
47
|
+
"@typescript-eslint/no-extra-parens": "off",
|
|
48
|
+
"@typescript-eslint/no-extra-semi": "off",
|
|
49
|
+
"@typescript-eslint/padding-line-between-statements": "off",
|
|
50
|
+
"@typescript-eslint/quotes": "off",
|
|
51
|
+
"@typescript-eslint/semi": "off",
|
|
52
|
+
"@typescript-eslint/space-before-blocks": "off",
|
|
53
|
+
"@typescript-eslint/space-before-function-paren": "off",
|
|
54
|
+
"@typescript-eslint/space-infix-ops": "off",
|
|
55
|
+
"@typescript-eslint/type-annotation-spacing": "off",
|
|
56
|
+
},
|
|
57
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
// ================================================================================
|
|
3
|
+
// Eslint 部分规则和 Typescript 检测存在冲突
|
|
4
|
+
// 比如:同一个报错引起 Typescript 报错,也会引起 Eslint 报错,导致重复报错,增加问题修复的成本
|
|
5
|
+
// ================================================================================
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
rules: {
|
|
9
|
+
// ts(2304)
|
|
10
|
+
"no-undef": "off",
|
|
11
|
+
// ts(2367)
|
|
12
|
+
"valid-typeof": "off",
|
|
13
|
+
// ts(2792)
|
|
14
|
+
"import/no-unresolved": "off",
|
|
15
|
+
},
|
|
16
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
module.exports = {
|
|
3
|
+
rules: {
|
|
4
|
+
// 禁止空接口
|
|
5
|
+
// https://typescript-eslint.io/rules/no-empty-interface
|
|
6
|
+
"@typescript-eslint/no-empty-interface": ["warn", {
|
|
7
|
+
allowSingleExtends: false,
|
|
8
|
+
}],
|
|
9
|
+
|
|
10
|
+
// 禁止失去精度的文字数字
|
|
11
|
+
// https://typescript-eslint.io/rules/no-loss-of-precision
|
|
12
|
+
"no-loss-of-precision": "off",
|
|
13
|
+
"@typescript-eslint/no-loss-of-precision": "error",
|
|
14
|
+
|
|
15
|
+
// 禁止使用类型别名
|
|
16
|
+
// https://typescript-eslint.io/rules/no-type-alias
|
|
17
|
+
"@typescript-eslint/no-type-alias": ["error", {
|
|
18
|
+
allowAliases: "in-unions",
|
|
19
|
+
allowCallbacks: "never",
|
|
20
|
+
allowConditionalTypes: "always",
|
|
21
|
+
allowConstructors: "always",
|
|
22
|
+
allowLiterals: "always",
|
|
23
|
+
allowMappedTypes: "always",
|
|
24
|
+
allowTupleTypes: "always",
|
|
25
|
+
allowGenerics: "always",
|
|
26
|
+
}],
|
|
27
|
+
|
|
28
|
+
// 要求在某些地方添加类型注解
|
|
29
|
+
// https://typescript-eslint.io/rules/typedef
|
|
30
|
+
"@typescript-eslint/typedef": ["error", {
|
|
31
|
+
arrayDestructuring: false,
|
|
32
|
+
arrowParameter: false,
|
|
33
|
+
memberVariableDeclaration: false,
|
|
34
|
+
objectDestructuring: false,
|
|
35
|
+
parameter: false,
|
|
36
|
+
propertyDeclaration: false,
|
|
37
|
+
variableDeclaration: false,
|
|
38
|
+
variableDeclarationIgnoreFunction: false,
|
|
39
|
+
}],
|
|
40
|
+
},
|
|
41
|
+
};
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
|
|
2
|
+
module.exports = {
|
|
3
|
+
rules: {
|
|
4
|
+
// 强制类方法使用 "this"
|
|
5
|
+
// https://typescript-eslint.io/rules/class-methods-use-this
|
|
6
|
+
// 注意:必须禁用基础规则,否则扩展规则会报告错误
|
|
7
|
+
"class-methods-use-this": "off",
|
|
8
|
+
"@typescript-eslint/class-methods-use-this": ["off", {
|
|
9
|
+
exceptMethods: [],
|
|
10
|
+
enforceForClassFields: false,
|
|
11
|
+
ignoreOverrideMethods: false,
|
|
12
|
+
ignoreClassesThatImplementAnInterface: false,
|
|
13
|
+
}],
|
|
14
|
+
|
|
15
|
+
// 要求返回语句要么始终指定值,要么从不指定值
|
|
16
|
+
// https://typescript-eslint.io/rules/consistent-return
|
|
17
|
+
"consistent-return": "off",
|
|
18
|
+
"@typescript-eslint/consistent-return": ["error", {
|
|
19
|
+
treatUndefinedAsUnspecified: true,
|
|
20
|
+
}],
|
|
21
|
+
|
|
22
|
+
// 强制默认参数放在最后
|
|
23
|
+
// https://typescript-eslint.io/rules/default-param-last
|
|
24
|
+
"default-param-last": "off",
|
|
25
|
+
"@typescript-eslint/default-param-last": "error",
|
|
26
|
+
|
|
27
|
+
// 尽可能的使用点符号
|
|
28
|
+
// 依赖:parserServices
|
|
29
|
+
// https://typescript-eslint.io/rules/dot-notation
|
|
30
|
+
"dot-notation": "off",
|
|
31
|
+
"@typescript-eslint/dot-notation": ["warn", {
|
|
32
|
+
allowKeywords: true,
|
|
33
|
+
allowPattern: "",
|
|
34
|
+
// TS 拓展项
|
|
35
|
+
allowPrivateClassPropertyAccess: false,
|
|
36
|
+
allowProtectedClassPropertyAccess: false,
|
|
37
|
+
allowIndexSignaturePropertyAccess: false,
|
|
38
|
+
}],
|
|
39
|
+
|
|
40
|
+
// 在变量声明时是否要初始化
|
|
41
|
+
// https://typescript-eslint.io/rules/init-declarations
|
|
42
|
+
"init-declarations": "off",
|
|
43
|
+
"@typescript-eslint/init-declarations": ["error", "always"],
|
|
44
|
+
|
|
45
|
+
// 强制规定了函数定义中参数的最大数量
|
|
46
|
+
// https://typescript-eslint.io/rules/max-params
|
|
47
|
+
"max-params": "off",
|
|
48
|
+
"@typescript-eslint/max-params": "off",
|
|
49
|
+
|
|
50
|
+
// 不允许使用数组构造函数
|
|
51
|
+
// https://typescript-eslint.io/rules/no-array-constructor
|
|
52
|
+
"no-array-constructor": "off",
|
|
53
|
+
"@typescript-eslint/no-array-constructor": "warn",
|
|
54
|
+
|
|
55
|
+
// 禁止类的成员(方法、属性)名称重复
|
|
56
|
+
// https://typescript-eslint.io/rules/no-dupe-class-members
|
|
57
|
+
"no-dupe-class-members": "off",
|
|
58
|
+
"@typescript-eslint/no-dupe-class-members": "error",
|
|
59
|
+
|
|
60
|
+
// 禁止空函数
|
|
61
|
+
// https://typescript-eslint.io/rules/no-empty-function
|
|
62
|
+
"no-empty-function": "off",
|
|
63
|
+
"@typescript-eslint/no-empty-function": ["error", {
|
|
64
|
+
allow: [
|
|
65
|
+
// "functions", // 普通函数
|
|
66
|
+
// "arrowFunctions", // 箭头函数
|
|
67
|
+
// "generatorFunctions", // 生成器函数
|
|
68
|
+
// "methods", // 类的方法和对象字面的方法缩写
|
|
69
|
+
// "generatorMethods", // 带有生成器的对象字面的类方法和方法速记
|
|
70
|
+
// "getters", // 获取器
|
|
71
|
+
// "setters", // 设置器
|
|
72
|
+
// "constructors", // 类的构造函数
|
|
73
|
+
// "asyncFunctions", // 异步函数
|
|
74
|
+
// "asyncMethods", // 异步类方法和对象字面的方法缩写
|
|
75
|
+
// TS 拓展项
|
|
76
|
+
// "private-constructors", // 私有构造函数
|
|
77
|
+
// "protected-constructors", // 受保护的构造函数
|
|
78
|
+
// "decoratedFunctions", // 装饰器函数
|
|
79
|
+
// "overrideMethods", // 重写方法
|
|
80
|
+
],
|
|
81
|
+
}],
|
|
82
|
+
|
|
83
|
+
// 禁止使用 eval() 等方法
|
|
84
|
+
// 依赖:parserServices
|
|
85
|
+
// https://typescript-eslint.io/rules/no-implied-eval
|
|
86
|
+
"no-implied-eval": "off",
|
|
87
|
+
"@typescript-eslint/no-implied-eval": "error",
|
|
88
|
+
|
|
89
|
+
// 禁止在全局作用域中使用 this
|
|
90
|
+
// https://typescript-eslint.io/rules/no-invalid-this
|
|
91
|
+
"no-invalid-this": "off",
|
|
92
|
+
"@typescript-eslint/no-invalid-this": "error",
|
|
93
|
+
|
|
94
|
+
// 不允许在循环语句中包含不安全引用的函数声明
|
|
95
|
+
// https://typescript-eslint.io/rules/no-loop-func
|
|
96
|
+
"no-loop-func": "off",
|
|
97
|
+
"@typescript-eslint/no-loop-func": "error",
|
|
98
|
+
|
|
99
|
+
// 禁止使用“魔数”
|
|
100
|
+
// “魔数“是在代码中多次出现的数字,没有明确的含义,它们最好被命名的常量所取代
|
|
101
|
+
// https://typescript-eslint.io/rules/no-magic-numbers
|
|
102
|
+
"no-magic-numbers": "off",
|
|
103
|
+
"@typescript-eslint/no-magic-numbers": "off",
|
|
104
|
+
|
|
105
|
+
// 禁止重复声明变量
|
|
106
|
+
// https://typescript-eslint.io/rules/no-redeclare
|
|
107
|
+
"no-redeclare": "off",
|
|
108
|
+
"@typescript-eslint/no-redeclare": ["error", {
|
|
109
|
+
builtinGlobals: true,
|
|
110
|
+
// TS 拓展项
|
|
111
|
+
ignoreDeclarationMerge: true,
|
|
112
|
+
}],
|
|
113
|
+
|
|
114
|
+
// 禁止 imports 导入指定的模块
|
|
115
|
+
// https://typescript-eslint.io/rules/no-restricted-imports
|
|
116
|
+
"no-restricted-imports": "off",
|
|
117
|
+
"@typescript-eslint/no-restricted-imports": "off",
|
|
118
|
+
|
|
119
|
+
// 禁止变量声明掩盖在外部作用域中声明的变量
|
|
120
|
+
// https://typescript-eslint.io/rules/no-shadow
|
|
121
|
+
"no-shadow": "off",
|
|
122
|
+
"@typescript-eslint/no-shadow": ["error", {
|
|
123
|
+
builtinGlobals: true,
|
|
124
|
+
hoist: "all",
|
|
125
|
+
allow: ["name"],
|
|
126
|
+
ignoreOnInitialization: true,
|
|
127
|
+
// TS 拓展项
|
|
128
|
+
ignoreTypeValueShadow: true,
|
|
129
|
+
ignoreFunctionTypeParameterNameValueShadow: true,
|
|
130
|
+
}],
|
|
131
|
+
|
|
132
|
+
// 禁止未使用的表达式
|
|
133
|
+
// https://typescript-eslint.io/rules/no-unused-expressions
|
|
134
|
+
"no-unused-expressions": "off",
|
|
135
|
+
"@typescript-eslint/no-unused-expressions": ["error", {
|
|
136
|
+
allowShortCircuit: true,
|
|
137
|
+
allowTernary: true,
|
|
138
|
+
allowTaggedTemplates: false,
|
|
139
|
+
enforceForJSX: true,
|
|
140
|
+
// ignoreDirectives: true,
|
|
141
|
+
}],
|
|
142
|
+
|
|
143
|
+
// 不允许 Class 存在未使用的私有成员(属性、方法)
|
|
144
|
+
// https://typescript-eslint.io/rules/no-unused-private-class-members
|
|
145
|
+
"no-unused-private-class-members": "off",
|
|
146
|
+
"@typescript-eslint/no-unused-private-class-members": "error",
|
|
147
|
+
|
|
148
|
+
// 不允许未使用的变量
|
|
149
|
+
// https://typescript-eslint.io/rules/no-unused-vars
|
|
150
|
+
"no-unused-vars": "off",
|
|
151
|
+
"@typescript-eslint/no-unused-vars": ["error", {
|
|
152
|
+
vars: "all",
|
|
153
|
+
varsIgnorePattern: "",
|
|
154
|
+
args: "after-used", // 参数相关
|
|
155
|
+
argsIgnorePattern: "^_|^(evt|err)\\d*$|^(resolve|reject)$", // 指定了不检查使用情况的例外情况:参数的名称与 regexp 模式相匹配。例如,名称以下划线开头的变量。
|
|
156
|
+
caughtErrors: "none",
|
|
157
|
+
caughtErrorsIgnorePattern: "^_|^(e|err|error)\\d*$", // try-catch 代码块
|
|
158
|
+
destructuredArrayIgnorePattern: "", // 数组解构相关
|
|
159
|
+
ignoreRestSiblings: true,
|
|
160
|
+
}],
|
|
161
|
+
|
|
162
|
+
// 禁止定义前使用
|
|
163
|
+
// https://typescript-eslint.io/rules/no-use-before-define
|
|
164
|
+
"no-use-before-define": "off",
|
|
165
|
+
"@typescript-eslint/no-use-before-define": ["error", {
|
|
166
|
+
functions: false,
|
|
167
|
+
classes: true,
|
|
168
|
+
variables: true,
|
|
169
|
+
allowNamedExports: false,
|
|
170
|
+
// TS 拓展项
|
|
171
|
+
enums: true,
|
|
172
|
+
typedefs: true,
|
|
173
|
+
ignoreTypeReferences: true,
|
|
174
|
+
}],
|
|
175
|
+
|
|
176
|
+
// 禁止无用的构造函数
|
|
177
|
+
// https://typescript-eslint.io/rules/no-useless-constructor
|
|
178
|
+
"no-useless-constructor": "off",
|
|
179
|
+
"@typescript-eslint/no-useless-constructor": "error",
|
|
180
|
+
|
|
181
|
+
// 禁止抛出原始值
|
|
182
|
+
// https://typescript-eslint.io/rules/only-throw-error
|
|
183
|
+
"no-throw-literal": "off",
|
|
184
|
+
"@typescript-eslint/only-throw-error": "error",
|
|
185
|
+
|
|
186
|
+
// 优先使用数组和对象解构
|
|
187
|
+
// https://typescript-eslint.io/rules/prefer-destructuring
|
|
188
|
+
"prefer-destructuring": "off",
|
|
189
|
+
"@typescript-eslint/prefer-destructuring": "off",
|
|
190
|
+
|
|
191
|
+
// 要求使用 Error 对象作为 Promise 拒绝的原因
|
|
192
|
+
// https://typescript-eslint.io/rules/prefer-promise-reject-errors
|
|
193
|
+
"prefer-promise-reject-errors": "off",
|
|
194
|
+
"@typescript-eslint/prefer-promise-reject-errors": ["error", {
|
|
195
|
+
allowEmptyReject: true,
|
|
196
|
+
// TS 拓展项
|
|
197
|
+
allowThrowingAny: false,
|
|
198
|
+
allowThrowingUnknown: false,
|
|
199
|
+
}],
|
|
200
|
+
|
|
201
|
+
// 要求 async 函数中含有 await 表达式
|
|
202
|
+
// 依赖:parserServices
|
|
203
|
+
// https://typescript-eslint.io/rules/require-await
|
|
204
|
+
"require-await": "off",
|
|
205
|
+
"@typescript-eslint/require-await": "error",
|
|
206
|
+
},
|
|
207
|
+
};
|