[testbed-no-implicit-providers] new rule preventing implicit use of dependencies provided in root #1365
FDIM
started this conversation in
New Rule Proposals
Replies: 2 comments 1 reply
-
I don't believe this is even possible to create a rule for based on the information available to the linter, but you are welcome to build out a POC to further the discussion |
Beta Was this translation helpful? Give feedback.
0 replies
-
Cool! I'll see what I can do about this. There should be enough information in typescript to implement such rule, maybe not directly but still, code is there, so I'm hopeful. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Suggestion for a new rule
There is this issue in angular: angular/angular#25593
Today we are avoiding use of
providedIn: 'root'
approach, but this is starting to clash with my long term vision of splitting a big project in multiple smaller libraries and eventually being able to adopt micro frontends pattern (when needed).I'm proposing to solve the issue from another angle, by being OK to use
providedIn: 'root'
but having a lint rule that checks that no implicit providers are used in a component test (or anything that involves TestBed).Consider this scenario:
App code
Test code
I'd expect the lint rule to highlight
InputDirective
indeclarations
array stating that not all dependencies are mocked since. This would prevent later code additions from turning this unit test to an integration test. Worst part is misleading error message complaining about a missing dependency that is not even used by the directive itself directly.A little tricky bit will be to come up with a list of built in providers that do not need/cannot to be mocked and still let users customize it, such as
ElementRef
.Another tricky bit is related to
HttpClient
, we are not usingHttpClientTestingModule
but some/majority of others do and this rule should still cover these cases and not complain aboutHttpClient
when the relevant testing module is imported.I'm up to work on a PR making this possible if authors/contributors are onboard with this idea? Thoughts?
Versions
@angular-eslint/eslint-plugin
X.Y.Z
@typescript-eslint/parser
X.Y.Z
ESLint
X.Y.Z
node
X.Y.Z
# Please run `npx ng version` in your project and paste the full output here:
ng version
output per the instructions given here.Beta Was this translation helpful? Give feedback.
All reactions