Skip to content

Migrate no equal then else rule and its tests#241

Open
daria-trusca-solid wants to merge 4 commits into
analysis_server_migrationfrom
migrate_no_equal_then_else
Open

Migrate no equal then else rule and its tests#241
daria-trusca-solid wants to merge 4 commits into
analysis_server_migrationfrom
migrate_no_equal_then_else

Conversation

@daria-trusca-solid
Copy link
Copy Markdown
Collaborator

Migrated the no_equal_then_else rule and its corresponding tests to comply with the analyzer package.

Changes

  • Rule Refactoring: Updated the implementation no_equal_then_else to use the current analyzer syntax.
  • Tests: Updated and verified all associated test cases to ensure the rule triggers correctly and no regressions are introduced.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

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 no_equal_then_else lint rule to the standard analyzer AnalysisRule API, updates its visitor to report diagnostics directly, bumps the SDK constraint, and adds a reflective test suite. The review feedback highlights a critical compilation error in NoEqualThenElseRule where a visitor instance is incorrectly passed to addBlockFunctionBody. To resolve this and prevent inefficient, redundant AST traversals, the reviewer recommends registering specific node processors (addIfStatement and addConditionalExpression) and refactoring NoEqualThenElseVisitor to extend SimpleAstVisitor instead of RecursiveAstVisitor.

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 on lines 73 to 74
registry.addBlockFunctionBody(this, visitor);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The current implementation passes visitor (which is a RecursiveAstVisitor<void>) directly to registry.addBlockFunctionBody. This will cause a compilation error because addBlockFunctionBody expects a callback function of type void Function(BlockFunctionBody), not an AST visitor instance.

Furthermore, using a RecursiveAstVisitor inside a registered node processor is highly inefficient and leads to redundant AST traversals and duplicate diagnostics for nested functions or closures.

Instead, you should register specific node processors for IfStatement and ConditionalExpression directly on the registry. This leverages the analyzer's built-in traversal, making the lint rule much more efficient and correct.

    final visitor = NoEqualThenElseVisitor(this);
    registry.addIfStatement(this, visitor.visitIfStatement);
    registry.addConditionalExpression(this, visitor.visitConditionalExpression);

/// The AST visitor that will collect all unnecessary if statements and
/// conditional expressions.
/// Visitor for [NoEqualThenElseRule].
class NoEqualThenElseVisitor extends RecursiveAstVisitor<void> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

To support registering the visitor methods directly on the registry and to avoid redundant/duplicate AST traversals (double-visiting nested nodes), NoEqualThenElseVisitor should extend SimpleAstVisitor<void> instead of RecursiveAstVisitor<void>.

Suggested change
class NoEqualThenElseVisitor extends RecursiveAstVisitor<void> {
class NoEqualThenElseVisitor extends SimpleAstVisitor<void> {

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