eslint-plugin-better-codes 1.2.11 → 1.4.11
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
CHANGED
|
@@ -46,7 +46,7 @@ module.exports = {
|
|
|
46
46
|
禁止提交注释掉的代码:
|
|
47
47
|
|
|
48
48
|
- 对于单行注释:累计行数大于等于minLines时报错。对于第一个字符为中文、大写英文字母、数字,不进行校验。如果最后面包含ignore-eslint,不进行校验(最多可以忽略minLines - 1次)
|
|
49
|
-
-
|
|
49
|
+
- 对于多行注释:单块累计行数或者累计块数大于等于minLines时报错,空格行、只包含\*的行、空行不计数。如果内容包含@param、@returns(函数注释),@D(d)escription(文件头注释),@C(c)omment(块状功能注释)不进行校验,注释的内容如果以中文、数字、大写英文字母开头,不进行校验
|
|
50
50
|
|
|
51
51
|
### function-with-try-catch
|
|
52
52
|
|
|
@@ -79,6 +79,7 @@ module.exports = {
|
|
|
79
79
|
|
|
80
80
|
强制使用可选链操作符(`?.`)来约束长表达式的点访问
|
|
81
81
|
|
|
82
|
+
针对赋值表达式 = 左半部分的表达式不会进行校验,将来进行针对性处理
|
|
82
83
|
## 许可证
|
|
83
84
|
|
|
84
85
|
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 (
|
|
@@ -8,6 +8,14 @@ function isFunctionComment(comment, isBlock = false) {
|
|
|
8
8
|
try {
|
|
9
9
|
// 去除前后空格
|
|
10
10
|
comment = comment.trim();
|
|
11
|
+
if (isBlock) {
|
|
12
|
+
// 块注释,前去除前面的例如* 换行 空格等无效代码
|
|
13
|
+
comment = comment
|
|
14
|
+
.trim()
|
|
15
|
+
.split("")
|
|
16
|
+
.filter(s => !!s && !["*", "\r", "\n"].includes(s) && !isEmptyStr(s))
|
|
17
|
+
.join("");
|
|
18
|
+
}
|
|
11
19
|
// 取第一个字符
|
|
12
20
|
const firstStr = comment[0];
|
|
13
21
|
// 判断第一个字符是否为中文
|
|
@@ -16,12 +24,7 @@ function isFunctionComment(comment, isBlock = false) {
|
|
|
16
24
|
const isCapitalEnglish = /^[A-Z]+$/.test(firstStr);
|
|
17
25
|
// 判断第一个字符是否为数字
|
|
18
26
|
const isNum = /^[0-9]+$/.test(firstStr);
|
|
19
|
-
if (
|
|
20
|
-
isChinese ||
|
|
21
|
-
isCapitalEnglish ||
|
|
22
|
-
isFuncComment(comment, isBlock) ||
|
|
23
|
-
isNum
|
|
24
|
-
) {
|
|
27
|
+
if (isChinese || isCapitalEnglish || isFuncComment(comment) || isNum) {
|
|
25
28
|
return true;
|
|
26
29
|
}
|
|
27
30
|
} catch (error) {
|
|
@@ -58,6 +61,19 @@ function isFuncComment(comment) {
|
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
|
|
64
|
+
/**
|
|
65
|
+
* 判断是否为空值字符串,例如' ', ' ', ' ', ' '
|
|
66
|
+
* @param {String} str - 要判断的字符串
|
|
67
|
+
* @returns {Boolean} 是否为空值字符串
|
|
68
|
+
*/
|
|
69
|
+
function isEmptyStr(str) {
|
|
70
|
+
try {
|
|
71
|
+
return !str || str.trim().length === 0;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.error(error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
61
77
|
module.exports = {
|
|
62
78
|
meta: {
|
|
63
79
|
type: "problem",
|
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.11",
|
|
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
|
}
|