Skip to content

Add use_nearest_context lint rule (#190)#288

Open
solid-illiaaihistov wants to merge 2 commits into
solid-software:masterfrom
solid-illiaaihistov:issue-190-implement-use-nearest-context
Open

Add use_nearest_context lint rule (#190)#288
solid-illiaaihistov wants to merge 2 commits into
solid-software:masterfrom
solid-illiaaihistov:issue-190-implement-use-nearest-context

Conversation

@solid-illiaaihistov

Copy link
Copy Markdown
Contributor

Closes #190

@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 introduces the use_nearest_context lint rule and its corresponding quick fix, which ensures that BuildContext is used from the nearest available scope. The feedback highlights two critical issues: first, the quick fix is currently broken for anonymous functions and builders because it only registers listeners for FunctionDeclaration and MethodDeclaration instead of applying the replacement directly; second, the lint rule suffers from several false positives, such as triggering on variable declarations, named argument labels, and properties of other objects, which need to be explicitly ignored.

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.

Comment thread lib/src/lints/use_nearest_context/fixes/use_nearest_context_fix.dart Outdated
Comment thread lib/src/lints/use_nearest_context/use_nearest_context_rule.dart
@solid-illiaaihistov

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 introduces a new lint rule, use_nearest_context, which ensures that BuildContext is accessed from the nearest available scope in Flutter applications. It includes the rule implementation, a corresponding quick fix to rename the context parameter, integration into the linter package, and comprehensive test cases. The feedback recommends simplifying the analyzer API usage in use_nearest_context_rule.dart by using element.nameOffset and declaredElement?.type directly, which eliminates unnecessary null checks and fragment traversals.

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.

Comment thread lib/src/lints/use_nearest_context/use_nearest_context_rule.dart
Comment thread lib/src/lints/use_nearest_context/use_nearest_context_rule.dart
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.

Implement "use_nearest_context" rule

1 participant