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
Allow the user to choose between cyclomatic and cognitive complexity in ComplexMethod rule #5349
Comments
Shouldn't this be another rule instead if the user whish to have both reported? |
If no one is working on this issue, can I work on this issue? I'm going to rename |
I believe that in this case is fine to rename the rule as long as:
I've assigned this issue to you @sanggggg Let me know if you need further support 👍 |
I've made draft PR #5442, but there's a point I want to ask for help. IMHO, It is awkward that implementation details such as Cyclomatic and Cognitive are exposed to the rule's name.
And there are also minor questions encountered during the implementation.
Sorry for the passive questions, I haven't written many good test codes or opensource contributions yet, so I'd like to get some help. |
I think that Cognitive complexity and Cyclomatic complexity are not implementation details. They are two different concepts and it have sense to have them upfront. So I'm ok having those names for rules.
Maybe I'm wrong here but we just provide
Sure, there is no need to test what
Don't be sorry. All these questions have a lot of sense and we are more than happy to help. |
thank you for your kind response, @BraisGabin
I also think it's a good idea to disable |
Expected Behavior
The cyclomatic complexity calculates how many paths there are in a function.
It is a measurement for testability as the number of paths tells us how many test cases we need to write.
For example a class with 10x mcabe=1 functions would accumulate to complexity 10 and a class with just one function which is nested a lot could still accumulate to complexity 10.
Most users will say that both classes are not equal complex but the deeper nested one is.
Here comes the cognitive complexity into play. It takes nesting into count and would calculate a much higher value for the one function with deep nesting.
detekt/detekt-metrics/src/main/kotlin/io/github/detekt/metrics/CognitiveComplexity.kt
Lines 28 to 36 in 31520da
To not break users baselines and CI's, we could let the user choose the complexity metric to calculate:
Current Behavior
Cyclomatic complexity is used to calculate function complexity.
Context
Cyclomatic complexity does not really measure the complexity but the testability of a function.
Cognitive complexity was described in https://www.sonarsource.com/docs/CognitiveComplexity.pdf to take function nesting into count.
The text was updated successfully, but these errors were encountered: