D
D
Drovosek012021-04-28 00:13:06
Angular
Drovosek01, 2021-04-28 00:13:06

How to find all Observable without unsubscribing, for example using regular expressions?

I have a project in Angular. It has components in which there is no unsubscribe when subscribing to an Observable.

Is there any tool to find all pieces of code where there is a subscription without unsubscribing?

On the project I am considering, unsubscribing occurs with the help of or Well, these fields themselves are registered in ngOnDestroy, etc. I thought that we could try to write a regular expression that would check if there are pieces of code presented above before ".subscribe". As I understand it, for this you will have to use the "Negative lookbehind" construct, which is not supported by all browsers, but it works in VSCode in file search. I wrote this regex
.pipe(takeUntil(this.unsubscribe$))
.pipe(takeUntil(this.componentDestroyed$))


(?<!componentDestroyed\$\)\)|unsubscribe\$\)\))[.\s]+\.subscribe

which finds the text ".subscribe" that is not immediately or indefinitely preceded by "componentDestroyed$))" or "unsubscribe$))".
But for some reason it doesn't work on such a block of code. The text ".subscribe" is highlighted even though it is preceded by the above lines.
this.componentDestroyed$))
         .subscribe(
        (blob: Blob) => {

60887e5f8ae81320314341.png
I can't understand why ".subscribe" is highlighted if it is preceded by "componentDestroyed$))" and how to fix the regular expression so that it works correctly, please tell me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Brezhnev, 2021-04-28
@Drovosek01

We use https://cartant.github.io/rxjs-tslint-rules/ and the rxjs-prefer-angular-takeuntil rule

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question