Skip to content

fix: resolve false positives in avoid_returning_widgets - #338

Open
solid-illiaaihistov wants to merge 3 commits into
solid-software:masterfrom
solid-illiaaihistov:fix-avoid_returning_widgets
Open

fix: resolve false positives in avoid_returning_widgets#338
solid-illiaaihistov wants to merge 3 commits into
solid-software:masterfrom
solid-illiaaihistov:fix-avoid_returning_widgets

Conversation

@solid-illiaaihistov

@solid-illiaaihistov solid-illiaaihistov commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Improved the avoid_returning_widgets lint to avoid false positives for abstract or empty methods, widget collections, non-widget return types, and inline builder callbacks.
    • Correctly handles state widget accessors and overridden methods.
    • Improved widget type detection, including widget subclasses, while excluding supported provider-related cases.
  • Tests

    • Added coverage for state classes, widget colors, widget state properties, and related lint scenarios.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e37fd935-9fc0-46fa-9cc7-7d632c869572

📥 Commits

Reviewing files that changed from the base of the PR and between 10eaae0 and 225c90a.

📒 Files selected for processing (1)
  • lib/src/lints/avoid_returning_widgets/visitors/avoid_returning_widgets_visitor.dart
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/src/lints/avoid_returning_widgets/visitors/avoid_returning_widgets_visitor.dart

📝 Walkthrough

Walkthrough

The 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.

Changes

Avoid returning widgets lint

Layer / File(s) Summary
Widget and return-expression utilities
lib/src/utils/types_utils.dart, lib/src/utils/node_utils.dart
Widget detection now uses Flutter interface element names. Method utilities resolve identifiers and extract single return expressions.
Method return filtering
lib/src/lints/avoid_returning_widgets/visitors/avoid_returning_widgets_visitor.dart
The visitor adds exclusions for abstract methods, empty bodies, state widget-casting getters, and directly overridden methods.
Lint regression coverage
test/src/lints/avoid_returning_widgets/avoid_returning_widgets_rule_test.dart
Tests cover collection returns, non-widget returns, abstract methods, state getters, inline builder callbacks, and local widget types.

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
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: fixing false positives in the avoid_returning_widgets lint.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 06b5d55 and 6966168.

📒 Files selected for processing (4)
  • lib/src/lints/avoid_returning_widgets/visitors/avoid_returning_widgets_visitor.dart
  • lib/src/utils/node_utils.dart
  • lib/src/utils/types_utils.dart
  • test/src/lints/avoid_returning_widgets/avoid_returning_widgets_rule_test.dart

Comment thread lib/src/utils/types_utils.dart
Illia Aihistov added 2 commits August 3, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant