Closed WiseBird closed 2 years ago
Hey thanks for reporting this. I fixed the rule so that it won't error for you with providers using identifiers.
but I didn't add support for following identifiers to discover the providers referenced. Like you said it becomes a bit of a rabbit hole. This rule is already a bit hacky because of the way it has to list all providers in modules and then go parse every file.
I didn't want to add actual TS parsing at that step.
Happy to accept a PR for it though 👍
I added a note to the readme describing the limitation
Description
injectable-should-be-provided
expect providers to be an array, otherwise it may fail with NPE:Reproduction
https://github.com/WiseBird/eslint-plugin-nestjs-issue-shorthand (commit)
Details
Works:
Moving the array into a variable doesn't:
Shorthand syntax doesn't work as well:
The error happens when we try to iterate the elements:
Disclamer
I understand that's it's a rabbit hole. You also can import providers array from somewhere or construct it dynamically or whatever. But maybe covering a case when providers array is moved to a variable (which is often done to use it in
exports
) worth doing.