Repository navigation
feat(bloc_lint): add prefer_multi_bloc_provider - #4912
Open
shubhransh-gupta wants to merge 1 commit into
Open
shubhransh-gupta wants to merge 1 commit into
shubhransh-gupta wants to merge 1 commit into
Conversation
Adds the `prefer_multi_bloc_provider` lint rule which warns when `BlocProvider` widgets are nested directly through the `child` argument, recommending a single `MultiBlocProvider` instead for improved readability. Closes felangel#4453
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 the
prefer_multi_bloc_providerlint rule requested in #4453. It warns whenBlocProviderwidgets are nested directly through thechildargument, recommending a singleMultiBlocProviderwidget instead for improved readability and reduced widget nesting.Implementation Details
BlocProvider(...)andBlocProvider<T>(...), including named constructors likeBlocProvider.value(...)andBlocProvider<T>.value(...).BlocProvider.child:argument nesting while ignoring intervening widgets (e.g.,Padding,Builder), callback closures, or other providers.BlocProviderin a contiguous chain of nested providers.info, consistent with otherprefer_*stylistic lint rules.allRules, exported inbloc_lint.dartandrules.dart, added toall.yaml, listed inpackages/bloc_lint/README.md, and documented with examples underdocs/src/content/docs/lint-rules/prefer_multi_bloc_provider.mdx.Verification
lintTesttest cases covering: direct nesting, chain of 3+ nested providers (only outermost reported),.valueconstructor,constconstructor in child, singleBlocProvider(quiet),MultiBlocProvider(quiet), indirect non-child nesting (quiet), different widget nested (quiet), callback closure (quiet), and// ignore: prefer_multi_bloc_provider.dart test: all 160 tests pass inpackages/bloc_lint.prefer_multi_bloc_provider.dart.dart analyze --fatal-infos --fatal-warnings .: 0 issues found.dart format --set-exit-if-changed .: 0 files changed.npm run format:checkandnpm run buildpass with 0 errors).Closes #4453
Type of Change