fix: avoid_unnecessary_return_variable#283
Conversation
There was a problem hiding this comment.
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>(); |
There was a problem hiding this comment.
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
Closed #236