diff --git a/modules/eslint-plugin/spec/rules/component-store/require-super-ondestroy.spec.ts b/modules/eslint-plugin/spec/rules/component-store/require-super-ondestroy.spec.ts index 3c5d90ab25..ee06d720f6 100644 --- a/modules/eslint-plugin/spec/rules/component-store/require-super-ondestroy.spec.ts +++ b/modules/eslint-plugin/spec/rules/component-store/require-super-ondestroy.spec.ts @@ -71,7 +71,6 @@ class BooksStore extends ComponentStore implements OnDestroy override ngOnDestroy(): void { this.cleanUp(); - super.ngOnDestroy(); } }`, ]; @@ -113,18 +112,6 @@ class BooksStore extends ComponentStore implements OnDestroy { ~~~~~~~~~~~ [${messageId}] super.get(); } -}`), - fromFixture(` -import { ComponentStore } from '../components/component-store'; - -class BooksStore extends ComponentStore implements OnDestroy -{ - cleanUp() {} - - override ngOnDestroy(): void { - ~~~~~~~~~~~ [${messageId}] - this.cleanUp(); - } }`), ]; diff --git a/modules/eslint-plugin/src/rules/component-store/require-super-ondestroy.ts b/modules/eslint-plugin/src/rules/component-store/require-super-ondestroy.ts index d4e6b05c6f..e1d6068683 100644 --- a/modules/eslint-plugin/src/rules/component-store/require-super-ondestroy.ts +++ b/modules/eslint-plugin/src/rules/component-store/require-super-ondestroy.ts @@ -24,11 +24,23 @@ export default createRule({ defaultOptions: [], create: (context) => { const ngOnDestroyMethodSelector = `MethodDefinition[key.name='ngOnDestroy']`; + const componentStoreClassName = 'ComponentStore'; + + let hasNgrxComponentStoreImport = false; return { - [`ClassDeclaration[superClass.name=ComponentStore] ${ngOnDestroyMethodSelector}:not(:has(CallExpression[callee.object.type='Super'][callee.property.name='ngOnDestroy'])) > .key`]( + [`ImportDeclaration[source.value='@ngrx/component-store'] ImportSpecifier[imported.name='${componentStoreClassName}']`]( + _: TSESTree.ImportSpecifier + ) { + hasNgrxComponentStoreImport = true; + }, + [`ClassDeclaration[superClass.name=${componentStoreClassName}] ${ngOnDestroyMethodSelector}:not(:has(CallExpression[callee.object.type='Super'][callee.property.name='ngOnDestroy'])) > .key`]( node: TSESTree.Identifier ) { + if (!hasNgrxComponentStoreImport) { + return; + } + context.report({ node, messageId,