@murky-web/typebuddy 1.1.0 → 1.1.1
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/dist/rules/async_rule.js +55 -3
- package/dist/rules/maybe_promise_rule.js +90 -7
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/rules/async_rule.ts +137 -6
- package/rules/maybe_promise_rule.ts +246 -20
- package/src/type_helper.ts +252 -253
package/dist/rules/async_rule.js
CHANGED
|
@@ -1,4 +1,45 @@
|
|
|
1
1
|
//#region rules/async_rule.ts
|
|
2
|
+
function isNode(value) {
|
|
3
|
+
return typeof value === "object" && value !== null && "type" in value;
|
|
4
|
+
}
|
|
5
|
+
function getProgram(node) {
|
|
6
|
+
let current = node;
|
|
7
|
+
while (current?.parent) current = current.parent;
|
|
8
|
+
return current?.type === "Program" ? current : null;
|
|
9
|
+
}
|
|
10
|
+
function isIdentifierNamed(node, name) {
|
|
11
|
+
return isNode(node) && node.type === "Identifier" && node.name === name;
|
|
12
|
+
}
|
|
13
|
+
function isImportDeclaration(node) {
|
|
14
|
+
return isNode(node) && node.type === "ImportDeclaration";
|
|
15
|
+
}
|
|
16
|
+
function getStringLiteralValue(node) {
|
|
17
|
+
if (!isNode(node)) return null;
|
|
18
|
+
if ((node.type === "Literal" || node.type === "StringLiteral") && typeof node.value === "string") return node.value;
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
function getProgramBody(node) {
|
|
22
|
+
if (!Array.isArray(node.body)) return [];
|
|
23
|
+
return node.body.filter(isNode);
|
|
24
|
+
}
|
|
25
|
+
function hasTypeBuddyHelperImport(program, helperName) {
|
|
26
|
+
return getProgramBody(program).some((statement) => {
|
|
27
|
+
if (!isImportDeclaration(statement)) return false;
|
|
28
|
+
if (getStringLiteralValue(statement.source) !== "@murky-web/typebuddy") return false;
|
|
29
|
+
if (statement.importKind === "type") return false;
|
|
30
|
+
return (Array.isArray(statement.specifiers) ? statement.specifiers : []).some((specifier) => {
|
|
31
|
+
return isNode(specifier) && specifier.type === "ImportSpecifier" && isIdentifierNamed(specifier.local, helperName);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function getTypeBuddyImportInsertRange(program) {
|
|
36
|
+
const body = getProgramBody(program);
|
|
37
|
+
const imports = body.filter(isImportDeclaration);
|
|
38
|
+
const anchor = imports.at(-1) ?? body[0] ?? program;
|
|
39
|
+
if (!Array.isArray(anchor.range) || anchor.range.length < 2) return null;
|
|
40
|
+
if (imports.length > 0) return [anchor.range[1], anchor.range[1]];
|
|
41
|
+
return [anchor.range[0], anchor.range[0]];
|
|
42
|
+
}
|
|
2
43
|
function hasTryCatch(nodes) {
|
|
3
44
|
return nodes.some((node) => {
|
|
4
45
|
return node.type === "TryStatement";
|
|
@@ -13,6 +54,17 @@ function isCallArgumentCallback(node) {
|
|
|
13
54
|
const rule = {
|
|
14
55
|
create(context) {
|
|
15
56
|
const sourceCode = context.getSourceCode();
|
|
57
|
+
let scheduledErrImport = false;
|
|
58
|
+
function ensureErrImportFixes(node, fixer) {
|
|
59
|
+
if (scheduledErrImport) return [];
|
|
60
|
+
const program = getProgram(node);
|
|
61
|
+
if (!program || hasTypeBuddyHelperImport(program, "err")) return [];
|
|
62
|
+
const insertRange = getTypeBuddyImportInsertRange(program);
|
|
63
|
+
if (!insertRange) return [];
|
|
64
|
+
scheduledErrImport = true;
|
|
65
|
+
const importText = insertRange[0] !== 0 ? "\nimport { err } from \"@murky-web/typebuddy\";" : "import { err } from \"@murky-web/typebuddy\";\n";
|
|
66
|
+
return [fixer.insertTextBeforeRange(insertRange, importText)];
|
|
67
|
+
}
|
|
16
68
|
function getIndentation(node) {
|
|
17
69
|
const firstLine = sourceCode.getText(node).split("\n")[0];
|
|
18
70
|
const match = /^\s*/.exec(firstLine);
|
|
@@ -27,8 +79,8 @@ ${indent}try {
|
|
|
27
79
|
${body.map((statement) => {
|
|
28
80
|
return `${innerIndent}${sourceCode.getText(statement).replaceAll(/^\s*/gm, "")}`;
|
|
29
81
|
}).join("\n")}
|
|
30
|
-
${indent}} catch
|
|
31
|
-
${innerIndent}return
|
|
82
|
+
${indent}} catch {
|
|
83
|
+
${innerIndent}return err();
|
|
32
84
|
${indent}}
|
|
33
85
|
}`;
|
|
34
86
|
}
|
|
@@ -42,7 +94,7 @@ ${indent}}
|
|
|
42
94
|
node,
|
|
43
95
|
messageId: "missingTryCatch",
|
|
44
96
|
fix(fixer) {
|
|
45
|
-
return fixer.replaceText(bodyNode, wrapInTryCatch(bodyNode));
|
|
97
|
+
return [...ensureErrImportFixes(node, fixer), fixer.replaceText(bodyNode, wrapInTryCatch(bodyNode))];
|
|
46
98
|
}
|
|
47
99
|
});
|
|
48
100
|
}
|
|
@@ -17,6 +17,23 @@ function isCallArgumentCallback(node) {
|
|
|
17
17
|
function isIdentifierNamed(node, name) {
|
|
18
18
|
return isNode(node) && node.type === "Identifier" && node.name === name;
|
|
19
19
|
}
|
|
20
|
+
function getProgram(node) {
|
|
21
|
+
let current = node;
|
|
22
|
+
while (current?.parent) current = current.parent;
|
|
23
|
+
return current?.type === "Program" ? current : null;
|
|
24
|
+
}
|
|
25
|
+
function isImportDeclaration(node) {
|
|
26
|
+
return isNode(node) && node.type === "ImportDeclaration";
|
|
27
|
+
}
|
|
28
|
+
function getStringLiteralValue(node) {
|
|
29
|
+
if (!isNode(node)) return null;
|
|
30
|
+
if ((node.type === "Literal" || node.type === "StringLiteral") && typeof node.value === "string") return node.value;
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
function getProgramBody(node) {
|
|
34
|
+
if (!Array.isArray(node.body)) return [];
|
|
35
|
+
return node.body.filter(isNode);
|
|
36
|
+
}
|
|
20
37
|
function isResultHelperCall(node, name) {
|
|
21
38
|
return isNode(node) && node.type === "CallExpression" && isIdentifierNamed(node.callee, name);
|
|
22
39
|
}
|
|
@@ -26,9 +43,39 @@ function hasIsErrorFlag(node, expected) {
|
|
|
26
43
|
return isNode(property) && property.type === "Property" && isIdentifierNamed(property.key, "isError") && isNode(property.value) && property.value.type === "Literal" && property.value.value === expected;
|
|
27
44
|
});
|
|
28
45
|
}
|
|
46
|
+
function getObjectPropertyValue(node, propertyName) {
|
|
47
|
+
if (!isNode(node) || node.type !== "ObjectExpression" || !Array.isArray(node.properties)) return null;
|
|
48
|
+
for (const property of node.properties) if (isNode(property) && property.type === "Property" && isIdentifierNamed(property.key, propertyName) && isNode(property.value)) return property.value;
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
function isBooleanLiteral(node, expected) {
|
|
52
|
+
return isNode(node) && node.type === "Literal" && node.value === expected;
|
|
53
|
+
}
|
|
54
|
+
function isNullLiteral(node) {
|
|
55
|
+
return isNode(node) && node.type === "Literal" && node.value === null;
|
|
56
|
+
}
|
|
57
|
+
function hasTypeBuddyHelperImport(program, helperName) {
|
|
58
|
+
return getProgramBody(program).some((statement) => {
|
|
59
|
+
if (!isImportDeclaration(statement)) return false;
|
|
60
|
+
if (getStringLiteralValue(statement.source) !== "@murky-web/typebuddy") return false;
|
|
61
|
+
if (statement.importKind === "type") return false;
|
|
62
|
+
return (Array.isArray(statement.specifiers) ? statement.specifiers : []).some((specifier) => {
|
|
63
|
+
return isNode(specifier) && specifier.type === "ImportSpecifier" && isIdentifierNamed(specifier.local, helperName);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function getTypeBuddyImportInsertRange(program) {
|
|
68
|
+
const body = getProgramBody(program);
|
|
69
|
+
const imports = body.filter(isImportDeclaration);
|
|
70
|
+
const anchor = imports.at(-1) ?? body[0] ?? program;
|
|
71
|
+
if (!Array.isArray(anchor.range) || anchor.range.length < 2) return null;
|
|
72
|
+
if (imports.length > 0) return [anchor.range[1], anchor.range[1]];
|
|
73
|
+
return [anchor.range[0], anchor.range[0]];
|
|
74
|
+
}
|
|
29
75
|
const rule = {
|
|
30
76
|
create(context) {
|
|
31
77
|
const sourceCode = context.getSourceCode();
|
|
78
|
+
const scheduledHelperImports = /* @__PURE__ */ new Set();
|
|
32
79
|
function isTypeReference(node) {
|
|
33
80
|
return isNode(node) && node.type === "TSTypeReference";
|
|
34
81
|
}
|
|
@@ -48,6 +95,16 @@ const rule = {
|
|
|
48
95
|
if (getTypeName(node) !== "Promise") return null;
|
|
49
96
|
return getTypeArgument(node);
|
|
50
97
|
}
|
|
98
|
+
function ensureResultHelperImportFixes(node, fixer, helperName) {
|
|
99
|
+
if (scheduledHelperImports.has(helperName)) return [];
|
|
100
|
+
const program = getProgram(node);
|
|
101
|
+
if (!program || hasTypeBuddyHelperImport(program, helperName)) return [];
|
|
102
|
+
const insertRange = getTypeBuddyImportInsertRange(program);
|
|
103
|
+
if (!insertRange) return [];
|
|
104
|
+
scheduledHelperImports.add(helperName);
|
|
105
|
+
const importText = insertRange[0] !== 0 ? `\nimport { ${helperName} } from "@murky-web/typebuddy";` : `import { ${helperName} } from "@murky-web/typebuddy";\n`;
|
|
106
|
+
return [fixer.insertTextBeforeRange(insertRange, importText)];
|
|
107
|
+
}
|
|
51
108
|
function checkReturnType(node) {
|
|
52
109
|
if (!isAsyncFunction(node)) return;
|
|
53
110
|
if (isCallArgumentCallback(node)) return;
|
|
@@ -72,19 +129,42 @@ const rule = {
|
|
|
72
129
|
node,
|
|
73
130
|
messageId: "returnVoidPromise",
|
|
74
131
|
fix(fixer) {
|
|
75
|
-
return fixer.replaceText(node, "return
|
|
132
|
+
return [...ensureResultHelperImportFixes(node, fixer, "ok"), fixer.replaceText(node, "return ok()")];
|
|
76
133
|
}
|
|
77
134
|
});
|
|
78
135
|
return;
|
|
79
136
|
}
|
|
80
137
|
if (argument.type === "Identifier" && (argument.name === "VOID_PROMISE" || argument.name === "FAILED_PROMISE")) return;
|
|
81
138
|
if (isResultHelperCall(argument, "ok") || isResultHelperCall(argument, "err")) return;
|
|
139
|
+
const isErrorValue = getObjectPropertyValue(argument, "isError");
|
|
140
|
+
const objectValue = getObjectPropertyValue(argument, "value");
|
|
141
|
+
if (isBooleanLiteral(isErrorValue, false) && objectValue) {
|
|
142
|
+
context.report({
|
|
143
|
+
node: argument,
|
|
144
|
+
messageId: "preferOkResult",
|
|
145
|
+
fix(fixer) {
|
|
146
|
+
const valueText = sourceCode.getText(objectValue);
|
|
147
|
+
return [...ensureResultHelperImportFixes(node, fixer, "ok"), fixer.replaceText(argument, `ok(${valueText})`)];
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (isBooleanLiteral(isErrorValue, true) && isNullLiteral(objectValue)) {
|
|
153
|
+
context.report({
|
|
154
|
+
node: argument,
|
|
155
|
+
messageId: "preferErrResult",
|
|
156
|
+
fix(fixer) {
|
|
157
|
+
return [...ensureResultHelperImportFixes(node, fixer, "err"), fixer.replaceText(argument, "err()")];
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
82
162
|
if (!hasIsErrorFlag(argument, true) && !hasIsErrorFlag(argument, false)) context.report({
|
|
83
163
|
node: argument,
|
|
84
164
|
messageId: "wrapReturn",
|
|
85
165
|
fix(fixer) {
|
|
86
166
|
const argumentText = sourceCode.getText(argument);
|
|
87
|
-
return fixer.replaceText(argument, `
|
|
167
|
+
return [...ensureResultHelperImportFixes(node, fixer, "ok"), fixer.replaceText(argument, `ok(${argumentText})`)];
|
|
88
168
|
}
|
|
89
169
|
});
|
|
90
170
|
}
|
|
@@ -111,17 +191,18 @@ const rule = {
|
|
|
111
191
|
for (const statement of blockBody) if (isNode(statement) && statement.type === "ReturnStatement") wrapReturnValue(statement, isAsync, returnType);
|
|
112
192
|
if (!isNode(node.handler) || !isNode(node.handler.body)) return;
|
|
113
193
|
const catchBody = Array.isArray(node.handler.body.body) ? node.handler.body.body.filter(isNode) : [];
|
|
194
|
+
for (const statement of catchBody) if (statement.type === "ReturnStatement" && isNode(statement.argument)) wrapReturnValue(statement, isAsync, returnType);
|
|
114
195
|
if (!catchBody.some((statement) => statement.type === "ReturnStatement" && isNode(statement.argument) && (statement.argument.type === "Identifier" && statement.argument.name === "FAILED_PROMISE" || isResultHelperCall(statement.argument, "err") || hasIsErrorFlag(statement.argument, true)))) context.report({
|
|
115
196
|
node: node.handler,
|
|
116
197
|
messageId: "returnFailedPromise",
|
|
117
198
|
fix(fixer) {
|
|
118
199
|
const lastStatement = catchBody.at(-1);
|
|
119
|
-
if (lastStatement?.type === "ReturnStatement" && isNode(lastStatement.argument) && lastStatement.argument.type === "ObjectExpression") return fixer.replaceText(lastStatement, "return
|
|
200
|
+
if (lastStatement?.type === "ReturnStatement" && isNode(lastStatement.argument) && lastStatement.argument.type === "ObjectExpression") return [...ensureResultHelperImportFixes(node, fixer, "err"), fixer.replaceText(lastStatement, "return err()")];
|
|
120
201
|
const handler = node.handler;
|
|
121
202
|
if (!isNode(handler)) return null;
|
|
122
203
|
const bodyRange = handler.body;
|
|
123
204
|
if (!isNode(bodyRange) || !Array.isArray(bodyRange.range)) return null;
|
|
124
|
-
return fixer.insertTextBeforeRange([bodyRange.range[1] - 1, bodyRange.range[1] - 1], "return
|
|
205
|
+
return [...ensureResultHelperImportFixes(node, fixer, "err"), fixer.insertTextBeforeRange([bodyRange.range[1] - 1, bodyRange.range[1] - 1], "return err(); ")];
|
|
125
206
|
}
|
|
126
207
|
});
|
|
127
208
|
}
|
|
@@ -143,9 +224,11 @@ const rule = {
|
|
|
143
224
|
schema: [],
|
|
144
225
|
messages: {
|
|
145
226
|
replaceWithMaybePromise: "Use 'MaybePromise' instead of 'Promise' as the return type in async functions.",
|
|
146
|
-
wrapReturn: "Wrap return value with
|
|
147
|
-
|
|
148
|
-
|
|
227
|
+
wrapReturn: "Wrap return value with ok(value).",
|
|
228
|
+
preferOkResult: "Use ok(value) instead of an inline success result object.",
|
|
229
|
+
preferErrResult: "Use err() instead of an inline error result object.",
|
|
230
|
+
returnVoidPromise: "Return ok() for async functions with Promise<void> return type.",
|
|
231
|
+
returnFailedPromise: "Return err() in the catch block of async functions."
|
|
149
232
|
}
|
|
150
233
|
}
|
|
151
234
|
};
|
package/jsr.json
CHANGED
package/package.json
CHANGED
package/rules/async_rule.ts
CHANGED
|
@@ -14,10 +14,112 @@ type RuleContext = {
|
|
|
14
14
|
messageId: string;
|
|
15
15
|
fix(fixer: {
|
|
16
16
|
replaceText(node: unknown, text: string): unknown;
|
|
17
|
+
insertTextBeforeRange(
|
|
18
|
+
range: [number, number],
|
|
19
|
+
text: string,
|
|
20
|
+
): unknown;
|
|
17
21
|
}): unknown;
|
|
18
22
|
}): void;
|
|
19
23
|
};
|
|
20
24
|
|
|
25
|
+
type RuleFixer = {
|
|
26
|
+
replaceText(node: unknown, text: string): unknown;
|
|
27
|
+
insertTextBeforeRange(range: [number, number], text: string): unknown;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function isNode(value: unknown): value is AstNode {
|
|
31
|
+
return typeof value === "object" && value !== null && "type" in value;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getProgram(node: AstNode): AstNode | null {
|
|
35
|
+
let current: AstNode | undefined = node;
|
|
36
|
+
|
|
37
|
+
while (current?.parent) {
|
|
38
|
+
current = current.parent;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return current?.type === "Program" ? current : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isIdentifierNamed(node: unknown, name: string): boolean {
|
|
45
|
+
return isNode(node) && node.type === "Identifier" && node.name === name;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function isImportDeclaration(node: unknown): node is AstNode {
|
|
49
|
+
return isNode(node) && node.type === "ImportDeclaration";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getStringLiteralValue(node: unknown): string | null {
|
|
53
|
+
if (!isNode(node)) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (
|
|
58
|
+
(node.type === "Literal" || node.type === "StringLiteral") &&
|
|
59
|
+
typeof node.value === "string"
|
|
60
|
+
) {
|
|
61
|
+
return node.value;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getProgramBody(node: AstNode): AstNode[] {
|
|
68
|
+
if (!Array.isArray(node.body)) {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return node.body.filter(isNode);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function hasTypeBuddyHelperImport(program: AstNode, helperName: "err") {
|
|
76
|
+
return getProgramBody(program).some((statement) => {
|
|
77
|
+
if (!isImportDeclaration(statement)) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (
|
|
82
|
+
getStringLiteralValue(statement.source) !== "@murky-web/typebuddy"
|
|
83
|
+
) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (statement.importKind === "type") {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const specifiers = Array.isArray(statement.specifiers)
|
|
92
|
+
? statement.specifiers
|
|
93
|
+
: [];
|
|
94
|
+
|
|
95
|
+
return specifiers.some((specifier) => {
|
|
96
|
+
return (
|
|
97
|
+
isNode(specifier) &&
|
|
98
|
+
specifier.type === "ImportSpecifier" &&
|
|
99
|
+
isIdentifierNamed(specifier.local, helperName)
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function getTypeBuddyImportInsertRange(
|
|
106
|
+
program: AstNode,
|
|
107
|
+
): [number, number] | null {
|
|
108
|
+
const body = getProgramBody(program);
|
|
109
|
+
const imports = body.filter(isImportDeclaration);
|
|
110
|
+
const anchor = imports.at(-1) ?? body[0] ?? program;
|
|
111
|
+
|
|
112
|
+
if (!Array.isArray(anchor.range) || anchor.range.length < 2) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (imports.length > 0) {
|
|
117
|
+
return [anchor.range[1], anchor.range[1]];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return [anchor.range[0], anchor.range[0]];
|
|
121
|
+
}
|
|
122
|
+
|
|
21
123
|
function hasTryCatch(nodes: AstNode[]): boolean {
|
|
22
124
|
return nodes.some((node) => {
|
|
23
125
|
return node.type === "TryStatement";
|
|
@@ -40,6 +142,35 @@ function isCallArgumentCallback(node: AstNode): boolean {
|
|
|
40
142
|
const rule = {
|
|
41
143
|
create(context: RuleContext) {
|
|
42
144
|
const sourceCode = context.getSourceCode();
|
|
145
|
+
let scheduledErrImport = false;
|
|
146
|
+
|
|
147
|
+
function ensureErrImportFixes(
|
|
148
|
+
node: AstNode,
|
|
149
|
+
fixer: RuleFixer,
|
|
150
|
+
): unknown[] {
|
|
151
|
+
if (scheduledErrImport) {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const program = getProgram(node);
|
|
156
|
+
if (!program || hasTypeBuddyHelperImport(program, "err")) {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const insertRange = getTypeBuddyImportInsertRange(program);
|
|
161
|
+
if (!insertRange) {
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
scheduledErrImport = true;
|
|
166
|
+
|
|
167
|
+
const hasImports = insertRange[0] !== 0;
|
|
168
|
+
const importText = hasImports
|
|
169
|
+
? '\nimport { err } from "@murky-web/typebuddy";'
|
|
170
|
+
: 'import { err } from "@murky-web/typebuddy";\n';
|
|
171
|
+
|
|
172
|
+
return [fixer.insertTextBeforeRange(insertRange, importText)];
|
|
173
|
+
}
|
|
43
174
|
|
|
44
175
|
function getIndentation(node: AstNode): string {
|
|
45
176
|
const lines = sourceCode.getText(node).split("\n");
|
|
@@ -62,8 +193,8 @@ const rule = {
|
|
|
62
193
|
return `{
|
|
63
194
|
${indent}try {
|
|
64
195
|
${bodyText}
|
|
65
|
-
${indent}} catch
|
|
66
|
-
${innerIndent}return
|
|
196
|
+
${indent}} catch {
|
|
197
|
+
${innerIndent}return err();
|
|
67
198
|
${indent}}
|
|
68
199
|
}`;
|
|
69
200
|
}
|
|
@@ -87,10 +218,10 @@ ${indent}}
|
|
|
87
218
|
node,
|
|
88
219
|
messageId: "missingTryCatch",
|
|
89
220
|
fix(fixer) {
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
wrapInTryCatch(bodyNode),
|
|
93
|
-
|
|
221
|
+
return [
|
|
222
|
+
...ensureErrImportFixes(node, fixer),
|
|
223
|
+
fixer.replaceText(bodyNode, wrapInTryCatch(bodyNode)),
|
|
224
|
+
];
|
|
94
225
|
},
|
|
95
226
|
});
|
|
96
227
|
}
|