angular-extensions / lint-rules

tslint rules useful for angular projects
MIT License
39 stars 4 forks source link

Feature Request: ngOnDestroy for Observable Subscriptions #9

Open danielzen opened 4 years ago

danielzen commented 4 years ago

Some might need a reminder by tslint, to remind us in the console that our components or directives should have a ngOnDestroy method when it detects none. We can add a custom rule to tslint to warn us in the console during linting and building if it finds no ngOnDestroy hook in our components:

Item #6 contains the code: https://blog.bitsrc.io/6-ways-to-unsubscribe-from-observables-in-angular-ab912819a78f

macjohnny commented 4 years ago

@danielzen thanks for your request.

whenever an observable is subscribed to within a component, the angular-rxjs-takeuntil-before-subscribe rule ensures that there is an ngOnDestroy method https://github.com/angular-extensions/lint-rules/blob/eafe305b2427a23c38c8767a57e4810bf99d2fca/rules/angularRxjsTakeuntilBeforeSubscribeRule.ts#L195-L216

https://github.com/angular-extensions/lint-rules/blob/eafe305b2427a23c38c8767a57e4810bf99d2fca/rules/angularRxjsTakeuntilBeforeSubscribeRule.ts#L417-L424

how is your feature request different from that?

danielzen commented 4 years ago

Not sure why it didn't work for me, but I will double check. Thanks!