@lsby/eslint-plugin 0.0.6 → 0.0.8
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/index.js +1 -0
- package/lib/rules/no-broken-link.js +31 -31
- package/lib/rules/no-negation.js +2 -2
- package/lib/rules/no-null.js +27 -0
- package/lib/rules/prefer-let.js +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
meta: {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
type: 'problem', // 规则类型,可以是 "problem", "suggestion", 或 "layout"
|
|
4
|
+
docs: {
|
|
5
|
+
description: 'Check for broken {@link} references in comments',
|
|
6
|
+
category: 'Possible Errors',
|
|
7
|
+
recommended: false,
|
|
8
|
+
},
|
|
9
|
+
schema: [], // 规则的选项配置
|
|
10
10
|
},
|
|
11
|
-
create: function(context) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
create: function (context) {
|
|
12
|
+
return {
|
|
13
|
+
Program(node) {
|
|
14
|
+
const sourceCode = context.getSourceCode()
|
|
15
|
+
const comments = sourceCode.getAllComments()
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
comments.forEach((comment) => {
|
|
18
|
+
const matches = comment.value.match(/\{@link\s+([^\s}]+)\s*\}/g)
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if (matches) {
|
|
21
|
+
matches.forEach((link) => {
|
|
22
|
+
const identifier = link.match(/\{@link\s+([^\s}]+)\s*\}/)[1]
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const variables = context.getScope().variables
|
|
25
|
+
const isDefined = variables.some((variable) => variable.name === identifier)
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
});
|
|
27
|
+
if (!isDefined) {
|
|
28
|
+
context.report({
|
|
29
|
+
node: comment,
|
|
30
|
+
message: `{@link}中的标识符“${identifier}”没有定义。`,
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
})
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
35
|
+
})
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
}
|
package/lib/rules/no-negation.js
CHANGED
|
@@ -2,10 +2,10 @@ module.exports = {
|
|
|
2
2
|
create(context) {
|
|
3
3
|
return {
|
|
4
4
|
UnaryExpression(node) {
|
|
5
|
-
if (node.operator === '!') {
|
|
5
|
+
if (node.operator === '!' && !(node.argument.type === 'Literal' && typeof node.argument.value === 'boolean')) {
|
|
6
6
|
context.report({
|
|
7
7
|
node,
|
|
8
|
-
message: "
|
|
8
|
+
message: "禁止对非布尔值使用 '!' 运算符。",
|
|
9
9
|
})
|
|
10
10
|
}
|
|
11
11
|
},
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: 'suggestion', // 表示这是个建议类型的规则
|
|
4
|
+
docs: {
|
|
5
|
+
description: 'Disallow usage of null and replace it with undefined',
|
|
6
|
+
category: 'Best Practices',
|
|
7
|
+
recommended: false,
|
|
8
|
+
},
|
|
9
|
+
fixable: 'code', // 支持自动修复
|
|
10
|
+
schema: [], // 无额外配置
|
|
11
|
+
},
|
|
12
|
+
create(context) {
|
|
13
|
+
return {
|
|
14
|
+
Literal(node) {
|
|
15
|
+
if (node.value === null) {
|
|
16
|
+
context.report({
|
|
17
|
+
node,
|
|
18
|
+
message: '不允许使用‘null’。使用‘undefined’代替。',
|
|
19
|
+
fix(fixer) {
|
|
20
|
+
return fixer.replaceText(node, 'undefined')
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
}
|
package/lib/rules/prefer-let.js
CHANGED