Migrate no equal then else rule and its tests#241
Conversation
There was a problem hiding this comment.
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.
| registry.addBlockFunctionBody(this, visitor); | ||
| } |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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>.
| class NoEqualThenElseVisitor extends RecursiveAstVisitor<void> { | |
| class NoEqualThenElseVisitor extends SimpleAstVisitor<void> { |
Migrated the
no_equal_then_elserule and its corresponding tests to comply with the analyzer package.Changes
no_equal_then_elseto use the current analyzer syntax.