@lsby/eslint-config 0.3.2 → 0.3.3
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/dist/cjs/index.cjs +64 -36
- package/dist/esm/index.js +64 -36
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -63,18 +63,14 @@ var ts\u5B89\u5168\u6027 = {
|
|
|
63
63
|
es: import_eslint_plugin_es.default
|
|
64
64
|
},
|
|
65
65
|
rules: {
|
|
66
|
+
// ==================== 避免安全漏洞 ====================
|
|
66
67
|
// 拒绝any
|
|
67
68
|
"@typescript-eslint/no-unsafe-assignment": "error",
|
|
68
|
-
// 检查无意义的比较
|
|
69
|
-
"@typescript-eslint/no-unnecessary-condition": ["error", { allowConstantLoopConditions: true }],
|
|
70
|
-
// 拒绝浮动promise
|
|
71
|
-
"@typescript-eslint/no-floating-promises": "error",
|
|
72
|
-
// 必须标注函数返回类型
|
|
73
|
-
"@typescript-eslint/explicit-function-return-type": ["error", {}],
|
|
74
|
-
// 必须为类的属性和方法显式写访问修饰符
|
|
75
|
-
"@typescript-eslint/explicit-member-accessibility": ["error", { accessibility: "explicit" }],
|
|
76
69
|
// 禁止类属性使用确定赋值断言语法
|
|
77
70
|
"@lsby/no-definite-assignment-assertion": "error",
|
|
71
|
+
// 禁止非空断言运算符
|
|
72
|
+
"@typescript-eslint/no-non-null-assertion": "error",
|
|
73
|
+
// ==================== 检查无意义的写法 ====================
|
|
78
74
|
// 禁止无意义的类型断言
|
|
79
75
|
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
|
80
76
|
// 检查没有使用的变量
|
|
@@ -88,32 +84,24 @@ var ts\u5B89\u5168\u6027 = {
|
|
|
88
84
|
varsIgnorePattern: "^_"
|
|
89
85
|
}
|
|
90
86
|
],
|
|
91
|
-
//
|
|
92
|
-
"@typescript-eslint/no-
|
|
93
|
-
//
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
|
|
87
|
+
// 检查无意义的比较
|
|
88
|
+
"@typescript-eslint/no-unnecessary-condition": ["error", { allowConstantLoopConditions: true }],
|
|
89
|
+
// ==================== 异步安全 ====================
|
|
90
|
+
// 拒绝浮动promise
|
|
91
|
+
"@typescript-eslint/no-floating-promises": "error",
|
|
92
|
+
// await必须要等待thenable
|
|
93
|
+
"@typescript-eslint/await-thenable": "error",
|
|
94
|
+
// ==================== 避免陷阱 ====================
|
|
95
|
+
// 禁止使用Object.assign, 它的行为是浅拷贝, 会污染第一个参数
|
|
96
|
+
"es/no-object-assign": "error",
|
|
97
|
+
// ==================== 信息需要写完整 ====================
|
|
98
|
+
// 必须标注函数返回类型
|
|
99
|
+
"@typescript-eslint/explicit-function-return-type": ["error", {}],
|
|
100
|
+
// 必须为类的属性和方法显式写访问修饰符
|
|
101
|
+
"@typescript-eslint/explicit-member-accessibility": ["error", { accessibility: "explicit" }],
|
|
102
|
+
// ==================== 不依赖非布尔条件 ====================
|
|
99
103
|
// 永远使用 === 而不是 ==, 在一些情况下能自动修复
|
|
100
104
|
eqeqeq: ["error", "always"],
|
|
101
|
-
// 禁止 else
|
|
102
|
-
// else 表示"除当前条件外的所有可能"
|
|
103
|
-
// 当状态集合未来扩展时, 依然会被包含在else分支里, 导致状态遗漏却无任何报错
|
|
104
|
-
// 应当使用提早返回 或 switch + 穷尽检查
|
|
105
|
-
"no-else-return": "error",
|
|
106
|
-
"@lsby/no-else": "error",
|
|
107
|
-
"@typescript-eslint/switch-exhaustiveness-check": "error",
|
|
108
|
-
// 在除了条件表达式的地方, 使用??而不是||
|
|
109
|
-
"@typescript-eslint/prefer-nullish-coalescing": "error",
|
|
110
|
-
// 禁止对非布尔值使用取反
|
|
111
|
-
// 对于 number | null 的值x, if(!x)在x等于null和0时都会触发, 这可能是非预期的
|
|
112
|
-
"@lsby/no-negation": "error",
|
|
113
|
-
// 禁止使用undefined
|
|
114
|
-
// 因为我们不需要两个空值, 总是使用null会更明确
|
|
115
|
-
// 但js的原生方法返回的都是undefined, 这时候用void 0代替
|
|
116
|
-
"no-undefined": "error",
|
|
117
105
|
// 条件里必须明确写布尔值, 以避免if('')被理解为假的情况
|
|
118
106
|
"@typescript-eslint/strict-boolean-expressions": [
|
|
119
107
|
"error",
|
|
@@ -123,10 +111,50 @@ var ts\u5B89\u5168\u6027 = {
|
|
|
123
111
|
allowNullableObject: false
|
|
124
112
|
}
|
|
125
113
|
],
|
|
126
|
-
//
|
|
127
|
-
"
|
|
128
|
-
//
|
|
129
|
-
|
|
114
|
+
// 在除了条件表达式的地方, 使用??而不是||
|
|
115
|
+
"@typescript-eslint/prefer-nullish-coalescing": "error",
|
|
116
|
+
// 禁止对非布尔值使用取反
|
|
117
|
+
// 对于 number | null 的值x, if(!x)在x等于null和0时都会触发, 这可能是非预期的
|
|
118
|
+
"@lsby/no-negation": "error",
|
|
119
|
+
// ==================== 优化心智 ====================
|
|
120
|
+
// 禁止使用undefined
|
|
121
|
+
// 因为我们不需要两个空值, 总是使用null会更明确
|
|
122
|
+
// 但js的原生方法返回的都是undefined, 这时候用void 0代替
|
|
123
|
+
"no-undefined": "error",
|
|
124
|
+
// ==================== 反虚假安全 ====================
|
|
125
|
+
// 永远使用let, 拒绝var和const, 并自动修复
|
|
126
|
+
// 原因:
|
|
127
|
+
// 1 抽象泄漏
|
|
128
|
+
// const只约束原语值和指针不变, 不约束引用值本身不变
|
|
129
|
+
// 使用者要搞懂什么可变什么不可变, 必须理解原语值和引用值的区别, 以及变量在内存上的机制
|
|
130
|
+
// 这种"必须搞懂背后的原理才能正常使用"的情况是显然的抽象泄漏
|
|
131
|
+
// 2 误导
|
|
132
|
+
// 对于新人, 很容易被误解, 导致引用值被意外修改
|
|
133
|
+
// 3 心智成本
|
|
134
|
+
// 实际使用时, 即使是const声明值, 也必须确认其是否为引用类型, 若是则还是需要确认所有可能的修改
|
|
135
|
+
// 这与let无异, 反而增加了心智成本
|
|
136
|
+
// **错误的信息比没有信息更糟糕**
|
|
137
|
+
// 替代:
|
|
138
|
+
// 如果真的需要表达不变, 应该使用类型等级的递归只读, 建模隐藏等方法
|
|
139
|
+
// 这虽然复杂度更高, 但可以真正保证安全
|
|
140
|
+
// 这也迫使程序员思考是否真的有必要这样设计, 而不是"随手一用", 提供一个"虚假的安全感"
|
|
141
|
+
"@lsby/prefer-let": "error",
|
|
142
|
+
// ==================== 反兜底 ====================
|
|
143
|
+
// 这几条规则的意图是, 避免当状态扩展后, 新状态被默默归类到兜底分支中
|
|
144
|
+
// 例如, else 表示"除当前条件外的所有可能"
|
|
145
|
+
// 但当状态在未来被扩展时, 扩展的状态依然会被包含在else分支里, 导致状态遗漏却无任何报错
|
|
146
|
+
// 此时, 应该考虑使用提前返回或switch穷尽所有可能, 而不是提供一个默默吃掉所有新状态的兜底逻辑
|
|
147
|
+
// 这几条规则包括:
|
|
148
|
+
// - 修剪可以提前返回的else
|
|
149
|
+
// - 不允许else
|
|
150
|
+
// - switch的case必须穷尽
|
|
151
|
+
// - 不允许switch的default分支
|
|
152
|
+
// - 不允许连续的if判定相同条件
|
|
153
|
+
"no-else-return": "error",
|
|
154
|
+
"@lsby/no-else": "error",
|
|
155
|
+
"@typescript-eslint/switch-exhaustiveness-check": "error",
|
|
156
|
+
"@lsby/no-switch-default": "error",
|
|
157
|
+
"@lsby/prefer-switch-over-multi-if": "error"
|
|
130
158
|
}
|
|
131
159
|
};
|
|
132
160
|
var jsDoc\u5B89\u5168\u6027 = {
|
package/dist/esm/index.js
CHANGED
|
@@ -23,18 +23,14 @@ var ts\u5B89\u5168\u6027 = {
|
|
|
23
23
|
es: eslintPluginEs
|
|
24
24
|
},
|
|
25
25
|
rules: {
|
|
26
|
+
// ==================== 避免安全漏洞 ====================
|
|
26
27
|
// 拒绝any
|
|
27
28
|
"@typescript-eslint/no-unsafe-assignment": "error",
|
|
28
|
-
// 检查无意义的比较
|
|
29
|
-
"@typescript-eslint/no-unnecessary-condition": ["error", { allowConstantLoopConditions: true }],
|
|
30
|
-
// 拒绝浮动promise
|
|
31
|
-
"@typescript-eslint/no-floating-promises": "error",
|
|
32
|
-
// 必须标注函数返回类型
|
|
33
|
-
"@typescript-eslint/explicit-function-return-type": ["error", {}],
|
|
34
|
-
// 必须为类的属性和方法显式写访问修饰符
|
|
35
|
-
"@typescript-eslint/explicit-member-accessibility": ["error", { accessibility: "explicit" }],
|
|
36
29
|
// 禁止类属性使用确定赋值断言语法
|
|
37
30
|
"@lsby/no-definite-assignment-assertion": "error",
|
|
31
|
+
// 禁止非空断言运算符
|
|
32
|
+
"@typescript-eslint/no-non-null-assertion": "error",
|
|
33
|
+
// ==================== 检查无意义的写法 ====================
|
|
38
34
|
// 禁止无意义的类型断言
|
|
39
35
|
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
|
40
36
|
// 检查没有使用的变量
|
|
@@ -48,32 +44,24 @@ var ts\u5B89\u5168\u6027 = {
|
|
|
48
44
|
varsIgnorePattern: "^_"
|
|
49
45
|
}
|
|
50
46
|
],
|
|
51
|
-
//
|
|
52
|
-
"@typescript-eslint/no-
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
// 检查无意义的比较
|
|
48
|
+
"@typescript-eslint/no-unnecessary-condition": ["error", { allowConstantLoopConditions: true }],
|
|
49
|
+
// ==================== 异步安全 ====================
|
|
50
|
+
// 拒绝浮动promise
|
|
51
|
+
"@typescript-eslint/no-floating-promises": "error",
|
|
52
|
+
// await必须要等待thenable
|
|
53
|
+
"@typescript-eslint/await-thenable": "error",
|
|
54
|
+
// ==================== 避免陷阱 ====================
|
|
55
|
+
// 禁止使用Object.assign, 它的行为是浅拷贝, 会污染第一个参数
|
|
56
|
+
"es/no-object-assign": "error",
|
|
57
|
+
// ==================== 信息需要写完整 ====================
|
|
58
|
+
// 必须标注函数返回类型
|
|
59
|
+
"@typescript-eslint/explicit-function-return-type": ["error", {}],
|
|
60
|
+
// 必须为类的属性和方法显式写访问修饰符
|
|
61
|
+
"@typescript-eslint/explicit-member-accessibility": ["error", { accessibility: "explicit" }],
|
|
62
|
+
// ==================== 不依赖非布尔条件 ====================
|
|
59
63
|
// 永远使用 === 而不是 ==, 在一些情况下能自动修复
|
|
60
64
|
eqeqeq: ["error", "always"],
|
|
61
|
-
// 禁止 else
|
|
62
|
-
// else 表示"除当前条件外的所有可能"
|
|
63
|
-
// 当状态集合未来扩展时, 依然会被包含在else分支里, 导致状态遗漏却无任何报错
|
|
64
|
-
// 应当使用提早返回 或 switch + 穷尽检查
|
|
65
|
-
"no-else-return": "error",
|
|
66
|
-
"@lsby/no-else": "error",
|
|
67
|
-
"@typescript-eslint/switch-exhaustiveness-check": "error",
|
|
68
|
-
// 在除了条件表达式的地方, 使用??而不是||
|
|
69
|
-
"@typescript-eslint/prefer-nullish-coalescing": "error",
|
|
70
|
-
// 禁止对非布尔值使用取反
|
|
71
|
-
// 对于 number | null 的值x, if(!x)在x等于null和0时都会触发, 这可能是非预期的
|
|
72
|
-
"@lsby/no-negation": "error",
|
|
73
|
-
// 禁止使用undefined
|
|
74
|
-
// 因为我们不需要两个空值, 总是使用null会更明确
|
|
75
|
-
// 但js的原生方法返回的都是undefined, 这时候用void 0代替
|
|
76
|
-
"no-undefined": "error",
|
|
77
65
|
// 条件里必须明确写布尔值, 以避免if('')被理解为假的情况
|
|
78
66
|
"@typescript-eslint/strict-boolean-expressions": [
|
|
79
67
|
"error",
|
|
@@ -83,10 +71,50 @@ var ts\u5B89\u5168\u6027 = {
|
|
|
83
71
|
allowNullableObject: false
|
|
84
72
|
}
|
|
85
73
|
],
|
|
86
|
-
//
|
|
87
|
-
"
|
|
88
|
-
//
|
|
89
|
-
|
|
74
|
+
// 在除了条件表达式的地方, 使用??而不是||
|
|
75
|
+
"@typescript-eslint/prefer-nullish-coalescing": "error",
|
|
76
|
+
// 禁止对非布尔值使用取反
|
|
77
|
+
// 对于 number | null 的值x, if(!x)在x等于null和0时都会触发, 这可能是非预期的
|
|
78
|
+
"@lsby/no-negation": "error",
|
|
79
|
+
// ==================== 优化心智 ====================
|
|
80
|
+
// 禁止使用undefined
|
|
81
|
+
// 因为我们不需要两个空值, 总是使用null会更明确
|
|
82
|
+
// 但js的原生方法返回的都是undefined, 这时候用void 0代替
|
|
83
|
+
"no-undefined": "error",
|
|
84
|
+
// ==================== 反虚假安全 ====================
|
|
85
|
+
// 永远使用let, 拒绝var和const, 并自动修复
|
|
86
|
+
// 原因:
|
|
87
|
+
// 1 抽象泄漏
|
|
88
|
+
// const只约束原语值和指针不变, 不约束引用值本身不变
|
|
89
|
+
// 使用者要搞懂什么可变什么不可变, 必须理解原语值和引用值的区别, 以及变量在内存上的机制
|
|
90
|
+
// 这种"必须搞懂背后的原理才能正常使用"的情况是显然的抽象泄漏
|
|
91
|
+
// 2 误导
|
|
92
|
+
// 对于新人, 很容易被误解, 导致引用值被意外修改
|
|
93
|
+
// 3 心智成本
|
|
94
|
+
// 实际使用时, 即使是const声明值, 也必须确认其是否为引用类型, 若是则还是需要确认所有可能的修改
|
|
95
|
+
// 这与let无异, 反而增加了心智成本
|
|
96
|
+
// **错误的信息比没有信息更糟糕**
|
|
97
|
+
// 替代:
|
|
98
|
+
// 如果真的需要表达不变, 应该使用类型等级的递归只读, 建模隐藏等方法
|
|
99
|
+
// 这虽然复杂度更高, 但可以真正保证安全
|
|
100
|
+
// 这也迫使程序员思考是否真的有必要这样设计, 而不是"随手一用", 提供一个"虚假的安全感"
|
|
101
|
+
"@lsby/prefer-let": "error",
|
|
102
|
+
// ==================== 反兜底 ====================
|
|
103
|
+
// 这几条规则的意图是, 避免当状态扩展后, 新状态被默默归类到兜底分支中
|
|
104
|
+
// 例如, else 表示"除当前条件外的所有可能"
|
|
105
|
+
// 但当状态在未来被扩展时, 扩展的状态依然会被包含在else分支里, 导致状态遗漏却无任何报错
|
|
106
|
+
// 此时, 应该考虑使用提前返回或switch穷尽所有可能, 而不是提供一个默默吃掉所有新状态的兜底逻辑
|
|
107
|
+
// 这几条规则包括:
|
|
108
|
+
// - 修剪可以提前返回的else
|
|
109
|
+
// - 不允许else
|
|
110
|
+
// - switch的case必须穷尽
|
|
111
|
+
// - 不允许switch的default分支
|
|
112
|
+
// - 不允许连续的if判定相同条件
|
|
113
|
+
"no-else-return": "error",
|
|
114
|
+
"@lsby/no-else": "error",
|
|
115
|
+
"@typescript-eslint/switch-exhaustiveness-check": "error",
|
|
116
|
+
"@lsby/no-switch-default": "error",
|
|
117
|
+
"@lsby/prefer-switch-over-multi-if": "error"
|
|
90
118
|
}
|
|
91
119
|
};
|
|
92
120
|
var jsDoc\u5B89\u5168\u6027 = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lsby/eslint-config",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"require": "./dist/cjs/index.cjs",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"tsup": "^8.3.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@lsby/eslint-plugin": "^0.0.
|
|
33
|
+
"@lsby/eslint-plugin": "^0.0.17",
|
|
34
34
|
"@types/eslint": "^9.6.1",
|
|
35
35
|
"eslint": "^8.57.0",
|
|
36
36
|
"eslint-config-prettier": "^9.1.0",
|