Skip to content

Fix avoid_context_read_in_build false positive on non-widget-returning callbacks - #566

Merged
PiotrRogulski merged 4 commits into
masterfrom
claude/context-read-build-false-positive-ybv13m
Aug 15, 2026
Merged

Fix avoid_context_read_in_build false positive on non-widget-returning callbacks#566
PiotrRogulski merged 4 commits into
masterfrom
claude/context-read-build-false-positive-ybv13m

Conversation

@PiotrRogulski

Copy link
Copy Markdown
Member

Summary

  • avoid_context_read_in_build was flagging context.read inside a provider's create callback (e.g. BlocProvider(create: (context) => MyCubit(repo: context.read()))), even though create runs lazily once rather than on every rebuild.
  • A BuildContext-taking closure is now only treated as running during build if it also returns a Widget. Non-widget-returning closures (a provider's create, or any other lazy factory) are exempt regardless of the callback's name or the enclosing widget's name.

Test plan

  • dart test on packages/leancode_lint — 253/253 passing
  • dart analyze — no issues
  • dart format --set-exit-if-changed — no changes needed
  • Added tests covering the original false positive and confirming the exemption tracks return type, not naming conventions

Generated by Claude Code

claude added 4 commits August 14, 2026 21:21
…lbacks

context.read() inside a provider's create callback (BlocProvider,
RepositoryProvider, Provider, ...) was being flagged even though create
runs lazily once to construct the provided value, not on every rebuild,
making read() the correct choice there.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FadFXZpP7Bzd3yPQwNorQZ
Replace the class-name-based special case for provider create callbacks
with a general rule: a BuildContext-taking closure only counts as
running during build if it actually produces a Widget. Non-widget-
returning callbacks (create, or any other lazy factory) are exempt
regardless of parameter name or enclosing widget name.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FadFXZpP7Bzd3yPQwNorQZ
@github-actions github-actions Bot added the p: leancode_lint Related to the leancode_lint package label Aug 14, 2026
@PiotrRogulski
PiotrRogulski marked this pull request as ready for review August 14, 2026 21:55
@PiotrRogulski
PiotrRogulski requested a review from mchudy as a code owner August 14, 2026 21:55
@PiotrRogulski
PiotrRogulski merged commit 799a28c into master Aug 15, 2026
4 checks passed
@PiotrRogulski
PiotrRogulski deleted the claude/context-read-build-false-positive-ybv13m branch August 15, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: leancode_lint Related to the leancode_lint package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants