[no current rule] rule proposal to forbid async lifecyclehooks #1515
Labels
package: eslint-plugin
Angular-specific TypeScript rules
PRs Welcome
If a high-quality PR is created for this it will be accepted
I propose a rule that forbids marking lifecyclehooks
async
(could be namedno-async-lifecyclehooks
).For example:
The reason should be obvious: Angular does not wait for async lifecyclehooks but the code suggests it does. I regularly see something like this:
This code reads as that the ngOnInit lifecyclehook is fetching some data and that the whole lifecycle of the component is basically "pausing" until the data has arrived. Which is not true, as we know.
Disallowing the
async
notation here will make developers instantly aware of that they are now working with a state of the component where it will finish all init cycles first and THEN get the data:Writing the rule should be very easy since I even can create it with the
no-restricted-syntax
myself:I still feel this rule would definitely belong into an official angular-esling package like this one here. In this case I would not go the
[key.name=/^ng[A-Z]/]
-approach but explicitly add the lifecycle names.For rule-options... I'm not sure if there is any option that would make sense. Excluding certain lifecyclehooks from this rule doesn't make any sense for the reasons explained above.
Would be glad to get some feedback and maybe have it added quickly :)
ng version
output per the instructions given here.The text was updated successfully, but these errors were encountered: