New rule: `no-implicit-service-injection-argument`
See original GitHub issueI’m proposing adding a new Best Practices rule that promotes usage of explicit injections.
So instead of:
store: inject.service()
The recommended way would be:
store: inject.service('store')
The reasoning behind this change, is that I’ve heard new Ember developers asking about what that means and where is the file that defines the given injection. It’s a sort of “black magic” that allows for shortcuts that don’t really help down the line. For example:
users: inject.controller()
// The route also defines `users` as a model.
Now if a new developer saw that in the template, even if there wasn’t a model defined, they might think it’s the model and try to do {{#each users as |user|}}
.
A better approach:
usersController: inject.controller('users')
// The route defines `users` as a model.
The above won’t prevent users from naming injections poorly, but it will allow them to be more verbose by default.
This rule could have a fix as well, and would open up the way to deprecating the implicit injections all-together, via an RFC. I’m sure that there are also performance improvements when you no longer have to do that implicit check in the internals.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (7 by maintainers)
Top GitHub Comments
FWIW, I would love if this rule existed.
I opened a PR to implement
no-implicit-service-injection-argument
: #1188