@huangjunsen/eslint-config 1.0.0 → 1.0.2

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 (56) hide show
  1. package/.editorconfig +17 -17
  2. package/.eslintignore +17 -17
  3. package/.eslintrc.js +5 -5
  4. package/CHANGELOG.md +7 -0
  5. package/README.md +0 -286
  6. package/__tests__/fixtures/es5.js +4 -4
  7. package/__tests__/fixtures/index.js +3 -3
  8. package/__tests__/fixtures/node.js +23 -23
  9. package/__tests__/fixtures/react-display-name.js +7 -7
  10. package/__tests__/fixtures/react.jsx +132 -132
  11. package/__tests__/fixtures/ts-import-a.ts +3 -3
  12. package/__tests__/fixtures/ts-import-b.ts +3 -3
  13. package/__tests__/fixtures/ts-node.ts +19 -19
  14. package/__tests__/fixtures/ts-react.tsx +27 -27
  15. package/__tests__/fixtures/ts-vue.vue +36 -36
  16. package/__tests__/fixtures/ts.ts +17 -17
  17. package/__tests__/fixtures/vue.vue +16 -16
  18. package/__tests__/validate-js-configs.test.js +259 -259
  19. package/es5.js +10 -10
  20. package/essential/es5.js +12 -12
  21. package/essential/index.js +12 -12
  22. package/essential/react.js +76 -76
  23. package/essential/rules/blacklist.js +48 -48
  24. package/essential/rules/es6-blacklist.js +62 -62
  25. package/essential/rules/set-style-to-warn.js +30 -30
  26. package/essential/rules/ts-blacklist.js +15 -15
  27. package/essential/typescript/index.js +7 -7
  28. package/essential/typescript/react.js +7 -7
  29. package/essential/typescript/vue.js +9 -9
  30. package/essential/vue.js +8 -8
  31. package/flat/index.js +32 -0
  32. package/flat/react.js +19 -0
  33. package/flat/typescript.js +15 -0
  34. package/flat/vue.js +12 -0
  35. package/index.js +23 -23
  36. package/jsx-a11y.js +5 -5
  37. package/node.js +6 -6
  38. package/package.json +28 -10
  39. package/react.js +11 -11
  40. package/rules/base/best-practices.js +284 -284
  41. package/rules/base/es6.js +168 -168
  42. package/rules/base/possible-errors.js +126 -126
  43. package/rules/base/strict.js +6 -6
  44. package/rules/base/style.js +445 -445
  45. package/rules/base/variables.js +48 -48
  46. package/rules/es5.js +11 -11
  47. package/rules/imports.js +167 -167
  48. package/rules/jsx-a11y.js +23 -23
  49. package/rules/node.js +11 -11
  50. package/rules/react.js +354 -354
  51. package/rules/vue.js +96 -96
  52. package/typescript/node.js +6 -6
  53. package/typescript/react.js +6 -6
  54. package/typescript/vue.js +10 -10
  55. package/vue.js +10 -10
  56. package/LICENSE +0 -21
package/rules/base/es6.js CHANGED
@@ -1,168 +1,168 @@
1
- module.exports = {
2
- rules: {
3
- // 箭头函数-函数体风格
4
- // @reason 允许灵活使用
5
- 'arrow-body-style': [
6
- 'off',
7
- 'as-needed',
8
- {
9
- requireReturnForObjectLiteral: false,
10
- },
11
- ],
12
-
13
- // 箭头函数-函数参数始终加上小括号
14
- // @reason 同 prettier 默认配置值一致:https://prettier.io/docs/en/options.html#arrow-function-parentheses
15
- 'arrow-parens': ['warn', 'always'],
16
-
17
- // 箭头函数的箭头前后各留一个空格
18
- // @unessential
19
- 'arrow-spacing': ['error', { before: true, after: true }],
20
-
21
- // 子类的 constructor 中必须使用 super,非子类的 constructor 中不能使用 super
22
- 'constructor-super': 'error',
23
-
24
- // generator 函数的 * 号前面无空格,后面有一个空格
25
- // @unessential
26
- 'generator-star-spacing': ['error', { before: false, after: true }],
27
-
28
- // 禁止对类声明变量重新赋值
29
- 'no-class-assign': 'error',
30
-
31
- // 避免箭头函数与比较操作符产生混淆
32
- // @unessential
33
- 'no-confusing-arrow': 'error',
34
-
35
- // 禁止修改 const 声明的变量
36
- 'no-const-assign': 'error',
37
-
38
- // 避免重复的类成员命名
39
- 'no-dupe-class-members': 'error',
40
-
41
- // 不要用多个 import 引入同一模块
42
- // @reason replacedBy import/no-duplicates
43
- 'no-duplicate-imports': 'off',
44
-
45
- // 禁止使用 new Symbol
46
- 'no-new-symbol': 'error',
47
-
48
- // 禁止特定的 import
49
- 'no-restricted-imports': [
50
- 'off',
51
- {
52
- paths: [],
53
- patterns: [],
54
- },
55
- ],
56
-
57
- // 在 constructor 中,禁止在调用 super() 前使用 this 或 super 关键字
58
- 'no-this-before-super': 'error',
59
-
60
- // 对象的属性名不要使用无必要的计算属性
61
- 'no-useless-computed-key': 'error',
62
-
63
- // 避免不必要的 constructor
64
- 'no-useless-constructor': 'error',
65
-
66
- // 禁止在解构/import/export时进行无用的重命名
67
- 'no-useless-rename': [
68
- 'error',
69
- {
70
- ignoreDestructuring: false,
71
- ignoreImport: false,
72
- ignoreExport: false,
73
- },
74
- ],
75
-
76
- // 使用 const 或 let 声明变量,不要使用 var
77
- // @unessential
78
- 'no-var': 'error',
79
-
80
- // 使用对象属性和方法的简写语法
81
- // @unessential
82
- 'object-shorthand': [
83
- 'error',
84
- 'always',
85
- {
86
- ignoreConstructors: false,
87
- avoidQuotes: true,
88
- },
89
- ],
90
-
91
- // 回调函数使用箭头函数而不是匿名函数
92
- // @unessential
93
- 'prefer-arrow-callback': [
94
- 'error',
95
- {
96
- allowNamedFunctions: false,
97
- allowUnboundThis: true,
98
- },
99
- ],
100
-
101
- // 优先使用 const,只有当变量会被重新赋值时才使用 let
102
- // @unessential
103
- 'prefer-const': [
104
- 'error',
105
- {
106
- destructuring: 'any',
107
- ignoreReadBeforeAssign: true,
108
- },
109
- ],
110
-
111
- // 使用对象和数组的解构
112
- 'prefer-destructuring': [
113
- 'warn',
114
- {
115
- VariableDeclarator: {
116
- array: false,
117
- object: true,
118
- },
119
- AssignmentExpression: {
120
- array: false,
121
- object: false,
122
- },
123
- },
124
- {
125
- enforceForRenamedProperties: false,
126
- },
127
- ],
128
-
129
- // 禁止使用 parseInt() 进行二、八、十六禁止转换
130
- 'prefer-numeric-literals': 'off',
131
-
132
- // 使用 rest 操作符替代 arguments 对象
133
- 'prefer-rest-params': 'warn',
134
-
135
- // 使用扩展运算符 ... 替代 apply()
136
- 'prefer-spread': 'warn',
137
-
138
- // 使用模板字符串替代字符串拼接
139
- 'prefer-template': 'warn',
140
-
141
- // generator 函数内必须有 yield 语句
142
- 'require-yield': 'error',
143
-
144
- // 剩余和扩展操作符与操作对象间不应有空格
145
- 'rest-spread-spacing': ['error', 'never'],
146
-
147
- // 为 import 排序
148
- 'sort-imports': [
149
- 'off',
150
- {
151
- ignoreCase: false,
152
- ignoreMemberSort: false,
153
- memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
154
- },
155
- ],
156
-
157
- // 创建 Symbol 时必须传入参数
158
- 'symbol-description': 'warn',
159
-
160
- // 模板字符串中的大括号内部两侧无空格
161
- // @unessential
162
- 'template-curly-spacing': 'warn',
163
-
164
- // yield* 表达式的 * 号前面无空格,后面有一个空格
165
- // @unessential
166
- 'yield-star-spacing': ['error', 'after'],
167
- },
168
- };
1
+ module.exports = {
2
+ rules: {
3
+ // 箭头函数-函数体风格
4
+ // @reason 允许灵活使用
5
+ 'arrow-body-style': [
6
+ 'off',
7
+ 'as-needed',
8
+ {
9
+ requireReturnForObjectLiteral: false,
10
+ },
11
+ ],
12
+
13
+ // 箭头函数-函数参数始终加上小括号
14
+ // @reason 同 prettier 默认配置值一致:https://prettier.io/docs/en/options.html#arrow-function-parentheses
15
+ 'arrow-parens': ['warn', 'always'],
16
+
17
+ // 箭头函数的箭头前后各留一个空格
18
+ // @unessential
19
+ 'arrow-spacing': ['error', { before: true, after: true }],
20
+
21
+ // 子类的 constructor 中必须使用 super,非子类的 constructor 中不能使用 super
22
+ 'constructor-super': 'error',
23
+
24
+ // generator 函数的 * 号前面无空格,后面有一个空格
25
+ // @unessential
26
+ 'generator-star-spacing': ['error', { before: false, after: true }],
27
+
28
+ // 禁止对类声明变量重新赋值
29
+ 'no-class-assign': 'error',
30
+
31
+ // 避免箭头函数与比较操作符产生混淆
32
+ // @unessential
33
+ 'no-confusing-arrow': 'error',
34
+
35
+ // 禁止修改 const 声明的变量
36
+ 'no-const-assign': 'error',
37
+
38
+ // 避免重复的类成员命名
39
+ 'no-dupe-class-members': 'error',
40
+
41
+ // 不要用多个 import 引入同一模块
42
+ // @reason replacedBy import/no-duplicates
43
+ 'no-duplicate-imports': 'off',
44
+
45
+ // 禁止使用 new Symbol
46
+ 'no-new-symbol': 'error',
47
+
48
+ // 禁止特定的 import
49
+ 'no-restricted-imports': [
50
+ 'off',
51
+ {
52
+ paths: [],
53
+ patterns: [],
54
+ },
55
+ ],
56
+
57
+ // 在 constructor 中,禁止在调用 super() 前使用 this 或 super 关键字
58
+ 'no-this-before-super': 'error',
59
+
60
+ // 对象的属性名不要使用无必要的计算属性
61
+ 'no-useless-computed-key': 'error',
62
+
63
+ // 避免不必要的 constructor
64
+ 'no-useless-constructor': 'error',
65
+
66
+ // 禁止在解构/import/export时进行无用的重命名
67
+ 'no-useless-rename': [
68
+ 'error',
69
+ {
70
+ ignoreDestructuring: false,
71
+ ignoreImport: false,
72
+ ignoreExport: false,
73
+ },
74
+ ],
75
+
76
+ // 使用 const 或 let 声明变量,不要使用 var
77
+ // @unessential
78
+ 'no-var': 'error',
79
+
80
+ // 使用对象属性和方法的简写语法
81
+ // @unessential
82
+ 'object-shorthand': [
83
+ 'error',
84
+ 'always',
85
+ {
86
+ ignoreConstructors: false,
87
+ avoidQuotes: true,
88
+ },
89
+ ],
90
+
91
+ // 回调函数使用箭头函数而不是匿名函数
92
+ // @unessential
93
+ 'prefer-arrow-callback': [
94
+ 'error',
95
+ {
96
+ allowNamedFunctions: false,
97
+ allowUnboundThis: true,
98
+ },
99
+ ],
100
+
101
+ // 优先使用 const,只有当变量会被重新赋值时才使用 let
102
+ // @unessential
103
+ 'prefer-const': [
104
+ 'error',
105
+ {
106
+ destructuring: 'any',
107
+ ignoreReadBeforeAssign: true,
108
+ },
109
+ ],
110
+
111
+ // 使用对象和数组的解构
112
+ 'prefer-destructuring': [
113
+ 'warn',
114
+ {
115
+ VariableDeclarator: {
116
+ array: false,
117
+ object: true,
118
+ },
119
+ AssignmentExpression: {
120
+ array: false,
121
+ object: false,
122
+ },
123
+ },
124
+ {
125
+ enforceForRenamedProperties: false,
126
+ },
127
+ ],
128
+
129
+ // 禁止使用 parseInt() 进行二、八、十六禁止转换
130
+ 'prefer-numeric-literals': 'off',
131
+
132
+ // 使用 rest 操作符替代 arguments 对象
133
+ 'prefer-rest-params': 'warn',
134
+
135
+ // 使用扩展运算符 ... 替代 apply()
136
+ 'prefer-spread': 'warn',
137
+
138
+ // 使用模板字符串替代字符串拼接
139
+ 'prefer-template': 'warn',
140
+
141
+ // generator 函数内必须有 yield 语句
142
+ 'require-yield': 'error',
143
+
144
+ // 剩余和扩展操作符与操作对象间不应有空格
145
+ 'rest-spread-spacing': ['error', 'never'],
146
+
147
+ // 为 import 排序
148
+ 'sort-imports': [
149
+ 'off',
150
+ {
151
+ ignoreCase: false,
152
+ ignoreMemberSort: false,
153
+ memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
154
+ },
155
+ ],
156
+
157
+ // 创建 Symbol 时必须传入参数
158
+ 'symbol-description': 'warn',
159
+
160
+ // 模板字符串中的大括号内部两侧无空格
161
+ // @unessential
162
+ 'template-curly-spacing': 'warn',
163
+
164
+ // yield* 表达式的 * 号前面无空格,后面有一个空格
165
+ // @unessential
166
+ 'yield-star-spacing': ['error', 'after'],
167
+ },
168
+ };
@@ -1,126 +1,126 @@
1
- module.exports = {
2
- rules: {
3
- // for 循环中的计数器应朝着正确方向移动
4
- 'for-direction': 'error',
5
-
6
- // getter 需要有返回值
7
- 'getter-return': ['error', { allowImplicit: true }],
8
-
9
- // 不要使用 async 函数作为 Promise 的 executor
10
- 'no-async-promise-executor': 'error',
11
-
12
- // 不要在循环中使用 await,应使用 Promise.all()
13
- 'no-await-in-loop': 'warn',
14
-
15
- // 不要与负零进行比较
16
- 'no-compare-neg-zero': 'error',
17
-
18
- // 不要在条件表达式中使用赋值语句
19
- 'no-cond-assign': ['error', 'always'],
20
-
21
- // 生产环境禁止使用 console
22
- 'no-console': 'warn',
23
-
24
- // 不要在条件表达式中使用常量
25
- 'no-constant-condition': 'warn',
26
-
27
- // 禁止在正则中使用 ctrl 键的 ASCII 码
28
- 'no-control-regex': 'off',
29
-
30
- // 禁止使用 debugger
31
- 'no-debugger': 'error',
32
-
33
- // 函数的参数列表中禁止出现重复命名的参数
34
- 'no-dupe-args': 'error',
35
-
36
- // 对象中禁止出现重复命名的 key
37
- 'no-dupe-keys': 'error',
38
-
39
- // switch 语句中禁止出现重复的 case
40
- 'no-duplicate-case': 'error',
41
-
42
- // 不要出现空代码块
43
- 'no-empty': 'error',
44
-
45
- // 禁止在正则中使用空字符集 [],这不能匹配任何字符,可能是 typo
46
- 'no-empty-character-class': 'error',
47
-
48
- // 禁止对 catch 的入参重新赋值
49
- 'no-ex-assign': 'error',
50
-
51
- // 避免不必要的布尔类型转换
52
- 'no-extra-boolean-cast': 'error',
53
-
54
- // 禁止不必要的小括号
55
- 'no-extra-parens': [
56
- 'off',
57
- 'all',
58
- {
59
- conditionalAssign: true,
60
- nestedBinaryExpressions: false,
61
- returnAssign: false,
62
- ignoreJSX: 'all', // delegate to eslint-plugin-react
63
- enforceForArrowConditionals: false,
64
- },
65
- ],
66
-
67
- // 禁止不必要的分号
68
- 'no-extra-semi': 'error',
69
-
70
- // 不要对函数声明重新赋值
71
- 'no-func-assign': 'error',
72
-
73
- // 不要在块中使用函数声明
74
- 'no-inner-declarations': 'error',
75
-
76
- // 禁止在 RegExp 构造函数中使用无效的正则表达式
77
- 'no-invalid-regexp': 'error',
78
-
79
- // 禁止不规则的空白符
80
- 'no-irregular-whitespace': 'error',
81
-
82
- // 禁止在正则的字符集语法 [] 中使用由多个字符点构成的字符
83
- 'no-misleading-character-class': 'error',
84
-
85
- // 禁止将全局对象 Math、JSON、Reflect 当作函数进行调用
86
- 'no-obj-calls': 'error',
87
-
88
- // 不要直接在对象上调用 Object.prototypes 上的方法
89
- // @unessential
90
- 'no-prototype-builtins': 'error',
91
-
92
- // 禁止在正则表达式中出现多个连续空格
93
- 'no-regex-spaces': 'error',
94
-
95
- // 禁用稀疏数组,如 var items = [,,];
96
- 'no-sparse-arrays': 'error',
97
-
98
- // 不要在普通字符串中出现模板字符串占位语法,如 "Hello ${name}!",旨在防错写。
99
- // 但不排除有时普通字符串内容就是这样,因此这条开为 warn 级别
100
- 'no-template-curly-in-string': 'warn',
101
-
102
- // 避免令人困惑的多行表达式,多是由不加分号导致
103
- 'no-unexpected-multiline': 'error',
104
-
105
- // 不要在 return 等语句之后出现不可达的代码
106
- 'no-unreachable': 'error',
107
-
108
- // 禁止在 finally 中出现控制流语句,如 return, throw, break 或 continue
109
- 'no-unsafe-finally': 'error',
110
-
111
- // 禁止对关系运算符左边的运算元使用否定操作符,包括 in 和 instanceof
112
- 'no-unsafe-negation': 'error',
113
-
114
- // 避免因使用 await 或 yield 导致的竞争性赋值
115
- 'require-atomic-updates': 'warn',
116
-
117
- // 使用 Number.isNaN(),而不是直接与 NaN 进行比较
118
- 'use-isnan': 'error',
119
-
120
- // 使用有效的 JSDoc 注释
121
- 'valid-jsdoc': 'off',
122
-
123
- // 同 typeof 表达式结果进行比较的值必须是有效的字符串,即 'undefined', 'object', 'boolean', 'number', 'string', 'function' 或 'symbol'
124
- 'valid-typeof': ['error', { requireStringLiterals: true }],
125
- },
126
- };
1
+ module.exports = {
2
+ rules: {
3
+ // for 循环中的计数器应朝着正确方向移动
4
+ 'for-direction': 'error',
5
+
6
+ // getter 需要有返回值
7
+ 'getter-return': ['error', { allowImplicit: true }],
8
+
9
+ // 不要使用 async 函数作为 Promise 的 executor
10
+ 'no-async-promise-executor': 'error',
11
+
12
+ // 不要在循环中使用 await,应使用 Promise.all()
13
+ 'no-await-in-loop': 'warn',
14
+
15
+ // 不要与负零进行比较
16
+ 'no-compare-neg-zero': 'error',
17
+
18
+ // 不要在条件表达式中使用赋值语句
19
+ 'no-cond-assign': ['error', 'always'],
20
+
21
+ // 生产环境禁止使用 console
22
+ 'no-console': 'warn',
23
+
24
+ // 不要在条件表达式中使用常量
25
+ 'no-constant-condition': 'warn',
26
+
27
+ // 禁止在正则中使用 ctrl 键的 ASCII 码
28
+ 'no-control-regex': 'off',
29
+
30
+ // 禁止使用 debugger
31
+ 'no-debugger': 'error',
32
+
33
+ // 函数的参数列表中禁止出现重复命名的参数
34
+ 'no-dupe-args': 'error',
35
+
36
+ // 对象中禁止出现重复命名的 key
37
+ 'no-dupe-keys': 'error',
38
+
39
+ // switch 语句中禁止出现重复的 case
40
+ 'no-duplicate-case': 'error',
41
+
42
+ // 不要出现空代码块
43
+ 'no-empty': 'error',
44
+
45
+ // 禁止在正则中使用空字符集 [],这不能匹配任何字符,可能是 typo
46
+ 'no-empty-character-class': 'error',
47
+
48
+ // 禁止对 catch 的入参重新赋值
49
+ 'no-ex-assign': 'error',
50
+
51
+ // 避免不必要的布尔类型转换
52
+ 'no-extra-boolean-cast': 'error',
53
+
54
+ // 禁止不必要的小括号
55
+ 'no-extra-parens': [
56
+ 'off',
57
+ 'all',
58
+ {
59
+ conditionalAssign: true,
60
+ nestedBinaryExpressions: false,
61
+ returnAssign: false,
62
+ ignoreJSX: 'all', // delegate to eslint-plugin-react
63
+ enforceForArrowConditionals: false,
64
+ },
65
+ ],
66
+
67
+ // 禁止不必要的分号
68
+ 'no-extra-semi': 'error',
69
+
70
+ // 不要对函数声明重新赋值
71
+ 'no-func-assign': 'error',
72
+
73
+ // 不要在块中使用函数声明
74
+ 'no-inner-declarations': 'error',
75
+
76
+ // 禁止在 RegExp 构造函数中使用无效的正则表达式
77
+ 'no-invalid-regexp': 'error',
78
+
79
+ // 禁止不规则的空白符
80
+ 'no-irregular-whitespace': 'error',
81
+
82
+ // 禁止在正则的字符集语法 [] 中使用由多个字符点构成的字符
83
+ 'no-misleading-character-class': 'error',
84
+
85
+ // 禁止将全局对象 Math、JSON、Reflect 当作函数进行调用
86
+ 'no-obj-calls': 'error',
87
+
88
+ // 不要直接在对象上调用 Object.prototypes 上的方法
89
+ // @unessential
90
+ 'no-prototype-builtins': 'error',
91
+
92
+ // 禁止在正则表达式中出现多个连续空格
93
+ 'no-regex-spaces': 'error',
94
+
95
+ // 禁用稀疏数组,如 var items = [,,];
96
+ 'no-sparse-arrays': 'error',
97
+
98
+ // 不要在普通字符串中出现模板字符串占位语法,如 "Hello ${name}!",旨在防错写。
99
+ // 但不排除有时普通字符串内容就是这样,因此这条开为 warn 级别
100
+ 'no-template-curly-in-string': 'warn',
101
+
102
+ // 避免令人困惑的多行表达式,多是由不加分号导致
103
+ 'no-unexpected-multiline': 'error',
104
+
105
+ // 不要在 return 等语句之后出现不可达的代码
106
+ 'no-unreachable': 'error',
107
+
108
+ // 禁止在 finally 中出现控制流语句,如 return, throw, break 或 continue
109
+ 'no-unsafe-finally': 'error',
110
+
111
+ // 禁止对关系运算符左边的运算元使用否定操作符,包括 in 和 instanceof
112
+ 'no-unsafe-negation': 'error',
113
+
114
+ // 避免因使用 await 或 yield 导致的竞争性赋值
115
+ 'require-atomic-updates': 'warn',
116
+
117
+ // 使用 Number.isNaN(),而不是直接与 NaN 进行比较
118
+ 'use-isnan': 'error',
119
+
120
+ // 使用有效的 JSDoc 注释
121
+ 'valid-jsdoc': 'off',
122
+
123
+ // 同 typeof 表达式结果进行比较的值必须是有效的字符串,即 'undefined', 'object', 'boolean', 'number', 'string', 'function' 或 'symbol'
124
+ 'valid-typeof': ['error', { requireStringLiterals: true }],
125
+ },
126
+ };
@@ -1,6 +1,6 @@
1
- module.exports = {
2
- rules: {
3
- // 不限制严格模式的使用
4
- strict: 'off',
5
- },
6
- };
1
+ module.exports = {
2
+ rules: {
3
+ // 不限制严格模式的使用
4
+ strict: 'off',
5
+ },
6
+ };