-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.razor: complexity/cognitive complexity return 0 #7978
.razor: complexity/cognitive complexity return 0 #7978
Conversation
if (GeneratedCodeRecognizer.IsRazor(node.SyntaxTree)) | ||
{ | ||
return new(0, ImmutableArray<SecondaryLocation>.Empty); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will disable also the cognitive complexity rule, not only the metric. This rule is not exclude by: #7879. Could you please check with @csaba-sagi-sonarsource if it makes sense to keep the rule active or not for razor files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personal opinion: If we don't have a reliable count of cognitive complexity for .razor files to be shown in the metrics why would we want a rule that might be raised based on the same flawed logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rule is computing the complexity at the function level. For this kind of limited scope, the precision is better. Please check with @csaba-sagi-sonarsource as he has investigated this already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked with @csaba-sagi-sonarsource and he thinks that the count for the complexity of methods fully declared inside .razor files should be good enough. I changed the implementation to target the metrics only.
if (GeneratedCodeRecognizer.IsRazor(syntaxNode.SyntaxTree)) | ||
{ | ||
return new(ImmutableArray<SecondaryLocation>.Empty); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for cyclomatic complexity.
5db6b41
to
f4045fa
Compare
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
Closing this issue since the computed global cognitive complexity and cyclomatic complexity are correct for .razor files and consider both HTML and C# code. The only question remaining would be if it makes sense to keep S1541 (cyclomatic complexity) and S3776 (cognitive complexity) active. At the moment they are both NOT raising for HTML code (everything that is inside the |
Part of #7936