eslint-plugin-complete 1.0.4 → 1.0.6
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-explicit-array-loops.d.ts","sourceRoot":"","sources":["../../src/rules/no-explicit-array-loops.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"no-explicit-array-loops.d.ts","sourceRoot":"","sources":["../../src/rules/no-explicit-array-loops.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAKvE,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAE3C,eAAO,MAAM,oBAAoB,+HAyJ/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-mutable-return.d.ts","sourceRoot":"","sources":["../../src/rules/no-mutable-return.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"no-mutable-return.d.ts","sourceRoot":"","sources":["../../src/rules/no-mutable-return.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAMvD,KAAK,UAAU,GAAG,cAAc,GAAG,YAAY,GAAG,YAAY,CAAC;AAE/D,eAAO,MAAM,eAAe,wHAsD1B,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isTypeReferenceType } from "@typescript-eslint/type-utils";
|
|
1
2
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
3
|
import { getTypeName, unionTypeParts } from "../typeUtils.js";
|
|
3
4
|
import { createRule } from "../utils.js";
|
|
@@ -21,24 +22,27 @@ export const noMutableReturn = createRule({
|
|
|
21
22
|
create(context) {
|
|
22
23
|
const parserServices = ESLintUtils.getParserServices(context);
|
|
23
24
|
const checker = parserServices.program.getTypeChecker();
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
}
|
|
25
|
+
function checkReturnType(node) {
|
|
26
|
+
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
|
|
27
|
+
const type = checker.getTypeAtLocation(tsNode);
|
|
28
|
+
const signatures = type.getCallSignatures();
|
|
29
|
+
for (const signature of signatures) {
|
|
30
|
+
const returnType = signature.getReturnType();
|
|
31
|
+
for (const t of unionTypeParts(returnType)) {
|
|
32
|
+
const messageId = getErrorMessageId(t);
|
|
33
|
+
if (messageId !== undefined) {
|
|
34
|
+
context.report({
|
|
35
|
+
loc: node.loc,
|
|
36
|
+
messageId,
|
|
37
|
+
});
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
|
-
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
FunctionDeclaration: checkReturnType,
|
|
44
|
+
FunctionExpression: checkReturnType,
|
|
45
|
+
ArrowFunctionExpression: checkReturnType,
|
|
42
46
|
};
|
|
43
47
|
},
|
|
44
48
|
});
|
|
@@ -47,6 +51,15 @@ function getErrorMessageId(type) {
|
|
|
47
51
|
if (typeName === undefined) {
|
|
48
52
|
return undefined;
|
|
49
53
|
}
|
|
54
|
+
// Handle unwrapping promises.
|
|
55
|
+
if (typeName === "Promise" &&
|
|
56
|
+
isTypeReferenceType(type) &&
|
|
57
|
+
type.typeArguments !== undefined) {
|
|
58
|
+
const typeArgument = type.typeArguments[0];
|
|
59
|
+
if (typeArgument !== undefined) {
|
|
60
|
+
return getErrorMessageId(typeArgument);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
50
63
|
// This would be "ReadonlyMap" if it was the read-only version.
|
|
51
64
|
if (typeName === "Map") {
|
|
52
65
|
return "mutableMap";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-complete",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "An ESLint plugin that contains useful rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -44,18 +44,18 @@
|
|
|
44
44
|
"test": "jest"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@typescript-eslint/type-utils": "^8.
|
|
48
|
-
"@typescript-eslint/utils": "^8.
|
|
49
|
-
"typescript-eslint": "^8.
|
|
47
|
+
"@typescript-eslint/type-utils": "^8.8.1",
|
|
48
|
+
"@typescript-eslint/utils": "^8.8.1",
|
|
49
|
+
"typescript-eslint": "^8.8.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@babel/core": "^7.25.
|
|
53
|
-
"@babel/preset-env": "^7.25.
|
|
54
|
-
"@babel/preset-typescript": "^7.
|
|
52
|
+
"@babel/core": "^7.25.7",
|
|
53
|
+
"@babel/preset-env": "^7.25.7",
|
|
54
|
+
"@babel/preset-typescript": "^7.25.7",
|
|
55
55
|
"@types/jest": "^29.5.13",
|
|
56
|
-
"@types/node": "^22.7.
|
|
57
|
-
"@typescript-eslint/rule-tester": "^8.
|
|
58
|
-
"@typescript-eslint/types": "^8.
|
|
56
|
+
"@types/node": "^22.7.5",
|
|
57
|
+
"@typescript-eslint/rule-tester": "^8.8.1",
|
|
58
|
+
"@typescript-eslint/types": "^8.8.1",
|
|
59
59
|
"complete-common": "^1.0.0",
|
|
60
60
|
"complete-node": "^1.5.1",
|
|
61
61
|
"jest": "^29.7.0",
|