From 6abe055af050d773a92cafd6b5df461540fcb691 Mon Sep 17 00:00:00 2001 From: Gavin Barron Date: Tue, 26 Mar 2019 23:28:46 -0700 Subject: [PATCH] fix: explicit-function-return-type Ensuring that class arrow methods are validated for a return type. Fixes #348 --- .../src/rules/explicit-function-return-type.ts | 1 + .../tests/rules/explicit-function-return-type.test.ts | 7 +++++++ 2 files changed, 8 insertions(+) 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 d767959c29f..9cb9c983104 100644 --- a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts +++ b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts @@ -114,6 +114,7 @@ export default util.createRule({ ): void { if ( options.allowExpressions && + node.type !== AST_NODE_TYPES.ArrowFunctionExpression && node.parent && node.parent.type !== AST_NODE_TYPES.VariableDeclarator && node.parent.type !== AST_NODE_TYPES.MethodDefinition 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 932e50e9714..6786b92f4b1 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 @@ -41,6 +41,7 @@ class Test { method(): void { return; } + arrow = (): string => 'arrow'; } `, }, @@ -171,6 +172,7 @@ class Test { method() { return; } + arrow = () => 'arrow'; } `, errors: [ @@ -184,6 +186,11 @@ class Test { line: 8, column: 9, }, + { + messageId: 'missingReturnType', + line: 11, + column: 11, + }, ], }, {