From 53232d775ca0b808e2d75d9501f4411a868b2b48 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Tue, 2 Jun 2020 16:01:43 -0700 Subject: [PATCH] fix(eslint-plugin): [explicit-module-boundary-types] dont report return type errors on constructor overloads (#2158) --- .../rules/explicit-module-boundary-types.ts | 5 ++++- .../explicit-module-boundary-types.test.ts | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts b/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts index 3d5cafcb2e5..2c065eb6212 100644 --- a/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts +++ b/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts @@ -380,7 +380,10 @@ export default util.createRule({ function checkEmptyBodyFunctionExpression( node: TSESTree.TSEmptyBodyFunctionExpression, ): void { - if (!node.returnType) { + const isConstructor = + node.parent?.type === AST_NODE_TYPES.MethodDefinition && + node.parent.kind === 'constructor'; + if (!isConstructor && !node.returnType) { context.report({ node, messageId: 'missingReturnType', diff --git a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts index 3f619f1819d..74efa619d90 100644 --- a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts @@ -82,6 +82,25 @@ export class Test { } `, }, + { + // https://github.com/typescript-eslint/typescript-eslint/issues/2150 + code: ` +export class Test { + constructor(); + constructor(value?: string) { + console.log(value); + } +} + `, + }, + { + code: ` +declare class MyClass { + constructor(options?: MyClass.Options); +} +export { MyClass }; + `, + }, { code: ` export function test(): void {