fix: resolve false positives in avoid_returning_widgets - #338
fix: resolve false positives in avoid_returning_widgets#338solid-illiaaihistov wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe lint now uses Flutter-qualified widget type checks and return-expression utilities. It skips abstract methods, empty bodies, state widget-casting getters, and directly overridden methods. Tests cover the new exclusions and widget-return scenarios. ChangesAvoid returning widgets lint
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant MethodDeclaration
participant AvoidReturningWidgetsVisitor
participant TypeUtilities
participant Diagnostic
MethodDeclaration->>AvoidReturningWidgetsVisitor: inspect declaration
AvoidReturningWidgetsVisitor->>TypeUtilities: resolve return expression and widget type
TypeUtilities-->>AvoidReturningWidgetsVisitor: return widget classification
AvoidReturningWidgetsVisitor->>Diagnostic: report widget return when no exclusion applies
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@lib/src/lints/avoid_returning_widgets/visitors/avoid_returning_widgets_visitor.dart`:
- Around line 70-82: Update _isStateWidgetCastingGetter to exclude only getters
whose unwrapped return expression is a super.widget access, rather than any
property accessor declared on a State subtype. Validate the unwrapped
expression’s receiver is a super access targeting the widget member, while
preserving the existing enclosing State checks. Add a regression test covering
an unrelated State accessor that must not be excluded.
In `@lib/src/utils/types_utils.dart`:
- Around line 146-148: Restrict _isWidget and _isWidgetState to Flutter’s actual
Widget and State definitions instead of matching only InterfaceElement.name,
using the defining library URI or resolved Flutter elements. Ensure local and
third-party classes named Widget or State are not classified as Flutter types,
and add regressions covering both cases.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 0d59dc05-b11d-4a2c-b526-ed23e52c2509
📒 Files selected for processing (4)
lib/src/lints/avoid_returning_widgets/visitors/avoid_returning_widgets_visitor.dartlib/src/utils/node_utils.dartlib/src/utils/types_utils.darttest/src/lints/avoid_returning_widgets/avoid_returning_widgets_rule_test.dart
…urning_widgets rule to target State.widget accessors
…to super/this receivers
Summary by CodeRabbit
Bug Fixes
avoid_returning_widgetslint to avoid false positives for abstract or empty methods, widget collections, non-widget return types, and inline builder callbacks.Tests