@lsby/eslint-plugin 0.1.0 → 0.2.0
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.
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
declare const rule:
|
|
1
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
declare const rule: TSESLint.RuleModule<'noNegationOnNonBoolean', []>;
|
|
3
3
|
export default rule;
|
|
@@ -12,13 +12,14 @@ const rule = {
|
|
|
12
12
|
messages: { noNegationOnNonBoolean: '禁止对非布尔值使用 "!" 运算符' },
|
|
13
13
|
schema: [],
|
|
14
14
|
},
|
|
15
|
+
defaultOptions: [],
|
|
15
16
|
create(context) {
|
|
16
17
|
return {
|
|
17
18
|
UnaryExpression(node) {
|
|
18
19
|
if (node.operator !== '!')
|
|
19
20
|
return;
|
|
20
|
-
const parserServices = context.parserServices;
|
|
21
|
-
if (!parserServices)
|
|
21
|
+
const parserServices = context.sourceCode?.parserServices || context.parserServices;
|
|
22
|
+
if (!parserServices || !parserServices.program || !parserServices.esTreeNodeToTSNodeMap)
|
|
22
23
|
return;
|
|
23
24
|
const typeChecker = parserServices.program.getTypeChecker();
|
|
24
25
|
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node.argument);
|
|
@@ -30,8 +30,9 @@ const rule = {
|
|
|
30
30
|
if (node.test.type === 'BinaryExpression' && (node.test.operator === '===' || node.test.operator === '==')) {
|
|
31
31
|
const { left, right } = node.test;
|
|
32
32
|
// 使用 TypeScript 类型检查器检查类型
|
|
33
|
-
const parserServices = context.parserServices
|
|
34
|
-
|
|
33
|
+
const parserServices = context.parserServices ||
|
|
34
|
+
context.sourceCode?.parserServices;
|
|
35
|
+
if (!parserServices || !parserServices.program || !parserServices.esTreeNodeToTSNodeMap)
|
|
35
36
|
return;
|
|
36
37
|
const typeChecker = parserServices.program.getTypeChecker();
|
|
37
38
|
// 获取比较的主体(可能是左侧或右侧,且不是字面量)
|
package/package.json
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lsby/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/lsby/eslint-plugin.git"
|
|
7
|
+
},
|
|
4
8
|
"main": "dist/index.js",
|
|
5
9
|
"types": "dist/index.d.ts",
|
|
6
10
|
"files": [
|
|
@@ -16,26 +20,22 @@
|
|
|
16
20
|
"test": "npm run build && mocha test/**/*.test.js"
|
|
17
21
|
},
|
|
18
22
|
"devDependencies": {
|
|
19
|
-
"@ianvs/prettier-plugin-sort-imports": "^4.
|
|
20
|
-
"@types/eslint": "^
|
|
23
|
+
"@ianvs/prettier-plugin-sort-imports": "^4.7.0",
|
|
24
|
+
"@types/eslint": "^9.6.1",
|
|
21
25
|
"@types/estree": "^1.0.8",
|
|
22
|
-
"@types/node": "^
|
|
23
|
-
"@typescript-eslint/parser": "^8.
|
|
24
|
-
"@typescript-eslint/utils": "^8.
|
|
26
|
+
"@types/node": "^25.0.6",
|
|
27
|
+
"@typescript-eslint/parser": "^8.52.0",
|
|
28
|
+
"@typescript-eslint/utils": "^8.52.0",
|
|
25
29
|
"bumpp": "^9.5.1",
|
|
26
30
|
"chai": "^5.1.1",
|
|
27
31
|
"mocha": "^10.7.3",
|
|
28
32
|
"prettier": "^3.7.4",
|
|
29
33
|
"prettier-plugin-packagejson": "^2.5.20",
|
|
30
34
|
"rimraf": "^6.1.2",
|
|
31
|
-
"typescript": "^5.3
|
|
35
|
+
"typescript": "^5.9.3"
|
|
32
36
|
},
|
|
33
37
|
"peerDependencies": {
|
|
34
|
-
"eslint": "^
|
|
38
|
+
"eslint": "^9.39.2"
|
|
35
39
|
},
|
|
36
|
-
"packageManager": "pnpm@9.5.0"
|
|
37
|
-
"repository": {
|
|
38
|
-
"type": "git",
|
|
39
|
-
"url": "https://github.com/lsby/eslint-plugin.git"
|
|
40
|
-
}
|
|
40
|
+
"packageManager": "pnpm@9.5.0"
|
|
41
41
|
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// jsdoc的link必须存在
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const rule = {
|
|
5
|
-
meta: {
|
|
6
|
-
type: 'problem',
|
|
7
|
-
docs: { description: '禁止在 JSDoc 注解中使用未定义的 {@link} 引用' },
|
|
8
|
-
messages: { undefinedLink: '{@link} 中的标识符 "{{identifier}}" 未定义' },
|
|
9
|
-
schema: [],
|
|
10
|
-
},
|
|
11
|
-
create(context) {
|
|
12
|
-
return {
|
|
13
|
-
Program(node) {
|
|
14
|
-
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
15
|
-
const comments = sourceCode.getAllComments?.() || [];
|
|
16
|
-
comments.forEach((comment) => {
|
|
17
|
-
const matches = comment.value.match(/\{@link\s+([^\s}]+)\s*\}/g);
|
|
18
|
-
if (matches) {
|
|
19
|
-
matches.forEach((link) => {
|
|
20
|
-
const identifier = link.match(/\{@link\s+([^\s}]+)\s*\}/)[1];
|
|
21
|
-
const variables = context.getScope().variables;
|
|
22
|
-
const isDefined = variables.some((variable) => variable.name === identifier);
|
|
23
|
-
if (!isDefined) {
|
|
24
|
-
context.report({ node, messageId: 'undefinedLink', data: { identifier } });
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
exports.default = rule;
|