-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: disallow explicit calls to lifecycle hooks #427
Comments
I like this proposal. Lets implement it. |
Btw, this is not very trivial to solve in the generic case. We need to check if given object instance implements a lifecycle hook interface and later, it's method is being invoked somewhere. However, I think a basic check, such as:
Seems good enough. |
How can I disable this rule for tests? I can see the benefit for application code, but within specs I actually do want to call lifecycle hooks to test them. |
@mgechev I second the question. How can this be disabled just for testing? (Aside for the obvious solution of turning it off in a comment) |
There are two options:
|
@mgechev Just for you to notice, that Angular CLI seems to ignore the |
If there's no issue for this in the Angular CLI repo, it might be worth opening. |
Disallow code like
Instead, we should write something like
As Rob put it, "don't call your own hooks, because one day, you'll be debugging something and you'll be really confused why hooks are firing unexpectedly/out of order/whatever".
Thought it would be a nice addition to codelyzer.
The text was updated successfully, but these errors were encountered: