Adding Understandability (Sonar Cognitive Complexity)#74
Merged
Conversation
This commit introduces a new set of metrics focused on understandability, enhancing the cognitive analysis capabilities. Key changes include: - Added `UnderstandabilityMetrics` and `UnderstandabilityCalculator` for calculating and summarizing understandability metrics. - Integrated understandability metrics into the existing cognitive metrics framework. - Updated configuration options to enable the display of understandability metrics in reports. - Enhanced the reporting system to include understandability in the output format. - Added tests to ensure the correctness of the new understandability features. These changes aim to provide deeper insights into code complexity and maintainability, aligning with modern coding standards.
- Added new methods in `UnderstandabilityMetrics` for resolving risk levels and count values, improving data handling and robustness. - Updated `Parser` class to include understandability metrics in the analysis process. - Enhanced `CombinedMetricsVisitor` with type annotations for the `getMethodUnderstandability` method. - Added suppression warnings in `UnderstandabilityVisitor` for excessive complexity and method count, promoting cleaner code practices.
- Introduced a new document, Understandability.md, detailing the Sonar Cognitive Complexity metric. - Explained the calculation method, risk levels, and configuration options for enabling understandability metrics. - Provided references to relevant literature and resources for further reading on cognitive complexity.
…d clarity - Updated `UnderstandabilityCalculator` to skip low complexity methods, enhancing risk categorization. - Refined `UnderstandabilityVisitor` logic to return early for ignored classes and non-relevant nodes, improving code readability and maintainability. - Adjusted nesting and logical operator handling to streamline flow and reduce unnecessary checks.
…rstandability output - Introduced a new constant `CACHE_VERSION` in `CognitiveMetricsCollector` to manage cache versioning effectively. - Updated cache item versioning to use the new constant, ensuring stale entries are ignored when the analysis result shape changes. - Enhanced the understandability output in various test files by updating complexity ratings, improving clarity in metrics reporting.
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.
Understandability measures how hard it is for a human to follow a method’s control flow. It implements Sonar Cognitive Complexity as described in SonarSource’s 2023 white paper (Cognitive Complexity: a new way of measuring understandability, v1.7).
This metric is separate from this tool’s weighted Cognitive Complexity score, which sums logarithmic weights over structural metrics (lines, arguments,
ifcount, and so on). Understandability follows Sonar’s rule-based control-flow model instead.