question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New rule: `no-implicit-service-injection-argument`

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rwjbluecommented, Aug 5, 2019

FWIW, I would love if this rule existed.

0reactions
bmishcommented, May 9, 2021

I opened a PR to implement no-implicit-service-injection-argument: #1188

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint-plugin-ember/no-implicit-service-injection-argument.md ...
This rule disallows omitting the service name argument when injecting a service. Instead, the filename of the service should be used (i.e. service-name...
Read more >
eslint-plugin-ember - UNPKG
docs/rules/new-module-imports.md) | enforce using "New Module Imports" ... docs/rules/no-implicit-service-injection-argument.md) | disallow omitting the ...
Read more >
eslint-plugin-ember - npm
An ESLint plugin that provides a set of rules for Ember applications based on commonly known good ... no-implicit-service-injection-argument ...
Read more >
c# - Why does a generic type constraint result in a no implicit ...
The error is: The type 'Example.MyAppointment' cannot be used as type parameter 'T' in the generic type or method 'Example.AppointmentEntry<T> ...
Read more >
Dependency injection in action - Angular
There are a number of options for modifying the default search behavior, using parameter decorators on the service-valued parameters of a class constructor....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found