@houheaven/eslint-config-helper 1.4.0 → 2.1.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.
Files changed (104) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +149 -28
  3. package/lib/format-es5.js +23 -0
  4. package/lib/format-es6.js +25 -0
  5. package/lib/format-html.js +23 -0
  6. package/lib/format-import.js +23 -0
  7. package/lib/format-typescript.js +28 -0
  8. package/lib/format-vue2.js +23 -0
  9. package/lib/format-vue3.js +23 -0
  10. package/lib/html.js +16 -22
  11. package/lib/import.js +26 -0
  12. package/lib/javascript-es5.js +25 -0
  13. package/lib/javascript-es6.js +28 -0
  14. package/lib/support/es5-support.js +29 -0
  15. package/lib/support/es6-support.js +39 -0
  16. package/lib/support/html-support.js +38 -0
  17. package/lib/support/import-bugfix.js +65 -0
  18. package/lib/support/import-support.js +25 -0
  19. package/lib/support/typescript-support.js +27 -0
  20. package/lib/support/vue2-support.js +43 -0
  21. package/lib/support/vue3-support.js +43 -0
  22. package/lib/support/vue3-ts-support.js +51 -0
  23. package/lib/typescript.js +27 -32
  24. package/lib/utils/utils.js +2 -0
  25. package/lib/vue2.js +19 -22
  26. package/lib/vue3-ts.js +32 -0
  27. package/lib/vue3.js +16 -17
  28. package/node_modules/@houheaven/eslint-config-helper-core/package.json +7 -0
  29. package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/_deprecated.js +132 -0
  30. package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/_removed.js +25 -0
  31. package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/es6.js +365 -0
  32. package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/layout-formatting.js +441 -0
  33. package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/possible-errors.js +199 -0
  34. package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/suggestions.js +666 -0
  35. package/node_modules/@houheaven/eslint-config-helper-core/rules/html/accessibility.js +68 -0
  36. package/node_modules/@houheaven/eslint-config-helper-core/rules/html/best-practice.js +150 -0
  37. package/node_modules/@houheaven/eslint-config-helper-core/rules/html/seo.js +29 -0
  38. package/node_modules/@houheaven/eslint-config-helper-core/rules/html/style.js +70 -0
  39. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/import/helpful-warnings.js +23 -18
  40. package/node_modules/@houheaven/eslint-config-helper-core/rules/import/module-systems.js +33 -0
  41. package/node_modules/@houheaven/eslint-config-helper-core/rules/import/static-analysis.js +85 -0
  42. package/node_modules/@houheaven/eslint-config-helper-core/rules/import/style-guide.js +125 -0
  43. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/_deprecated.js +57 -0
  44. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/conflict.js +16 -0
  45. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/deprecated.js +41 -0
  46. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/extension.js +207 -0
  47. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/fixable.js +215 -0
  48. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/other.js +125 -0
  49. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/stylistic.js +34 -0
  50. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/suggestion.js +53 -0
  51. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/type-checked.js +263 -0
  52. package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/_deprecated.js +37 -0
  53. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-base.js +1 -11
  54. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-essential.js +25 -38
  55. package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/common-extension.js +321 -0
  56. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-recommended.js +64 -31
  57. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-strongly-recommended.js +37 -20
  58. package/{lib/rules/vue/common-extra.js → node_modules/@houheaven/eslint-config-helper-core/rules/vue/common-uncategorized.js} +141 -52
  59. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue2-essential.js +16 -14
  60. package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/vue2-uncategorized.js +15 -0
  61. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue3-essential.js +54 -24
  62. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue3-strongly-recommended.js +8 -10
  63. package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/vue3-uncategorized.js +115 -0
  64. package/node_modules/@houheaven/eslint-config-helper-core/summary.js +57 -0
  65. package/node_modules/@houheaven/eslint-config-helper-core/utils/utils.js +160 -0
  66. package/package.json +59 -25
  67. package/lib/configs/eslint-es5.js +0 -24
  68. package/lib/configs/eslint.js +0 -23
  69. package/lib/configs/format-html.js +0 -22
  70. package/lib/configs/format-js.js +0 -134
  71. package/lib/configs/format-vue.js +0 -278
  72. package/lib/configs/html.js +0 -20
  73. package/lib/configs/import-bugfix.js +0 -36
  74. package/lib/configs/import.js +0 -44
  75. package/lib/configs/typescript.js +0 -10
  76. package/lib/configs/vue2.js +0 -28
  77. package/lib/configs/vue3.js +0 -28
  78. package/lib/eslint.js +0 -18
  79. package/lib/format.js +0 -40
  80. package/lib/rules/eslint/best-practices.js +0 -422
  81. package/lib/rules/eslint/es6.js +0 -196
  82. package/lib/rules/eslint/node.js +0 -48
  83. package/lib/rules/eslint/possible-errors.js +0 -190
  84. package/lib/rules/eslint/strict-mode.js +0 -12
  85. package/lib/rules/eslint/stylistic-issues.js +0 -578
  86. package/lib/rules/eslint/variables.js +0 -73
  87. package/lib/rules/html/accessibility.js +0 -44
  88. package/lib/rules/html/best-practice.js +0 -64
  89. package/lib/rules/html/seo.js +0 -24
  90. package/lib/rules/html/style.js +0 -32
  91. package/lib/rules/import/module-systems.js +0 -34
  92. package/lib/rules/import/static-analysis.js +0 -69
  93. package/lib/rules/import/style-guide.js +0 -97
  94. package/lib/rules/typescript/all.js +0 -193
  95. package/lib/rules/typescript/base.js +0 -10
  96. package/lib/rules/typescript/eslint-recommended.js +0 -36
  97. package/lib/rules/typescript/recommended-requiring-type-checking.js +0 -26
  98. package/lib/rules/typescript/recommended.js +0 -36
  99. package/lib/rules/typescript/strict.js +0 -47
  100. package/lib/rules/vue/common-eslint.js +0 -220
  101. package/lib/rules/vue/vue2-recommended.js +0 -17
  102. package/lib/rules/vue/vue2-strongly-recommended.js +0 -16
  103. package/lib/rules/vue/vue3-recommended.js +0 -17
  104. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vuejs-accessibility/index.js +0 -0
@@ -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
+ };
@@ -0,0 +1,215 @@
1
+
2
+ module.exports = {
3
+ rules: {
4
+ // 规范数组的类型注释方式 T[] 或 Array<T>
5
+ // https://typescript-eslint.io/rules/array-type
6
+ "@typescript-eslint/array-type": ["warn", {
7
+ default: "array",
8
+ readonly: "array",
9
+ }],
10
+
11
+ // 禁止使用 tslint 注释
12
+ // https://typescript-eslint.io/rules/ban-tslint-comment
13
+ "@typescript-eslint/ban-tslint-comment": "warn",
14
+
15
+ // 一致的泛型构造函数类型
16
+ // https://typescript-eslint.io/rules/consistent-generic-constructors
17
+ "@typescript-eslint/consistent-generic-constructors": ["warn", "type-annotation"],
18
+
19
+ // 一致的索引对象类型
20
+ // https://typescript-eslint.io/rules/consistent-indexed-object-style
21
+ "@typescript-eslint/consistent-indexed-object-style": ["warn", "record"],
22
+
23
+ // 一致的类型断言风格
24
+ // https://typescript-eslint.io/rules/consistent-type-assertions
25
+ "@typescript-eslint/consistent-type-assertions": ["error", {
26
+ // assertionStyle: "never",
27
+ assertionStyle: "as",
28
+ objectLiteralTypeAssertions: "allow-as-parameter",
29
+ arrayLiteralTypeAssertions: "allow-as-parameter",
30
+ }],
31
+
32
+ // 一致的类型定义风格
33
+ // https://typescript-eslint.io/rules/consistent-type-definitions
34
+ "@typescript-eslint/consistent-type-definitions": ["warn", "interface"],
35
+
36
+ // 一致的类型导出风格
37
+ // 依赖:parserServices
38
+ // https://typescript-eslint.io/rules/consistent-type-exports
39
+ "@typescript-eslint/consistent-type-exports": ["warn", {
40
+ fixMixedExportsWithInlineTypeSpecifier: false,
41
+ }],
42
+
43
+ // 一致的类型导入风格
44
+ // https://typescript-eslint.io/rules/consistent-type-imports
45
+ "@typescript-eslint/consistent-type-imports": ["warn", {
46
+ prefer: "type-imports",
47
+ fixStyle: "separate-type-imports",
48
+ disallowTypeAnnotations: true,
49
+ }],
50
+
51
+ // 一致的成员可访问性
52
+ // https://typescript-eslint.io/rules/explicit-member-accessibility
53
+ "@typescript-eslint/explicit-member-accessibility": "off",
54
+
55
+ // 一致的方法签名风格
56
+ // https://typescript-eslint.io/rules/method-signature-style
57
+ "@typescript-eslint/method-signature-style": ["warn", "property"],
58
+
59
+ // 禁止令人困惑的 void 表达式
60
+ // https://typescript-eslint.io/rules/no-confusing-void-expression
61
+ "@typescript-eslint/no-confusing-void-expression": ["warn", {
62
+ ignoreArrowShorthand: false,
63
+ ignoreVoidOperator: false,
64
+ ignoreVoidReturningFunctions: false,
65
+ }],
66
+
67
+ // 禁止重复的类型组成部分
68
+ // 依赖:parserServices
69
+ // https://typescript-eslint.io/rules/no-duplicate-type-constituents
70
+ "@typescript-eslint/no-duplicate-type-constituents": ["warn", {
71
+ ignoreIntersections: false,
72
+ ignoreUnions: false,
73
+ }],
74
+
75
+ // 禁止动态删除属性
76
+ // https://typescript-eslint.io/rules/no-dynamic-delete
77
+ "@typescript-eslint/no-dynamic-delete": "warn",
78
+
79
+ // 禁止显式 any 类型
80
+ // https://typescript-eslint.io/rules/no-explicit-any
81
+ "@typescript-eslint/no-explicit-any": ["error", {
82
+ fixToUnknown: false,
83
+ ignoreRestArgs: false,
84
+ }],
85
+
86
+ // 禁止额外的非空断言
87
+ // https://typescript-eslint.io/rules/no-extra-non-null-assertion
88
+ "@typescript-eslint/no-extra-non-null-assertion": "warn",
89
+
90
+ // 禁止导入类型副作用
91
+ // https://typescript-eslint.io/rules/no-import-type-side-effects
92
+ "@typescript-eslint/no-import-type-side-effects": "warn",
93
+
94
+ // 禁止可推断的类型
95
+ // https://typescript-eslint.io/rules/no-inferrable-types
96
+ "@typescript-eslint/no-inferrable-types": ["warn", {
97
+ ignoreParameters: false,
98
+ ignoreProperties: false,
99
+ }],
100
+
101
+ // 禁止无意义的 void 表达式
102
+ // 依赖:parserServices
103
+ // https://typescript-eslint.io/rules/no-meaningless-void-operator
104
+ "@typescript-eslint/no-meaningless-void-operator": ["warn", {
105
+ checkNever: false,
106
+ }],
107
+
108
+ // 禁止使用某些类型
109
+ // https://typescript-eslint.io/rules/no-restricted-types
110
+ "@typescript-eslint/no-restricted-types": "off",
111
+
112
+ // 禁止不必要的布尔值字面量比较
113
+ // https://typescript-eslint.io/rules/no-unnecessary-boolean-literal-compare
114
+ "@typescript-eslint/no-unnecessary-boolean-literal-compare": ["warn", {
115
+ allowComparingNullableBooleansToTrue: true,
116
+ allowComparingNullableBooleansToFalse: true,
117
+ }],
118
+
119
+ // 禁止不必要的类型限定符
120
+ // https://typescript-eslint.io/rules/no-unnecessary-qualifier
121
+ "@typescript-eslint/no-unnecessary-qualifier": "warn",
122
+
123
+ // 禁止不必要的模板表达式
124
+ // https://typescript-eslint.io/rules/no-unnecessary-template-expression
125
+ "@typescript-eslint/no-unnecessary-template-expression": "warn",
126
+
127
+ // 禁止不必要的类型参数
128
+ // https://typescript-eslint.io/rules/no-unnecessary-type-arguments
129
+ "@typescript-eslint/no-unnecessary-type-arguments": "warn",
130
+
131
+ // 禁止不必要的类型断言
132
+ // https://typescript-eslint.io/rules/no-unnecessary-type-assertion
133
+ "@typescript-eslint/no-unnecessary-type-assertion": "warn",
134
+
135
+ // 禁止无意义的空导出
136
+ // https://typescript-eslint.io/rules/no-useless-empty-export
137
+ "@typescript-eslint/no-useless-empty-export": "warn",
138
+
139
+ // 禁止包装对象类型
140
+ // https://typescript-eslint.io/rules/no-wrapper-object-types
141
+ "@typescript-eslint/no-wrapper-object-types": "warn",
142
+
143
+ // 非空类型断言风格
144
+ // https://typescript-eslint.io/rules/non-nullable-type-assertion-style
145
+ "@typescript-eslint/non-nullable-type-assertion-style": "warn",
146
+
147
+ // 推荐使用 as const 断言
148
+ // https://typescript-eslint.io/rules/prefer-as-const
149
+ "@typescript-eslint/prefer-as-const": "warn",
150
+
151
+ // 推荐使用函数类型而不是接口
152
+ // https://typescript-eslint.io/rules/prefer-function-type
153
+ "@typescript-eslint/prefer-function-type": "warn",
154
+
155
+ // 推荐使用 includes 而不是 indexOf
156
+ // https://typescript-eslint.io/rules/prefer-includes
157
+ "@typescript-eslint/prefer-includes": "warn",
158
+
159
+ // 推荐使用 namespace 而不是 module
160
+ // https://typescript-eslint.io/rules/prefer-namespace-keyword
161
+ "@typescript-eslint/prefer-namespace-keyword": "warn",
162
+
163
+ // 推荐使用可选链而不是短路表达式
164
+ // https://typescript-eslint.io/rules/prefer-optional-chain
165
+ "@typescript-eslint/prefer-optional-chain": ["warn", {
166
+ allowPotentiallyUnsafeFixesThatModifyTheReturnTypeIKnowWhatImDoing: false,
167
+ checkAny: true,
168
+ checkBigInt: true,
169
+ checkBoolean: true,
170
+ checkNumber: true,
171
+ checkString: true,
172
+ checkUnknown: true,
173
+ requireNullish: false,
174
+ }],
175
+
176
+ // 推荐使用只读类型
177
+ // https://typescript-eslint.io/rules/prefer-readonly
178
+ "@typescript-eslint/prefer-readonly": ["off", {
179
+ onlyInlineLambdas: false,
180
+ }],
181
+
182
+ // 推荐使用 reduce 类型参数
183
+ // https://typescript-eslint.io/rules/prefer-reduce-type-parameter
184
+ "@typescript-eslint/prefer-reduce-type-parameter": "warn",
185
+
186
+ // 推荐使用 RegExp.exec 而不是 String.match
187
+ // https://typescript-eslint.io/rules/prefer-regexp-exec
188
+ "@typescript-eslint/prefer-regexp-exec": "warn",
189
+
190
+ // 推荐使用返回 this 类型
191
+ // https://typescript-eslint.io/rules/prefer-return-this-type
192
+ "@typescript-eslint/prefer-return-this-type": "off",
193
+
194
+ // 推荐使用 startsWith 和 endsWith 方法
195
+ // https://typescript-eslint.io/rules/prefer-string-starts-ends-with
196
+ "@typescript-eslint/prefer-string-starts-ends-with": ["warn", {
197
+ allowSingleElementEquality: "never",
198
+ }],
199
+
200
+ // 推荐使用异步函数
201
+ // https://typescript-eslint.io/rules/promise-function-async
202
+ "@typescript-eslint/promise-function-async": ["warn", {
203
+ allowAny: true,
204
+ allowedPromiseNames: [],
205
+ checkArrowFunctions: true,
206
+ checkFunctionDeclarations: true,
207
+ checkFunctionExpressions: true,
208
+ checkMethodDeclarations: true,
209
+ }],
210
+
211
+ // 推荐返回 await
212
+ // https://typescript-eslint.io/rules/return-await
213
+ "@typescript-eslint/return-await": ["off", "in-try-catch"],
214
+ },
215
+ };
@@ -0,0 +1,125 @@
1
+
2
+ module.exports = {
3
+ rules: {
4
+ // 要求函数重载签名必须连续排列
5
+ // https://typescript-eslint.io/rules/adjacent-overload-signatures
6
+ "@typescript-eslint/adjacent-overload-signatures": "error",
7
+
8
+ // 要求函数返回类型
9
+ // https://typescript-eslint.io/rules/explicit-function-return-type
10
+ "@typescript-eslint/explicit-function-return-type": ["error", {
11
+ allowExpressions: false,
12
+ allowTypedFunctionExpressions: true,
13
+ allowHigherOrderFunctions: true,
14
+ allowDirectConstAssertionInArrowFunctions: true,
15
+ allowConciseArrowFunctionExpressionsStartingWithVoid: false,
16
+ allowFunctionsWithoutTypeParameters: false,
17
+ allowedNames: [],
18
+ allowIIFEs: false,
19
+ }],
20
+
21
+ // 要求模块边界的类型
22
+ // https://typescript-eslint.io/rules/explicit-module-boundary-types
23
+ "@typescript-eslint/explicit-module-boundary-types": ["error", {
24
+ allowArgumentsExplicitlyTypedAsAny: false,
25
+ allowDirectConstAssertionInArrowFunctions: true,
26
+ allowedNames: [],
27
+ allowHigherOrderFunctions: true,
28
+ allowTypedFunctionExpressions: true,
29
+ allowOverloadFunctions: false,
30
+ }],
31
+
32
+ // 要求成员排序
33
+ // https://typescript-eslint.io/rules/member-ordering
34
+ "@typescript-eslint/member-ordering": "off",
35
+
36
+ // 禁止重复的枚举值
37
+ // https://typescript-eslint.io/rules/no-duplicate-enum-values
38
+ "@typescript-eslint/no-duplicate-enum-values": "error",
39
+
40
+ // 禁止多余的类
41
+ // https://typescript-eslint.io/rules/no-extraneous-class
42
+ "@typescript-eslint/no-extraneous-class": ["error", {
43
+ allowConstructorOnly: false,
44
+ allowEmpty: false,
45
+ allowStaticOnly: false,
46
+ allowWithDecorator: false,
47
+ }],
48
+
49
+ // 禁止无效的 void 类型
50
+ // https://typescript-eslint.io/rules/no-invalid-void-type
51
+ "@typescript-eslint/no-invalid-void-type": ["error", {
52
+ allowInGenericTypeArguments: true,
53
+ allowAsThisParameter: false,
54
+ }],
55
+
56
+ // 禁止使用 new 操作符调用无参数构造函数
57
+ // https://typescript-eslint.io/rules/no-misused-new
58
+ "@typescript-eslint/no-misused-new": "error",
59
+
60
+ // 禁止使用 namespace 关键字
61
+ // https://typescript-eslint.io/rules/no-namespace
62
+ "@typescript-eslint/no-namespace": ["error", {
63
+ allowDeclarations: true,
64
+ allowDefinitionFiles: true,
65
+ }],
66
+
67
+ // 禁止使用 require 导入,推荐使用 import 语句
68
+ // https://typescript-eslint.io/rules/no-require-imports
69
+ "@typescript-eslint/no-require-imports": ["error", {
70
+ allow: [],
71
+ allowAsImport: false,
72
+ }],
73
+
74
+ // 禁止使用 this 别名
75
+ // https://typescript-eslint.io/rules/no-this-alias
76
+ "@typescript-eslint/no-this-alias": ["error", {
77
+ allowDestructuring: true,
78
+ allowedNames: [],
79
+ }],
80
+
81
+ // 禁止不必要的参数属性赋值
82
+ // https://typescript-eslint.io/rules/no-unnecessary-parameter-property-assignment
83
+ "@typescript-eslint/no-unnecessary-parameter-property-assignment": "error",
84
+
85
+ // 禁止不安全的声明合并
86
+ // https://typescript-eslint.io/rules/no-unsafe-declaration-merging
87
+ "@typescript-eslint/no-unsafe-declaration-merging": "error",
88
+
89
+ // 禁止使用不安全的函数类型
90
+ // https://typescript-eslint.io/rules/no-unsafe-function-type
91
+ "@typescript-eslint/no-unsafe-function-type": "error",
92
+
93
+ // 参数属性
94
+ // https://typescript-eslint.io/rules/parameter-properties
95
+ "@typescript-eslint/parameter-properties": ["error", {
96
+ allow: [],
97
+ prefer: "class-property",
98
+ }],
99
+
100
+ // 要求使用 for-of 循环
101
+ // https://typescript-eslint.io/rules/prefer-for-of
102
+ "@typescript-eslint/prefer-for-of": "error",
103
+
104
+ // 要求所有枚举成员均为字面量值
105
+ // https://typescript-eslint.io/rules/prefer-literal-enum-member
106
+ "@typescript-eslint/prefer-literal-enum-member": ["error", {
107
+ allowBitwiseExpressions: false,
108
+ }],
109
+
110
+ // 三斜线引用
111
+ // https://typescript-eslint.io/rules/triple-slash-reference
112
+ "@typescript-eslint/triple-slash-reference": ["error", {
113
+ lib: "always",
114
+ path: "never",
115
+ types: "prefer-import",
116
+ }],
117
+
118
+ // 要求使用统一的函数签名
119
+ // https://typescript-eslint.io/rules/unified-signatures
120
+ "@typescript-eslint/unified-signatures": ["error", {
121
+ ignoreDifferentlyNamedParameters: false,
122
+ ignoreOverloadsWithDifferentJSDoc: false,
123
+ }],
124
+ },
125
+ };