feat(bloc_lint): add avoid_bloc_to_bloc_members
#4665
+429
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Status
READY
Breaking Changes
NO
Description
Adds support for a new
avoid_bloc_to_bloc_memberslint rule (I'm not married to the name, open to suggestions).This was mentioned in #4264 as "Avoid passing a bloc or cubit to the constructor of another bloc or cubit" (see this comment)
The goal being to avoid tightly coupling blocs or cubits together by allowing one to be a member or parameter of another.
❌ Bad
❌ Bad
Currently this covers both in one rule (as class fields and as parameters) but happy to split into two separate rules if that's preferable - I just figured they both fall under the same umbrella of "avoid tightly coupling blocs or cubits together".
It's done via name rather than looking at type hierarchy as that's what the other rules were doing (e.g.
avoid_public_bloc_methods) - I'm not very familiar with the analyzer/diagnostic tools so unsure if there's a way to do proper checking on the parameter typings to see if a parameter actually extendsBlocorCubit?Also happy to extend test coverage - I don't have every single case for both bloc and cubit and every combination between but tried to cover at least one of every variation (optional vs required, named vs positional vs default, bloc vs cubit).
Type of Change