feat(bloc_lint): add prefer_multi_bloc_listener and prefer_multi_repository_provider - #4852
Open
TiwariAshuism wants to merge 1 commit into
Open
TiwariAshuism wants to merge 1 commit into
TiwariAshuism wants to merge 1 commit into
Conversation
…sitory_provider Warn when `BlocListener` or `RepositoryProvider` widgets are nested via the `child` argument, where a single `MultiBlocListener` or `MultiRepositoryProvider` would be equivalent and easier to read. Both rules share a `NestedWidgetListener` which tracks the enclosing argument lists so only the outermost widget of a nested chain is reported, and a widget that merely has a matching ancestor further up the tree is not. Closes felangel#4454 Closes felangel#4455
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 two lint rules which warn when
BlocListenerorRepositoryProviderwidgets are nested through thechildargument, where a singleMultiBlocListener/MultiRepositoryProvideris equivalent and easier to read.Implementation notes
Both rules are thin wrappers over a shared
NestedWidgetListener(lib/src/nested_widget_listener.dart), parameterized by the widget name and its replacement.childslot. A report fires only when the immediately enclosing invocation is the same widget, so a widget that merely has a matching ancestor higher up the tree is not flagged.endTypeArgumentsand named constructors via the preceding., soBlocListener<A, B>(...),RepositoryProvider(...)andRepositoryProvider<A>.value(...)are all recognized.info, matching the otherprefer_*rules. These are readability rules — the two forms are equivalent at runtime, as theMultiBlocListenerdocs note.Adding
prefer_multi_bloc_provider(#4453) on top of this is a ~20 line change, should you want it — I left it out since that issue is assigned.Verified locally against the CI gates:
dart format,dart analyze --fatal-warnings lib test, full suite (172 tests, 21 new) and 100% coverage.Closes #4454
Closes #4455
Type of Change