eslint-plugin-better-codes 1.2.12 → 1.4.12
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/README.md +12 -0
- package/libs/long-expression-with-optional-chain-code.js +30 -4
- package/package.json +14 -14
package/README.md
CHANGED
|
@@ -79,6 +79,18 @@ module.exports = {
|
|
|
79
79
|
|
|
80
80
|
强制使用可选链操作符(`?.`)来约束长表达式的点访问
|
|
81
81
|
|
|
82
|
+
针对赋值表达式 = 左半部分的表达式不会进行校验,将来进行针对性处理
|
|
82
83
|
## 许可证
|
|
83
84
|
|
|
85
|
+
## 更新日志
|
|
86
|
+
|
|
87
|
+
### 功能新增
|
|
88
|
+
|
|
89
|
+
### Bug修复
|
|
90
|
+
|
|
91
|
+
#### 1.4.12
|
|
92
|
+
|
|
93
|
+
修复`long-expression-with-optional-chain`规则中对于例如`obj.user.getName().num`中的`getName().num`不会进行校验的情况
|
|
94
|
+
|
|
95
|
+
|
|
84
96
|
MIT
|
|
@@ -19,6 +19,21 @@ module.exports = {
|
|
|
19
19
|
return {
|
|
20
20
|
MemberExpression(node) {
|
|
21
21
|
try {
|
|
22
|
+
// 如果当前成员表达式出现在赋值语句 `=` 的左侧,则跳过校验
|
|
23
|
+
// 向上遍历祖先节点,若遇到使当前节点位于 AssignmentExpression.left 的 '=' 赋值,则直接返回
|
|
24
|
+
let anc = node;
|
|
25
|
+
while (anc && anc.parent) {
|
|
26
|
+
const p = anc.parent;
|
|
27
|
+
if (
|
|
28
|
+
p.type === "AssignmentExpression" &&
|
|
29
|
+
p.operator === "=" &&
|
|
30
|
+
p.left === anc
|
|
31
|
+
) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
anc = p;
|
|
35
|
+
}
|
|
36
|
+
|
|
22
37
|
// 只在最外层的 member 表达式上检查一次,避免重复报告
|
|
23
38
|
const parent = node.parent;
|
|
24
39
|
if (
|
|
@@ -28,12 +43,23 @@ module.exports = {
|
|
|
28
43
|
)
|
|
29
44
|
return;
|
|
30
45
|
|
|
31
|
-
// 收集从当前节点向内的连续 MemberExpression
|
|
46
|
+
// 收集从当前节点向内的连续 MemberExpression 链和调用表达式(CallExpression)
|
|
32
47
|
const chain = [];
|
|
33
48
|
let cur = node;
|
|
34
|
-
while (cur
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
while (cur) {
|
|
50
|
+
if (cur.type === "MemberExpression") { // MemberExpression 链
|
|
51
|
+
chain.push(cur);
|
|
52
|
+
const obj = cur.object;
|
|
53
|
+
if (obj && obj.type === "CallExpression") { // CallExpression
|
|
54
|
+
cur = obj.callee;
|
|
55
|
+
} else {
|
|
56
|
+
cur = obj;
|
|
57
|
+
}
|
|
58
|
+
} else if (cur.type === "CallExpression") {
|
|
59
|
+
cur = cur.callee;
|
|
60
|
+
} else {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
37
63
|
}
|
|
38
64
|
|
|
39
65
|
// 只统计使用点访问(computed === false)的成员表达式
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "eslint-plugin-better-codes",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"main": "index.js",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"test": "npx eslint ./test.js"
|
|
7
|
-
},
|
|
8
|
-
"keywords": [
|
|
9
|
-
"eslint",
|
|
10
|
-
"eslint-plugin"
|
|
11
|
-
],
|
|
12
|
-
"author": "",
|
|
13
|
-
"license": "MIT",
|
|
14
|
-
"description": "eslint代码规范校验自定义插件合集,提升代码质量"
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-plugin-better-codes",
|
|
3
|
+
"version": "1.4.12",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "npx eslint ./test.js"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [
|
|
9
|
+
"eslint",
|
|
10
|
+
"eslint-plugin"
|
|
11
|
+
],
|
|
12
|
+
"author": "",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"description": "eslint代码规范校验自定义插件合集,提升代码质量"
|
|
15
15
|
}
|