-
Notifications
You must be signed in to change notification settings - Fork 136
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
Provide an ESLint rule that helps with catching injection typos #388
Comments
Are you talking about type checking that the registration's type matches the parameter's type? Or are you talking about making sure there's a registration for the parameter name? Either way, both are going to be tricky considering Would be cool though! |
In our case we inject dependencies like this: export default MyService {
constructor({
authenticationService,
userService
}: {
authenticationService: IAuthenticationService,
userService: IUserService
})
} And we just found a bug where we had incorrectly written export default MyService {
constructor({
authorizationService,
userService
}: {
// Typo here, should be authenticationService
authorizationService: IAuthenticationService,
userService: IUserService
})
} So having a lint rule that catches these mistakes when writing the code would be really great. You can specify with ESLint what files the rules should run on, so it would be easy to configure it to run on the correct files. We have written a proof-of-concept ESLint rule that catches these kind of mistakes in proxy mode. But having a supported official package from Awilix would be great. It makes a lot of sense for Awilix to provide this, as these are bugs you cannot catch with the TS compiler at all, and it would improve the DX of this library a lot 😸 Classic modeIt should also work for this i suppose. You could have to separate rules, one for classic and one for proxy. export default MyService {
// Typo here, should be authenticationService
constructor(authorizationService: IAuthenticationService, userService: IUserService)
} |
Ah, I see! So you're doing this purely based on the type annotation's name? What about if you used the wrong type, or you name your registrations differently? My concern with doing an "official" plugin is that it'll be expected to catch every misuse under the sun. 😅 |
I totally get that, i can imagine there's a bunch of different cases here, and that this lint wish is only valid for TS. But could it be possible to have different configurations for the rule? So that you can configure it to match your code setup? |
Perhaps! It seems like you've got something going, if you create a repo and publish it, I can add it to the ecosystem section in the README if you want? |
It's quite easy to have a typo when injecting with Awilix. It would make a lot of sense for Awilix to provide an ESLint rule that helps users catch mistakes where the provided interface does not match the name of the parameter in the construction, both in classic and proxy mode.
The text was updated successfully, but these errors were encountered: