Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 60943e6

Browse files
fix(eslint-plugin): [efrt] support constructor arguments (typescript-eslint#1021)
Co-authored-by: Brad Zacher <[email protected]>
1 parent 47895c0 commit 60943e6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/eslint-plugin/src/rules/explicit-function-return-type.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ export default util.createRule<Options, MessageIds>({
152152
);
153153
}
154154

155+
/**
156+
* Checks if a node belongs to:
157+
* new Foo(() => {})
158+
* ^^^^^^^^
159+
*/
160+
function isConstructorArgument(parent: TSESTree.Node): boolean {
161+
return parent.type === AST_NODE_TYPES.NewExpression;
162+
}
163+
155164
/**
156165
* Checks if a node is a type cast
157166
* `(() => {}) as Foo`
@@ -325,7 +334,8 @@ export default util.createRule<Options, MessageIds>({
325334
isVariableDeclaratorWithTypeAnnotation(node.parent) ||
326335
isClassPropertyWithTypeAnnotation(node.parent) ||
327336
isPropertyOfObjectWithType(node.parent) ||
328-
isFunctionArgument(node.parent, node)
337+
isFunctionArgument(node.parent, node) ||
338+
isConstructorArgument(node.parent)
329339
) {
330340
return;
331341
}

packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,18 @@ const func = (value: number) => x as const;
322322
},
323323
],
324324
},
325+
{
326+
filename: 'test.ts',
327+
code: `
328+
new Promise(resolve => {});
329+
new Foo(1, () => {});
330+
`,
331+
options: [
332+
{
333+
allowTypedFunctionExpressions: true,
334+
},
335+
],
336+
},
325337
],
326338
invalid: [
327339
{

0 commit comments

Comments
 (0)