EmmanuelDemey / EmmanuelDemey/eslint-plugin-angular

on-watch rule also triggers for service/provider/runblock

Open
#378 3 comments 7 reactions 1 assignee Claimed by @tilmanschweitzer View on GitHub
Improvement Rule
Dominant language
JavaScript
Stars
620
Forks
127
PR merge metrics
No merged PRs in 30d

Description

The on-watch rule only makes sense to me in the context of a limited lifetime code block such as a controller. For services there are no destroy points so there's no point in making sure it's unassigned.
I have to disable the rule or capture it in a variable (which is then unused, triggering another warning).

A concrete example indicating why the on-watch rule should not be triggered in the case of service/provider/runblock:

I'm using UI-router and I want to listen to the $rootScope emitted event '$stateChangeSuccess' to track page changes in google analytics. So I attach a listener via $rootScope.$on in a method of Analytics service. (Originally the listener was attached in a run block but then I learned you should avoid having logic inside of run blocks to improve testability). This however results in a warning from the angular/on-watch rule as the listener is not captured in a variable to be destroyed later.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.