@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.
Files changed (91) 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 +13 -22
  11. package/lib/import.js +23 -0
  12. package/lib/javascript-es5.js +23 -0
  13. package/lib/javascript-es6.js +25 -0
  14. package/lib/rules/eslint/_deprecated.js +132 -0
  15. package/lib/rules/eslint/_removed.js +25 -0
  16. package/lib/rules/eslint/es6.js +279 -110
  17. package/lib/rules/eslint/layout-formatting.js +441 -0
  18. package/lib/rules/eslint/possible-errors.js +140 -131
  19. package/lib/rules/eslint/suggestions.js +666 -0
  20. package/lib/rules/html/accessibility.js +47 -23
  21. package/lib/rules/html/best-practice.js +122 -36
  22. package/lib/rules/html/seo.js +16 -11
  23. package/lib/rules/html/style.js +53 -15
  24. package/lib/rules/import/helpful-warnings.js +23 -18
  25. package/lib/rules/import/module-systems.js +16 -17
  26. package/lib/rules/import/static-analysis.js +54 -38
  27. package/lib/rules/import/style-guide.js +89 -61
  28. package/lib/rules/typescript/_deprecated.js +57 -0
  29. package/lib/rules/typescript/conflict.js +16 -0
  30. package/lib/rules/typescript/deprecated.js +41 -0
  31. package/lib/rules/typescript/extension.js +207 -0
  32. package/lib/rules/typescript/fixable.js +215 -0
  33. package/lib/rules/typescript/other.js +125 -0
  34. package/lib/rules/typescript/stylistic.js +34 -0
  35. package/lib/rules/typescript/suggestion.js +53 -0
  36. package/lib/rules/typescript/type-checked.js +263 -0
  37. package/lib/rules/vue/_deprecated.js +37 -0
  38. package/lib/rules/vue/common-base.js +1 -11
  39. package/lib/rules/vue/common-essential.js +25 -38
  40. package/lib/rules/vue/common-extension.js +321 -0
  41. package/lib/rules/vue/common-recommended.js +64 -31
  42. package/lib/rules/vue/common-strongly-recommended.js +37 -20
  43. package/lib/rules/vue/{common-extra.js → common-uncategorized.js} +141 -52
  44. package/lib/rules/vue/vue2-essential.js +16 -14
  45. package/lib/rules/vue/vue2-uncategorized.js +15 -0
  46. package/lib/rules/vue/vue3-essential.js +54 -24
  47. package/lib/rules/vue/vue3-strongly-recommended.js +8 -10
  48. package/lib/rules/vue/vue3-uncategorized.js +115 -0
  49. package/lib/support/es5-support.js +29 -0
  50. package/lib/support/es6-support.js +39 -0
  51. package/lib/support/html-support.js +38 -0
  52. package/lib/support/import-bugfix.js +65 -0
  53. package/lib/support/import-support.js +25 -0
  54. package/lib/support/typescript-support.js +27 -0
  55. package/lib/support/vue2-support.js +43 -0
  56. package/lib/support/vue3-support.js +43 -0
  57. package/lib/support/vue3-ts-support.js +51 -0
  58. package/lib/typescript.js +24 -32
  59. package/lib/utils/utils.js +160 -0
  60. package/lib/vue2.js +16 -22
  61. package/lib/vue3-ts.js +31 -0
  62. package/lib/vue3.js +13 -17
  63. package/package.json +38 -22
  64. package/lib/configs/eslint-es5.js +0 -24
  65. package/lib/configs/eslint.js +0 -23
  66. package/lib/configs/format-html.js +0 -22
  67. package/lib/configs/format-js.js +0 -134
  68. package/lib/configs/format-vue.js +0 -278
  69. package/lib/configs/html.js +0 -20
  70. package/lib/configs/import-bugfix.js +0 -36
  71. package/lib/configs/import.js +0 -44
  72. package/lib/configs/typescript.js +0 -10
  73. package/lib/configs/vue2.js +0 -28
  74. package/lib/configs/vue3.js +0 -28
  75. package/lib/eslint.js +0 -18
  76. package/lib/format.js +0 -40
  77. package/lib/rules/eslint/best-practices.js +0 -422
  78. package/lib/rules/eslint/node.js +0 -48
  79. package/lib/rules/eslint/strict-mode.js +0 -12
  80. package/lib/rules/eslint/stylistic-issues.js +0 -578
  81. package/lib/rules/eslint/variables.js +0 -73
  82. package/lib/rules/typescript/all.js +0 -193
  83. package/lib/rules/typescript/base.js +0 -10
  84. package/lib/rules/typescript/eslint-recommended.js +0 -36
  85. package/lib/rules/typescript/recommended-requiring-type-checking.js +0 -26
  86. package/lib/rules/typescript/recommended.js +0 -36
  87. package/lib/rules/typescript/strict.js +0 -47
  88. package/lib/rules/vue/common-eslint.js +0 -220
  89. package/lib/rules/vue/vue2-recommended.js +0 -17
  90. package/lib/rules/vue/vue2-strongly-recommended.js +0 -16
  91. package/lib/rules/vue/vue3-recommended.js +0 -17
@@ -0,0 +1,132 @@
1
+
2
+ // 这些规则已根据废弃政策被弃用,并被更新的规则所取代
3
+
4
+ // module.exports = {
5
+ // rules: {
6
+ // "callback-return": "", // [ ✅ 已使用 ]
7
+ // "global-require": "", // [ ✅ 已使用 ]
8
+ // "handle-callback-err": "", // [ ✅ 已使用 ]
9
+ // "id-blacklist": "", // [ ❌ 未使用 ] 替换为 id-denylist
10
+ // "indent-legacy": "", // [ ❌ 未使用 ] 替换为 indent
11
+ // "lines-around-directive": "", // [ ✅ 已使用 ] 替换为 padding-line-between-statements
12
+ // "newline-after-var": "", // [ ✅ 已使用 ] 替换为 padding-line-between-statements
13
+ // "newline-before-return": "", // [ ✅ 已使用 ] 替换为 padding-line-between-statements
14
+ // "no-buffer-constructor": "", // [ ✅ 已使用 ]
15
+ // "no-catch-shadow": "", // [ ✅ 已使用 ] 替换为 no-shadow
16
+ // "no-mixed-requires": "", // [ ✅ 已使用 ]
17
+ // "no-native-reassign": "", // [ ✅ 已使用 ] 替换为 no-global-assign
18
+ // "no-negated-in-lhs": "", // [ ✅ 已使用 ] 替换为 no-unsafe-negation
19
+ // "no-new-require": "", // [ ✅ 已使用 ]
20
+ // "no-path-concat": "", // [ ✅ 已使用 ]
21
+ // "no-process-env": "", // [ ✅ 已使用 ]
22
+ // "no-process-exit": "", // [ ✅ 已使用 ]
23
+ // "no-restricted-modules": "", // [ ✅ 已使用 ]
24
+ // "no-return-await": "", // [ ✅ 已使用 ]
25
+ // "no-spaced-func": "", // [ ❌ 未使用 ] 替换为 func-call-spacing
26
+ // "no-sync": "", // [ ✅ 已使用 ]
27
+ // "prefer-reflect": "", // [ ✅ 已使用 ]
28
+ // "require-jsdoc": "", // [ ✅ 已使用 ]
29
+ // "valid-jsdoc": "", // [ ✅ 已使用 ]
30
+ // },
31
+ // };
32
+
33
+ module.exports = {
34
+ rules: {
35
+ // enforce return after a callback
36
+ // ❌ 已废弃
37
+ "callback-return": "off",
38
+
39
+ // 强制在模块顶部调用
40
+ // ❌ 已废弃
41
+ // https://zh-hans.eslint.org/docs/latest/rules/global-require
42
+ "global-require": "off",
43
+
44
+ // enforces error handling in callbacks (node environment)
45
+ // ❌ 已废弃
46
+ "handle-callback-err": "off",
47
+
48
+ // require or disallow newlines around directives
49
+ // ❌ 已废弃
50
+ // https://zh-hans.eslint.org/docs/latest/rules/lines-around-directive
51
+ "lines-around-directive": ["error", {
52
+ before: "always",
53
+ after: "always",
54
+ }],
55
+
56
+ // allow/disallow an empty newline after var statement
57
+ // ❌ 已废弃
58
+ "newline-after-var": "off",
59
+
60
+ // https://zh-hans.eslint.org/docs/latest/rules/newline-before-return
61
+ // ❌ 已废弃
62
+ "newline-before-return": "off",
63
+
64
+ // disallow use of the Buffer() constructor
65
+ // ❌ 已废弃
66
+ // https://zh-hans.eslint.org/docs/latest/rules/no-buffer-constructor
67
+ "no-buffer-constructor": "error",
68
+
69
+ // disallow the catch clause parameter name being the same as a variable in the outer scope
70
+ // ❌ 已废弃
71
+ "no-catch-shadow": "off",
72
+
73
+ // disallow mixing regular variable and require declarations
74
+ // ❌ 已废弃
75
+ "no-mixed-requires": ["off", false],
76
+
77
+ // deprecated in favor of no-global-assign
78
+ // ❌ 已废弃
79
+ // https://zh-hans.eslint.org/docs/latest/rules/no-native-reassign
80
+ "no-native-reassign": "off",
81
+
82
+ // disallow negation of the left operand of an in expression
83
+ // deprecated in favor of no-unsafe-negation
84
+ // ❌ 已废弃
85
+ "no-negated-in-lhs": "off",
86
+
87
+ // disallow use of new operator with the require function
88
+ // ❌ 已废弃
89
+ "no-new-require": "error",
90
+
91
+ // disallow string concatenation with __dirname and __filename
92
+ // ❌ 已废弃
93
+ // https://zh-hans.eslint.org/docs/latest/rules/no-path-concat
94
+ "no-path-concat": "error",
95
+
96
+ // disallow use of process.env
97
+ // ❌ 已废弃
98
+ "no-process-env": "off",
99
+
100
+ // disallow process.exit()
101
+ // ❌ 已废弃
102
+ "no-process-exit": "off",
103
+
104
+ // restrict usage of specified node modules
105
+ // ❌ 已废弃
106
+ "no-restricted-modules": "off",
107
+
108
+ // disallow redundant `return await`
109
+ // ❌ 已废弃
110
+ // https://zh-hans.eslint.org/docs/latest/rules/no-return-await
111
+ "no-return-await": "error",
112
+
113
+ // disallow use of synchronous methods (off by default)
114
+ // ❌ 已废弃
115
+ "no-sync": "off",
116
+
117
+ // suggest using Reflect methods where applicable
118
+ // ❌ 已废弃
119
+ // https://zh-hans.eslint.org/docs/latest/rules/prefer-reflect
120
+ "prefer-reflect": "off",
121
+
122
+ // do not require jsdoc
123
+ // ❌ 已废弃
124
+ // https://zh-hans.eslint.org/docs/latest/rules/require-jsdoc
125
+ "require-jsdoc": "off",
126
+
127
+ // ensure JSDoc comments are valid
128
+ // ❌ 已废弃
129
+ // https://zh-hans.eslint.org/docs/latest/rules/valid-jsdoc
130
+ "valid-jsdoc": "off",
131
+ },
132
+ };
@@ -0,0 +1,25 @@
1
+
2
+ // 这些来自较旧版本的 ESLint 规则已被更新的规则所取代
3
+
4
+ module.exports = {
5
+ rules: {
6
+ "generator-star": "", // [ ✅ 已使用 ] 替换为 generator-star-spacing
7
+ "global-strict": "", // [ ❌ 未使用 ] 替换为 strict
8
+ "no-arrow-condition": "", // [ ❌ 未使用 ] 替换为 no-confusing-arrowno-constant-condition
9
+ "no-comma-dangle": "", // [ ❌ 未使用 ] 替换为 comma-dangle
10
+ "no-empty-class": "", // [ ❌ 未使用 ] 替换为 no-empty-character-class
11
+ "no-empty-label": "", // [ ❌ 未使用 ] 替换为 no-labels
12
+ "no-extra-strict": "", // [ ❌ 未使用 ] 替换为 strict
13
+ "no-reserved-keys": "", // [ ❌ 未使用 ] 替换为 quote-props
14
+ "no-space-before-semi": "", // [ ❌ 未使用 ] 替换为 semi-spacing
15
+ "no-wrap-func": "", // [ ❌ 未使用 ] 替换为 no-extra-parens
16
+ "space-after-function-name": "", // [ ❌ 未使用 ] 替换为 space-before-function-paren
17
+ "space-after-keywords": "", // [ ❌ 未使用 ] 替换为 keyword-spacing
18
+ "space-before-function-parentheses": "", // [ ❌ 未使用 ] 替换为 space-before-function-paren
19
+ "space-before-keywords": "", // [ ❌ 未使用 ] 替换为 keyword-spacing
20
+ "space-in-brackets": "", // [ ❌ 未使用 ] 替换为 object-curly-spacingarray-bracket-spacing
21
+ "space-return-throw-case": "", // [ ❌ 未使用 ] 替换为 keyword-spacing
22
+ "space-unary-word-ops": "", // [ ❌ 未使用 ] 替换为 space-unary-ops
23
+ "spaced-line-comment": "", // [ ❌ 未使用 ] 替换为 spaced-comment
24
+ },
25
+ };
@@ -5,175 +5,302 @@
5
5
  // ==========================================================
6
6
 
7
7
  module.exports = {
8
- env: {
9
- es6: true,
10
- },
11
- parserOptions: {
12
- ecmaVersion: 6,
13
- sourceType: "module",
14
- ecmaFeatures: {
15
- generators: false,
16
- objectLiteralDuplicateProperties: false,
17
- },
18
- },
19
8
  rules: {
20
- // 箭头函数体周围的大括号风格
21
- // https://eslint.org/docs/rules/arrow-body-style
22
- "arrow-body-style": ["error", "as-needed", {
23
- requireReturnForObjectLiteral: false,
9
+ // ==========================================================
10
+ // Possible Errors
11
+ // 这些规则与 JavaScript 代码中可能的错误或逻辑错误有关
12
+ // ==========================================================
13
+
14
+ // 数组方法的回调函数必须有返回值(map、filter、reduce 等)
15
+ "array-callback-return": ["error", {
16
+ allowImplicit: false,
17
+ checkForEach: true,
24
18
  }],
25
19
 
26
- // 要求箭头函数的参数使用圆括号
27
- // https://eslint.org/docs/rules/arrow-parens
28
- "arrow-parens": ["warn", "as-needed"],
20
+ // 要求在构造函数中调用 super()
21
+ // 派生类的构造者必须调用 super(),非派生类的构造器不得调用 super(),如果不遵守这一点,JavaScript 引擎将引起运行时错误。
22
+ // https://zh-hans.eslint.org/docs/latest/rules/constructor-super
23
+ "constructor-super": "off",
29
24
 
30
- // 要求箭头函数的箭头之前或之后有空格
31
- // https://eslint.org/docs/rules/arrow-spacing
32
- "arrow-spacing": ["warn", {
33
- "before": true,
34
- "after": true,
25
+ // 强制 getter 方法有返回值
26
+ "getter-return": ["error", {
27
+ // 不允许用 return 语句隐式返回 undefined
28
+ allowImplicit: false,
35
29
  }],
36
30
 
37
- // verify super() callings in constructors
38
- "constructor-super": "error",
31
+ // 禁止使用异步函数作为 Promise 执行器
32
+ "no-async-promise-executor": "error",
39
33
 
40
- // 强制 generator 函数中 * 号周围使用一致的空格
41
- // https://eslint.org/docs/rules/generator-star-spacing
42
- "generator-star-spacing": ["warn", {
43
- before: false,
44
- after: true,
45
- }],
34
+ // 禁止在循环内使用 await
35
+ "no-await-in-loop": "error",
46
36
 
47
- // disallow modifying variables of class declarations
48
- // https://eslint.org/docs/rules/no-class-assign
37
+ // 禁止重新分配类成员
38
+ // https://zh-hans.eslint.org/docs/latest/rules/no-class-assign
49
39
  "no-class-assign": "error",
50
40
 
51
- // 禁止在可能与比较操作符相混淆的地方使用箭头函数
52
- // https://eslint.org/docs/rules/no-confusing-arrow
53
- "no-confusing-arrow": ["error", {
54
- "allowParens": true,
55
- }],
56
-
57
- // disallow modifying variables that are declared using const
41
+ // 禁止对 const 变量重新赋值
42
+ // https://zh-hans.eslint.org/docs/latest/rules/no-const-assign
58
43
  "no-const-assign": "error",
59
44
 
60
- // disallow duplicate class members
61
- // https://eslint.org/docs/rules/no-dupe-class-members
45
+ // 在类的构造函数中,使用此规则禁用 return 语句
46
+ // https://zh-hans.eslint.org/docs/latest/rules/no-constructor-return
47
+ "no-constructor-return": "error",
48
+
49
+ // 禁止类的成员(方法、属性)名称重复
50
+ // https://zh-hans.eslint.org/docs/latest/rules/no-dupe-class-members
62
51
  "no-dupe-class-members": "error",
63
52
 
64
- // disallow importing from the same path more than once
65
- // https://eslint.org/docs/rules/no-duplicate-imports
66
- // replaced by https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
53
+ // 禁止重复导入模块
54
+ // 要求所有可以合并的单个模块的导入都在于一个 import 语句中
55
+ // https://zh-hans.eslint.org/docs/latest/rules/no-duplicate-imports
67
56
  "no-duplicate-imports": "off",
68
57
 
69
- // disallow symbol constructor
70
- // https://eslint.org/docs/rules/no-new-symbol
58
+ // 禁止空解构模式
59
+ // https://zh-hans.eslint.org/docs/latest/rules/no-empty-pattern
60
+ "no-empty-pattern": "error",
61
+
62
+ // 禁止对导入的模块赋值
63
+ // https://zh-hans.eslint.org/docs/latest/rules/no-import-assign
64
+ "no-import-assign": "error",
65
+
66
+ // Disallow new operators with global non-constructor functions
67
+ // 此规则旨在阻止使用 new 操作符意外调用原生 JavaScript 全局函数(Symbol、BigInt)
68
+ // https://zh-hans.eslint.org/docs/latest/rules/no-new-native-nonconstructor
69
+ "no-new-native-nonconstructor": "error",
70
+
71
+ // 禁止用 new 运算符意外地调用 Symbol
72
+ // 这是错误语法,因为 Symbol 是一个原始值,不是对象
73
+ // https://zh-hans.eslint.org/docs/latest/rules/no-new-symbol
71
74
  "no-new-symbol": "error",
72
75
 
73
- // Disallow specified names in exports
74
- // https://eslint.org/docs/rules/no-restricted-exports
76
+ // 不允许从 Promise 执行者函数返回值
77
+ // https://zh-hans.eslint.org/docs/latest/rules/no-promise-executor-return
78
+ "no-promise-executor-return": "error",
79
+
80
+ // 禁止在 setter 中返回值
81
+ // https://zh-hans.eslint.org/docs/latest/rules/no-setter-return
82
+ "no-setter-return": "error",
83
+
84
+ // 禁止在字符串中使用模板文字占位符语法
85
+ // https://zh-hans.eslint.org/docs/latest/rules/no-template-curly-in-string
86
+ "no-template-curly-in-string": "error",
87
+
88
+ // 禁止在 super() 之前使用 this 或 super
89
+ // https://zh-hans.eslint.org/docs/latest/rules/no-this-before-super
90
+ "no-this-before-super": "error",
91
+
92
+ // 禁止不安全的可选链(?.)
93
+ // 可选的链式(?.)表达式可以用 undefined 的返回值进行短路。因此,将一个已评估的选项链表达式作为一个函数、对象、数字等来处理,会导致 TypeError 或意外的结果。
94
+ // 这条规则的目的是检测一些使用可选链的情况,这些情况不能防止运行时错误。
95
+ // https://zh-hans.eslint.org/docs/latest/rules/no-unsafe-optional-chaining
96
+ "no-unsafe-optional-chaining": ["error", {
97
+ // 不允许对可选链式表达式进行算术运算(默认为 false)
98
+ disallowArithmeticOperators: true,
99
+ }],
100
+
101
+ // 不允许 Class 存在未使用的私有成员(属性、方法)
102
+ // https://zh-hans.eslint.org/docs/latest/rules/no-unused-private-class-members
103
+ "no-unused-private-class-members": "error",
104
+
105
+ // 禁止由于使用await或yield而导致竞争条件的赋值
106
+ // https://zh-hans.eslint.org/docs/latest/rules/require-atomic-updates
107
+ "require-atomic-updates": "error",
108
+
109
+ // ==========================================================
110
+ // Suggestions
111
+ // 这些规则提出了做事的替代方法
112
+ // ==========================================================
113
+
114
+ // 强制对象中的 getter/setter 成对出现
115
+ // https://zh-hans.eslint.org/docs/latest/rules/accessor-pairs
116
+ "accessor-pairs": ["error", {
117
+ setWithoutGet: true,
118
+ getWithoutSet: true,
119
+ enforceForClassMembers: true,
120
+ }],
121
+
122
+ // 箭头函数体周围的大括号风格
123
+ // https://zh-hans.eslint.org/docs/latest/rules/arrow-body-style
124
+ "arrow-body-style": ["warn", "as-needed", {
125
+ requireReturnForObjectLiteral: false,
126
+ }],
127
+
128
+ // 强制类方法使用 "this"
129
+ // https://zh-hans.eslint.org/docs/latest/rules/class-methods-use-this
130
+ "class-methods-use-this": ["off", {
131
+ exceptMethods: [],
132
+ enforceForClassFields: false,
133
+ }],
134
+
135
+ // 强制默认参数放在最后
136
+ // https://zh-hans.eslint.org/docs/latest/rules/default-param-last
137
+ "default-param-last": "error",
138
+
139
+ // 在对象文本和类中要求分组访问器对(getter/setter 配对出现)
140
+ // https://zh-hans.eslint.org/docs/latest/rules/grouped-accessor-pairs
141
+ "grouped-accessor-pairs": "error",
142
+
143
+ // 每个文件强制 Class 类的最大数量
144
+ // https://zh-hans.eslint.org/docs/latest/rules/max-classes-per-file
145
+ "max-classes-per-file": ["error", 1],
146
+
147
+ // 要求构造器函数首字母大写
148
+ // https://zh-hans.eslint.org/docs/latest/rules/new-cap
149
+ "new-cap": ["error", {
150
+ newIsCap: true,
151
+ newIsCapExceptions: [],
152
+ newIsCapExceptionPattern: "^hh[A-Z]",
153
+ capIsNew: false,
154
+ capIsNewExceptions: ["Immutable.Map", "Immutable.Set", "Immutable.List"],
155
+ capIsNewExceptionPattern: "",
156
+ properties: false,
157
+ }],
158
+
159
+ // 禁止在可能与比较操作符相混淆的地方使用箭头函数
160
+ // https://zh-hans.eslint.org/docs/latest/rules/no-confusing-arrow
161
+ "no-confusing-arrow": ["warn", {
162
+ allowParens: true,
163
+ onlyOneSimpleParam: false,
164
+ }],
165
+
166
+ // 禁止使用 __iterator__ 属性(应该使用 ECMAScript 6 迭代器和生成器来代替)
167
+ // https://zh-hans.eslint.org/docs/latest/rules/no-iterator
168
+ "no-iterator": "error",
169
+
170
+ // 禁止在 exports 导出中使用指定的名称
171
+ // https://zh-hans.eslint.org/docs/latest/rules/no-restricted-exports
75
172
  "no-restricted-exports": ["error", {
76
173
  restrictedNamedExports: [
77
- "default", // use `export default` to provide a default export
78
- "then", // this will cause tons of confusion when your module is dynamically `import()`ed, and will break in most node ESM versions
174
+ "default", // use `export default` to provide a default export
175
+ "then", // this will cause tons of confusion when your module is dynamically `import()`ed, and will break in most node ESM versions
79
176
  ],
80
177
  }],
81
178
 
82
- // disallow specific imports
83
- // https://eslint.org/docs/rules/no-restricted-imports
179
+ // 禁止 imports 导入指定的模块
180
+ // https://zh-hans.eslint.org/docs/latest/rules/no-restricted-imports
84
181
  "no-restricted-imports": ["off", {
85
182
  paths: [],
86
183
  patterns: [],
87
184
  }],
88
185
 
89
- // disallow to use this/super before super() calling in constructors.
90
- // https://eslint.org/docs/rules/no-this-before-super
91
- "no-this-before-super": "error",
92
-
93
- // disallow useless computed property keys
94
- // https://eslint.org/docs/rules/no-useless-computed-key
95
- "no-useless-computed-key": "error",
186
+ // 禁止无用的计算属性键
187
+ // https://zh-hans.eslint.org/docs/latest/rules/no-useless-computed-key
188
+ "no-useless-computed-key": ["warn", {
189
+ enforceForClassMembers: true,
190
+ }],
96
191
 
97
- // disallow unnecessary constructor
98
- // https://eslint.org/docs/rules/no-useless-constructor
192
+ // 禁止无用的构造函数
193
+ // https://zh-hans.eslint.org/docs/latest/rules/no-useless-constructor
99
194
  "no-useless-constructor": "error",
100
195
 
101
- // disallow renaming import, export, and destructured assignments to the same name
102
- // https://eslint.org/docs/rules/no-useless-rename
103
- "no-useless-rename": ["error", {
196
+ // 不允许重命名导入、导出以及以相同名称进行的解构赋值
197
+ // https://zh-hans.eslint.org/docs/latest/rules/no-useless-rename
198
+ "no-useless-rename": ["warn", {
104
199
  ignoreDestructuring: false,
105
200
  ignoreImport: false,
106
201
  ignoreExport: false,
107
202
  }],
108
203
 
109
- // require let or const instead of var
110
- "no-var": "error",
204
+ // 要求使用 let 或 const 而不是 var
205
+ // https://zh-hans.eslint.org/docs/latest/rules/no-var
206
+ "no-var": "warn",
111
207
 
112
208
  // 要求或禁止对象字面量的方法和属性简写语法
113
- // https://eslint.org/docs/rules/object-shorthand
114
- "object-shorthand": ["warn", "always", {
115
- ignoreConstructors: false,
209
+ // https://zh-hans.eslint.org/docs/latest/rules/object-shorthand
210
+ "object-shorthand": ["warn", "properties", {
116
211
  avoidQuotes: true,
212
+ // ignoreConstructors: false,
213
+ // methodsIgnorePattern: "",
214
+ // avoidExplicitReturnArrows: false,
117
215
  }],
118
216
 
119
- // suggest using arrow functions as callbacks
120
- "prefer-arrow-callback": ["error", {
217
+ // 要求回调函数使用箭头函数
218
+ // https://zh-hans.eslint.org/docs/latest/rules/prefer-arrow-callback
219
+ "prefer-arrow-callback": ["warn", {
121
220
  allowNamedFunctions: false,
122
221
  allowUnboundThis: true,
123
222
  }],
124
223
 
125
- // suggest using of const declaration for variables that are never modified after declared
126
- "prefer-const": ["error", {
224
+ // 初始赋值后从未重新赋值的变量应该使用 const 声明
225
+ // https://zh-hans.eslint.org/docs/latest/rules/prefer-const
226
+ "prefer-const": ["warn", {
127
227
  destructuring: "any",
128
228
  ignoreReadBeforeAssign: true,
129
229
  }],
130
230
 
131
231
  // 优先使用数组和对象解构
132
- // https://eslint.org/docs/rules/prefer-destructuring
232
+ // https://zh-hans.eslint.org/docs/latest/rules/prefer-destructuring
133
233
  "prefer-destructuring": "off",
134
- // 'prefer-destructuring': ['error', {
135
- // VariableDeclarator: {
136
- // array: false,
137
- // object: true,
234
+ // "prefer-destructuring": [
235
+ // "warn",
236
+ // {
237
+ // VariableDeclarator: {
238
+ // array: false,
239
+ // object: true,
240
+ // },
241
+ // AssignmentExpression: {
242
+ // array: true,
243
+ // object: false,
244
+ // },
138
245
  // },
139
- // AssignmentExpression: {
140
- // array: true,
141
- // object: false,
246
+ // {
247
+ // enforceForRenamedProperties: false,
142
248
  // },
143
- // }, {
144
- // enforceForRenamedProperties: false,
145
- // }],
249
+ // ],
146
250
 
147
- // disallow parseInt() in favor of binary, octal, and hexadecimal literals
148
- // https://eslint.org/docs/rules/prefer-numeric-literals
149
- "prefer-numeric-literals": "error",
251
+ // 不允许调用 Math.pow,建议使用 ** 运算符代替
252
+ // https://zh-hans.eslint.org/docs/latest/rules/prefer-exponentiation-operator
253
+ "prefer-exponentiation-operator": "warn",
254
+
255
+ // 正则表达式中建议使用命名捕获组
256
+ // https://zh-hans.eslint.org/docs/latest/rules/prefer-named-capture-group
257
+ "prefer-named-capture-group": "off",
150
258
 
151
- // suggest using Reflect methods where applicable
152
- // https://eslint.org/docs/rules/prefer-reflect
153
- "prefer-reflect": "off",
259
+ // disallow parseInt() in favor of binary, octal, and hexadecimal literals
260
+ // https://zh-hans.eslint.org/docs/latest/rules/prefer-numeric-literals
261
+ "prefer-numeric-literals": "warn",
262
+
263
+ // 要求使用 Object.hasOwn() 方法而不是 Object.prototype.hasOwnProperty.call()
264
+ // https://zh-hans.eslint.org/docs/latest/rules/prefer-object-has-own
265
+ "prefer-object-has-own": "warn",
266
+
267
+ // 禁止使用以对象字面量作为第一个参数的 Object.assign,优先使用对象扩展
268
+ // https://zh-hans.eslint.org/docs/latest/rules/prefer-object-spread
269
+ "prefer-object-spread": "off",
270
+ // "prefer-object-spread": "warn",
271
+
272
+ // 要求使用 Error 对象作为 Promise 拒绝的原因
273
+ // https://zh-hans.eslint.org/docs/latest/rules/prefer-promise-reject-errors
274
+ "prefer-promise-reject-errors": ["error", {
275
+ allowEmptyReject: true,
276
+ }],
154
277
 
155
- // use rest parameters instead of arguments
156
- // https://eslint.org/docs/rules/prefer-rest-params
278
+ // 要求使用 rest 参数而不是 arguments
279
+ // https://zh-hans.eslint.org/docs/latest/rules/prefer-rest-params
157
280
  "prefer-rest-params": "error",
158
281
 
159
- // suggest using the spread syntax instead of .apply()
160
- // https://eslint.org/docs/rules/prefer-spread
282
+ // 需要展开操作符而不是 .apply()
283
+ // https://zh-hans.eslint.org/docs/latest/rules/prefer-spread
161
284
  "prefer-spread": "error",
162
285
 
163
286
  // 要求使用模板文字进行字符串连接
164
- // https://eslint.org/docs/rules/prefer-template
287
+ // https://zh-hans.eslint.org/docs/latest/rules/prefer-template
165
288
  "prefer-template": "warn",
166
289
 
167
- // disallow generator functions that do not have yield
168
- // https://eslint.org/docs/rules/require-yield
169
- "require-yield": "error",
290
+ // 要求 async 函数中含有 await 表达式
291
+ // https://zh-hans.eslint.org/docs/latest/rules/require-await
292
+ "require-await": "error",
170
293
 
171
- // 强制剩余和扩展运算符及其表达式之间有空格
172
- // https://eslint.org/docs/rules/rest-spread-spacing
173
- "rest-spread-spacing": ["error", "never"],
294
+ // 要求在正则表达式中使用 u、v 标志
295
+ // https://zh-hans.eslint.org/docs/latest/rules/require-unicode-regexp
296
+ "require-unicode-regexp": "error",
174
297
 
175
- // import sorting
176
- // https://eslint.org/docs/rules/sort-imports
298
+ // 要求生成器函数包含 yield 表达式
299
+ // https://zh-hans.eslint.org/docs/latest/rules/require-yield
300
+ "require-yield": "error",
301
+
302
+ // 在模块内对导入声明进行强制排序
303
+ // https://zh-hans.eslint.org/docs/latest/rules/sort-imports
177
304
  "sort-imports": ["off", {
178
305
  ignoreCase: false,
179
306
  ignoreDeclarationSort: false,
@@ -181,16 +308,58 @@ module.exports = {
181
308
  memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
182
309
  }],
183
310
 
184
- // require a Symbol description
185
- // https://eslint.org/docs/rules/symbol-description
311
+ // 要求在创建 Symbol 时要有描述
312
+ // https://zh-hans.eslint.org/docs/latest/rules/symbol-description
186
313
  "symbol-description": "error",
187
314
 
315
+ // ==========================================================
316
+ // Layout and Formatting
317
+ // 这些规则关心的是代码的外观而不是执行方式
318
+ // ==========================================================
319
+
320
+ // 要求箭头函数的参数使用圆括号
321
+ // https://zh-hans.eslint.org/docs/latest/rules/arrow-parens
322
+ "arrow-parens": ["warn", "as-needed"],
323
+
324
+ // 要求箭头函数的箭头之前或之后有空格
325
+ // https://zh-hans.eslint.org/docs/latest/rules/arrow-spacing
326
+ "arrow-spacing": ["warn", {
327
+ before: true,
328
+ after: true,
329
+ }],
330
+
331
+ // 强制 generator 函数中 * 号周围使用一致的空格
332
+ // https://zh-hans.eslint.org/docs/latest/rules/generator-star-spacing
333
+ "generator-star-spacing": ["warn", {
334
+ before: false,
335
+ after: true,
336
+ }],
337
+
338
+ // 强制隐式返回的箭头函数体的位置
339
+ // https://zh-hans.eslint.org/docs/latest/rules/implicit-arrow-linebreak
340
+ "implicit-arrow-linebreak": ["warn", "beside"],
341
+
342
+ // 类成员之间要求或禁止空行
343
+ // https://zh-hans.eslint.org/docs/latest/rules/lines-between-class-members
344
+ "lines-between-class-members": "off",
345
+
346
+ // 强制剩余和扩展运算符及其表达式之间有空格
347
+ // https://zh-hans.eslint.org/docs/latest/rules/rest-spread-spacing
348
+ "rest-spread-spacing": ["warn", "never"],
349
+
188
350
  // 要求或禁止模板字符串中的嵌入表达式周围空格的使用
189
- // https://eslint.org/docs/rules/template-curly-spacing
190
- "template-curly-spacing": "warn",
351
+ // https://zh-hans.eslint.org/docs/latest/rules/template-curly-spacing
352
+ "template-curly-spacing": ["warn", "never"],
353
+
354
+ // 要求或禁止在模板标记和它们的字面量之间有空格
355
+ // https://zh-hans.eslint.org/docs/latest/rules/template-tag-spacing
356
+ "template-tag-spacing": ["warn", "never"],
191
357
 
192
358
  // 强制在 yield* 表达式中 * 周围使用空格
193
- // https://eslint.org/docs/rules/yield-star-spacing
194
- "yield-star-spacing": ["warn", "after"],
359
+ // https://zh-hans.eslint.org/docs/latest/rules/yield-star-spacing
360
+ "yield-star-spacing": ["warn", {
361
+ before: false,
362
+ after: true,
363
+ }],
195
364
  },
196
365
  };