Skip to content

refactor: migrate cyclomatic_complexity#294

Open
solid-illiaaihistov wants to merge 11 commits into
solid-software:analysis_server_migrationfrom
solid-illiaaihistov:250-migrate-cyclomatic_complexity
Open

refactor: migrate cyclomatic_complexity#294
solid-illiaaihistov wants to merge 11 commits into
solid-software:analysis_server_migrationfrom
solid-illiaaihistov:250-migrate-cyclomatic_complexity

Conversation

@solid-illiaaihistov

Copy link
Copy Markdown
Collaborator

Closes #250

@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 refactors the cyclomatic_complexity lint rule to use the updated analyzer APIs, replacing the token-based matching in CyclomaticComplexityFlowVisitor with node-specific AST visitors and introducing a new CyclomaticComplexityVisitor. It also replaces the old test file with a comprehensive suite of unit tests. The review feedback highlights a compilation error due to a non-existent property on LintCode, and suggests extending the complexity checks to cover constructor declarations and do-while loops.

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/cyclomatic_complexity/cyclomatic_complexity_rule.dart Outdated
Comment thread lib/src/lints/cyclomatic_complexity/visitors/cyclomatic_complexity_visitor.dart Outdated
@solid-illiaaihistov

Copy link
Copy Markdown
Collaborator 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 refactors the cyclomatic_complexity lint rule to use the new RuleVisitorRegistry and RuleContext API. It replaces the token-based block visitor with a structured AST visitor (CyclomaticComplexityVisitor and CyclomaticComplexityFlowVisitor) that handles various Dart language constructs such as switch expressions, patterns, and logical operators, while correctly ignoring nested functions and closures. Additionally, a comprehensive test suite has been added. Feedback suggests extending the complexity calculation to support collection elements (IfElement and ForElement) and adding corresponding test cases.

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 test/src/lints/cyclomatic_complexity/cyclomatic_complexity_rule_test.dart Outdated
…perators in cyclomatic complexity calculation
@solid-illiaaihistov

Copy link
Copy Markdown
Collaborator 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 refactors the CyclomaticComplexityRule to use the updated analyzer API (RuleVisitorRegistry and RuleContext). It introduces a new CyclomaticComplexityVisitor to traverse function, constructor, and method declarations, and updates CyclomaticComplexityFlowVisitor to support modern Dart features (such as switch expressions, patterns, null-aware cascades, and spreads) while stopping recursion into nested functions or closures. Comprehensive tests have also been added. The reviewer suggests further improving the accuracy of the cyclomatic complexity metric by counting NullCheckPattern and NullAssertPattern as complexity-increasing entities.

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.

@solid-illiaaihistov

Copy link
Copy Markdown
Collaborator 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 refactors the cyclomatic complexity lint rule to use the updated analyzer APIs and significantly expands its coverage to support Dart 3 features such as switch expressions, patterns, collection elements, and null-aware operators. It also replaces the old test file with a robust suite of unit tests. The review feedback suggests a key performance optimization: instead of using a recursive visitor over the entire compilation unit, the rule should register node processors directly for function, constructor, and method declarations, which would also allow the removal of the redundant CyclomaticComplexityVisitor class.

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/cyclomatic_complexity/cyclomatic_complexity_rule.dart
Comment thread lib/src/lints/cyclomatic_complexity/cyclomatic_complexity_rule.dart
Comment thread lib/src/lints/cyclomatic_complexity/visitors/cyclomatic_complexity_visitor.dart Outdated

@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 refactors the cyclomatic complexity lint rule to use the new analyzer API, moving the logic into CyclomaticComplexityVisitor and CyclomaticComplexityFlowVisitor. It also expands the AST nodes that contribute to complexity (such as switch expressions, patterns, null-aware cascades, and spreads) and adds comprehensive unit tests. The review feedback suggests supporting cyclomatic complexity checks for anonymous closures by overriding visitFunctionExpression instead of visitFunctionDeclaration in CyclomaticComplexityVisitor, which ensures complex closures are not ignored while still respecting exclusion rules.

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/cyclomatic_complexity/visitors/cyclomatic_complexity_visitor.dart Outdated

@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 refactors the cyclomatic_complexity lint rule to use the updated analyzer APIs (RuleVisitorRegistry and RuleContext) and introduces a more robust AST visitor structure (CyclomaticComplexityVisitor and CyclomaticComplexityFlowVisitor) to accurately calculate cyclomatic complexity across various Dart language features. It also replaces the old test file with a comprehensive reflective test suite. The review feedback suggests extending the complexity visitor to account for null-aware function expression invocations (e.g., func?.()) and adding a corresponding test case to verify this behavior.

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.

@solid-illiaaihistov

Copy link
Copy Markdown
Collaborator 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 refactors the CyclomaticComplexityRule to use the newer analyzer APIs (RuleVisitorRegistry and RuleContext) and introduces a new CyclomaticComplexityVisitor to traverse declarations. The CyclomaticComplexityFlowVisitor has been updated to visit a wider range of AST nodes (such as switch expressions, patterns, collection elements, and null-aware operators) to compute cyclomatic complexity. Feedback points out that ForEachStatement (for-in loops) is currently unhandled by the visitor, meaning their complexity is ignored. It is recommended to override visitForEachStatement and add corresponding test coverage.

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.

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