From ff2f2c7a08468551ae4b20f0ac17f72e7d9f1ca0 Mon Sep 17 00:00:00 2001 From: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> Date: Wed, 7 Jun 2023 10:49:00 +0200 Subject: [PATCH] fix(eslint): updater-explicit-return-type not applied when inheritance --- .../rules/updater-explicit-return-type.spec.ts | 10 ++++++++++ .../updater-explicit-return-type.ts | 2 +- .../src/utils/helper-functions/utils.ts | 18 ------------------ 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/modules/eslint-plugin/spec/rules/updater-explicit-return-type.spec.ts b/modules/eslint-plugin/spec/rules/updater-explicit-return-type.spec.ts index 7a60874690..bb1b5a12e0 100644 --- a/modules/eslint-plugin/spec/rules/updater-explicit-return-type.spec.ts +++ b/modules/eslint-plugin/spec/rules/updater-explicit-return-type.spec.ts @@ -122,6 +122,16 @@ class NotOk3 { const updater = (item: Movie) => item updater() } +}`), + fromFixture(` +@Injectable() +export class CompetitorsStore2 extends CompetitorsStore1 { + override updateName = this.updater((state, name: string) => ({ ...state, name })); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}] + + + updateName2 = this.updater(() => ({ name: 'test' })); + ~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}] }`), ]; diff --git a/modules/eslint-plugin/src/rules/component-store/updater-explicit-return-type.ts b/modules/eslint-plugin/src/rules/component-store/updater-explicit-return-type.ts index 8251124d81..dc553e6bb0 100644 --- a/modules/eslint-plugin/src/rules/component-store/updater-explicit-return-type.ts +++ b/modules/eslint-plugin/src/rules/component-store/updater-explicit-return-type.ts @@ -33,7 +33,7 @@ export default createRule({ const storeNames = identifiers.length > 0 ? asPattern(identifiers) : null; const withoutTypeAnnotation = `ArrowFunctionExpression:not([returnType.typeAnnotation])`; const selectors = [ - `ClassDeclaration[superClass.name='ComponentStore'] CallExpression[callee.object.type='ThisExpression'][callee.property.name='updater'] > ${withoutTypeAnnotation}`, + `ClassDeclaration[superClass.name=/Store/] CallExpression[callee.object.type='ThisExpression'][callee.property.name='updater'] > ${withoutTypeAnnotation}`, storeNames && `${namedExpression( storeNames diff --git a/modules/eslint-plugin/src/utils/helper-functions/utils.ts b/modules/eslint-plugin/src/utils/helper-functions/utils.ts index 61dfb0f0b4..31eee60fd3 100644 --- a/modules/eslint-plugin/src/utils/helper-functions/utils.ts +++ b/modules/eslint-plugin/src/utils/helper-functions/utils.ts @@ -260,10 +260,6 @@ export function getLast(items: T): T[number] { return items.slice(-1)[0]; } -export function getDecoratorArguments({ expression }: TSESTree.Decorator) { - return isCallExpression(expression) ? expression.arguments : []; -} - export function getDecoratorName({ expression, }: TSESTree.Decorator): string | undefined { @@ -276,20 +272,6 @@ export function getDecoratorName({ : undefined; } -export function getDecorator( - { - decorators, - }: - | TSESTree.PropertyDefinition - | TSESTree.ClassDeclaration - | TSESTree.MethodDefinition, - decoratorName: string -): TSESTree.Decorator | undefined { - return decorators?.find( - (decorator) => getDecoratorName(decorator) === decoratorName - ); -} - export function getRawText(node: TSESTree.Node): string | null { if (isIdentifier(node)) { return node.name;