Skip to content

Add new rule avoid_duplicate_code#320

Open
solid-illiaaihistov wants to merge 28 commits into
solid-software:analysis_server_migrationfrom
solid-illiaaihistov:153-add-avoid_duplicate_code_rule
Open

Add new rule avoid_duplicate_code#320
solid-illiaaihistov wants to merge 28 commits into
solid-software:analysis_server_migrationfrom
solid-illiaaihistov:153-add-avoid_duplicate_code_rule

Conversation

@solid-illiaaihistov

Copy link
Copy Markdown
Collaborator

Closes #153

Illia Aihistov added 17 commits July 8, 2026 16:02
…uctural config validation, and improved caching settings.
…t method exclusions and cleaning up JSON parsing logic
…or helper methods and improving cache handling
…plementing robust cache invalidation, parameter equality checks, and collision guarding.

@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 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.

Comment thread lib/src/lints/avoid_duplicate_code/services/hash_cache_storage.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 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.

Comment thread lib/src/lints/avoid_duplicate_code/services/global_hash_registry.dart Outdated
Comment thread lib/src/lints/avoid_duplicate_code/utils/token_utils.dart Outdated
Comment thread lib/src/lints/avoid_duplicate_code/avoid_duplicate_code_rule.dart
@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 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.

Comment thread lib/src/lints/avoid_duplicate_code/utils/token_utils.dart Outdated
Comment thread lib/src/lints/avoid_duplicate_code/services/global_hash_registry.dart Outdated
Illia Aihistov added 2 commits July 15, 2026 12:52
@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 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.

Comment thread lib/src/lints/avoid_duplicate_code/services/global_hash_registry.dart Outdated
Comment thread lib/src/lints/avoid_duplicate_code/services/hash_cache_storage.dart Outdated
Comment thread lib/src/lints/avoid_duplicate_code/services/hash_cache_storage.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 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.

@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 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.

Comment thread lib/src/lints/avoid_duplicate_code/services/global_hash_registry.dart Outdated
Comment thread lib/src/lints/avoid_duplicate_code/services/global_hash_registry.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 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.

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