From f59ff25520b07d68df118c756363ea8f051142cc Mon Sep 17 00:00:00 2001 From: auvred Date: Tue, 5 Dec 2023 17:29:42 +0000 Subject: [PATCH] feat(eslint-plugin): [explicit-function-return-type] add support for typed class property definitions --- .../src/util/explicitReturnTypeUtils.ts | 5 +++ .../explicit-function-return-type.test.ts | 40 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts b/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts index a8030da1bfb3..512ff62202b9 100644 --- a/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts +++ b/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts @@ -336,6 +336,11 @@ function ancestorHasReturnType(node: FunctionNode): boolean { return true; } break; + case AST_NODE_TYPES.PropertyDefinition: + if (ancestor.typeAnnotation) { + return true; + } + break; } ancestor = ancestor.parent; 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 eedbd9b76c79..8b0a05d6b5b4 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 @@ -713,6 +713,26 @@ let foo = (() => (() => {})())(); }, ], }, + { + code: ` +class Bar { + bar: Foo = { + foo: x => x + 1, + }; +} + `, + }, + { + code: ` +class Bar { + bar: Foo[] = [ + { + foo: x => x + 1, + }, + ]; +} + `, + }, ], invalid: [ { @@ -1651,6 +1671,26 @@ class Foo { }, { code: ` +class Bar { + bar = [ + { + foo: x => x + 1, + }, + ]; +} + `, + errors: [ + { + messageId: 'missingReturnType', + line: 5, + endLine: 5, + column: 7, + endColumn: 12, + }, + ], + }, + { + code: ` const foo = (function () { return 'foo'; })(); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy