Skip to content

fix: avoid_unnecessary_return_variable#283

Closed
solid-illiaaihistov wants to merge 1 commit into
solid-software:masterfrom
solid-illiaaihistov:fix-236-avoid-unnecessary-return-variable
Closed

fix: avoid_unnecessary_return_variable#283
solid-illiaaihistov wants to merge 1 commit into
solid-software:masterfrom
solid-illiaaihistov:fix-236-avoid-unnecessary-return-variable

Conversation

@solid-illiaaihistov

Copy link
Copy Markdown
Collaborator

Closed #236

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the avoid_unnecessary_return_variable lint rule to traverse the enclosing FunctionBody instead of just the immediate parent block of the return statement. This correctly handles cases where a variable is declared in an outer block and returned within a nested block (such as an if statement), preventing false positives. A test case has been added to verify this behavior. No review comments were provided, and the changes look correct.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.


final blockBody = statement.parent;
if (blockBody == null) return;
final functionBody = statement.thisOrAncestorOfType<FunctionBody>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what about cases like:

final a = 3;
if (b) {
  return a;
}

a is still unnecessary here. Let's also add a test case like that

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.

bug: false positive avoid_unnecessary_return_variable

2 participants