diff --git a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts index 43a1cac41fb4..d58754ef01cb 100644 --- a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts +++ b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts @@ -217,21 +217,20 @@ export default util.createRule({ return false; } - // Check if body is a block with a single statement - if ( - body.type === AST_NODE_TYPES.BlockStatement && - body.body.length === 1 - ) { - const [statement] = body.body; - - // Check if that statement is a return statement with an argument - if ( - statement.type === AST_NODE_TYPES.ReturnStatement && - !!statement.argument - ) { - // If so, check that returned argument as body - body = statement.argument; - } + // Check if body is a block with a return statement + if (body.type === AST_NODE_TYPES.BlockStatement) { + // Check if ReturnStatement exist among body and use that argument + // for checking whether it is a function expression + body.body.some(statement => { + if ( + statement.type === AST_NODE_TYPES.ReturnStatement && + !!statement.argument + ) { + // If so, check that returned argument as body + body = statement.argument; + return; + } + }); } // Check if the body being returned is a function expression diff --git a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts index bd69534089db..2632da7f559e 100644 --- a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts @@ -246,6 +246,17 @@ function FunctionDeclaration() { `, options: [{ allowHigherOrderFunctions: true }], }, + { + filename: 'test.ts', + code: ` +const x = (arg1: string) => { + const tempVar1 = 'temporary value1'; + const tempVar2 = 'temporary value2'; + return (arg2: number): string => 'foo'; +} + `, + options: [{ allowHigherOrderFunctions: true }], + }, // https://github.com/typescript-eslint/typescript-eslint/issues/679 { filename: 'test.ts',