Skip to content

refactor: migrate prefer last#287

Open
andrew-bekhiet-solid wants to merge 5 commits into
278-migrate-prefer_firstfrom
279-migrate-prefer_last
Open

refactor: migrate prefer last#287
andrew-bekhiet-solid wants to merge 5 commits into
278-migrate-prefer_firstfrom
279-migrate-prefer_last

Conversation

@andrew-bekhiet-solid

Copy link
Copy Markdown
Collaborator

Closes #279

@andrew-bekhiet-solid andrew-bekhiet-solid linked an issue Jun 15, 2026 that may be closed by this pull request

@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 migrates the prefer_last lint rule and its associated quick fix to the standard analyzer plugin APIs, refactoring the rule, visitor, and fix implementations while adding a new reflective test suite. The review feedback highlights two key issues: first, the quick fix implementation does not preserve null-awareness (e.g., ?.), which could strip null-safety operators and cause static analysis errors; second, the visitor accesses arguments.first without checking if the argument list is empty, which could throw a StateError and crash the linter during active editing.

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/prefer_last/fixes/prefer_last_fix.dart
Comment thread lib/src/lints/prefer_last/visitors/prefer_last_visitor.dart Outdated
: '${expression.target ?? ''}.last';
} else {
return '.last';
switch (expression) {

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.

should we also add test cases for cascades and null-awares, I think that only makes sense?

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.

Migrate prefer_last

2 participants