From f1059d82eae77e6d78800ed38ac1ce89692a419f Mon Sep 17 00:00:00 2001 From: Alexander T Date: Sat, 7 Sep 2019 08:34:38 +0300 Subject: [PATCH] fix(eslint-plugin): [efrt] allowExpressions - check functions in class field properties (#952) --- .../rules/explicit-function-return-type.ts | 3 +- .../explicit-function-return-type.test.ts | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) 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 b050578c189..43a1cac41fb 100644 --- a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts +++ b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts @@ -335,7 +335,8 @@ export default util.createRule({ options.allowExpressions && node.parent.type !== AST_NODE_TYPES.VariableDeclarator && node.parent.type !== AST_NODE_TYPES.MethodDefinition && - node.parent.type !== AST_NODE_TYPES.ExportDefaultDeclaration + node.parent.type !== AST_NODE_TYPES.ExportDefaultDeclaration && + node.parent.type !== AST_NODE_TYPES.ClassProperty ) { return; } 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 0c67b903cee..bd69534089d 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 @@ -516,6 +516,57 @@ function test() { }, ], }, + { + filename: 'test.ts', + code: ` +class Foo { + public a = () => {}; + public b = function () {}; + public c = function test() {}; + + static d = () => {}; + static e = function () {}; +} + `, + options: [{ allowExpressions: true }], + errors: [ + { + messageId: 'missingReturnType', + line: 3, + endLine: 3, + column: 14, + endColumn: 19, + }, + { + messageId: 'missingReturnType', + line: 4, + endLine: 4, + column: 14, + endColumn: 25, + }, + { + messageId: 'missingReturnType', + line: 5, + endLine: 5, + column: 14, + endColumn: 29, + }, + { + messageId: 'missingReturnType', + line: 7, + endLine: 7, + column: 14, + endColumn: 19, + }, + { + messageId: 'missingReturnType', + line: 8, + endLine: 8, + column: 14, + endColumn: 25, + }, + ], + }, { filename: 'test.ts', code: "var arrowFn = () => 'test';",