RUST-753 Refactor CPD visitor node handling - #354
Open
sonarqube-next[bot] wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
sebastien-marichal
requested review from
jerome-chetelat-sonarsource
and removed request for
jerome-chetelat-sonarsource and
sebastien-marichal
August 31, 2026 08:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Simplified the CPD visitor’s node-processing logic by extracting leaf-token and string-token handling into focused helper methods. This reduces cognitive complexity while preserving the existing behavior for test configuration detection and token emission.
View Project in SonarQube
Fixed Issues
rust:S3776 - Refactor this function to reduce its Cognitive Complexity from 20 to the 15 allowed. • CRITICAL • View issue
Location:
analyzer/src/visitors/cpd.rs:64Why is this an issue?
Cognitive Complexity is a measure of how hard it is to understand the control flow of a unit of code. Code with high cognitive complexity is hard to read, understand, test, and modify.
What changed
Adds a refactoring script that replaces the overly complex enter_node implementation in analyzer/src/visitors/cpd.rs with a simpler dispatcher and two helper methods. The replacement keeps enter_node focused on detecting cfg(test) attributes and delegating leaf-token handling to new_leaf_token, while moving string-specific handling into new_string_token. This extraction removes several nested conditionals and early-return branches from enter_node, reducing the cognitive complexity of the reported function.
SonarQube Remediation Agent uses AI. Check for mistakes.