Add new rule avoid_duplicate_code#320
Conversation
…obal hash registry
…reporting and improve code formatting
…zer plugin configuration
…uctural config validation, and improved caching settings.
…t method exclusions and cleaning up JSON parsing logic
…or helper methods and improving cache handling
…ized visitors and utility extensions
…al hashing to prevent cache invalidation
…plementing robust cache invalidation, parameter equality checks, and collision guarding.
There was a problem hiding this comment.
Code Review
This pull request introduces a new lint rule, avoid_duplicate_code, which detects structurally identical code blocks (Type 2 clones) both within a single file and across multiple files. It implements structural fingerprinting using a custom Jenkins hasher, global caching via a hash registry, and persistence storage. Feedback on the changes highlights a few critical issues: the operator == and hashCode implementations in AvoidDuplicateCodeParameters are missing the exclude parameter, which can cause stale cache usage; catching only Exception instead of all errors/exceptions in HashCacheStorage could lead to uncaught TypeErrors crashing the analyzer plugin; and passing contextRoot to AvoidDuplicateCodeVisitor in tests would prevent fallback physical file system checks.
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.
…ls for reliable comparison
…ifiers and context root
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new lint rule, avoid_duplicate_code, which detects structurally identical code blocks within and across files. It includes the core rule logic, configuration parameters, caching services via a global hash registry, AST visitors for structural hashing, and comprehensive tests. The review feedback is highly constructive and should be addressed: it suggests optimizing the global hash registry loop to avoid redundant processing, replacing the deprecated SimpleIdentifier.element with node.staticElement, adding null checks in getTokenCount to prevent potential errors on synthetic nodes, and safely resolving contextRoot to avoid null pointer exceptions in part files.
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.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces the avoid_duplicate_code lint rule to detect structurally identical code blocks (Type 2 clones) within and across files. It includes the rule implementation, configuration parameters, structural hashing visitors, caching services, and tests. The review feedback highlights a critical compilation error in AstStructuralHashVisitor where NamedType.name.lexeme is called, a deprecation warning for SimpleIdentifier.element, a potential null pointer issue in getTokenCount, and several path prefix-matching bugs in GlobalHashRegistry that could cause false positives with sibling directories.
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.
…a cycle is detected
…ing directory collisions and encapsulate utility methods.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces the avoid_duplicate_code lint rule to detect structurally identical code blocks (Type 2 clones) within and across files, complete with persistent caching and configuration support. The feedback focuses on improving robustness and compatibility: specifically, using a map of debouncers in GlobalHashRegistry to prevent save cancellations in multi-package workspaces, catching all exceptions during cache operations in HashCacheStorage to avoid crashing the analysis server, and replacing the deprecated SimpleIdentifier.element with staticElement in AstStructuralHashVisitor.
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.
…ts in GlobalHashRegistry
…e to prevent analysis crashes
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new lint rule, avoid_duplicate_code, to detect structurally identical code blocks (Type 2 clones) within and across files. It implements a robust architecture including AST structural hashing, a global hash registry with debounced disk caching, and various utility visitors. The feedback suggests optimizing the _removeFromInvertedIndex method in GlobalHashRegistry by replacing an O(N) removeWhere call with an O(1) remove call, leveraging the existing operator == and hashCode implementations on DuplicateLocation.
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.
…istry instead of filtering by path
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces the avoid_duplicate_code lint rule, which detects structurally identical code blocks (Type 2 clones) within and across files using a custom Jenkins hashing algorithm and a persistent global hash registry. The feedback highlights critical issues, including compilation errors due to deprecated analyzer APIs in AstStructuralHashVisitor, a potential race condition in GlobalHashRegistry under multi-package workspaces, and the direct use of dart:io which bypasses the ResourceProvider abstraction and breaks virtual file system compatibility.
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.
…che saves in multi-package workspaces
…to support testability
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new lint rule, 'avoid_duplicate_code', to detect structurally identical code blocks (Type 2 clones) both within a single file and across files. It implements a global hash registry with persistent caching to support cross-file detection, along with comprehensive tests. A critical issue was identified in 'AstStructuralHashVisitor' where 'node.element' is accessed on a 'SimpleIdentifier' instead of 'node.staticElement', which will cause a compilation error with the Dart 'analyzer' package.
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.
Closes #153