Skip to content
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

Return the actual values for complexity rules #2557

Closed
swsms opened this issue Mar 30, 2020 · 2 comments
Closed

Return the actual values for complexity rules #2557

swsms opened this issue Mar 30, 2020 · 2 comments

Comments

@swsms
Copy link
Contributor

swsms commented Mar 30, 2020

Expected Behavior

I'd like to get the actual values for the ComplexMethod, LongMethod and ComplexCondition rules in the message from Detekt.

Current Behavior

At this moment, Detekt returns messages without actual values for metrics.

For the rule ComplexMethod it returns a message without a value:
The function main appears to be too complex.

For the rule LongMethod it returns only the threshold (but not the actual value):
The function main is too long. The maximum length is 60.

For the rule ComplexCondition, it returns neither actual nor threshold values:
'This condition is too complex.'

At the same time, standard linters for other languages often returns these value.

For example, checkstyle does it for all the metrics:

  • Cyclomatic Complexity is 15 (max allowed is 14).
  • NCSS for this method is 120 (max allowed is 100).
  • Boolean expression complexity is 6 (max allowed is 4).

Context

We build an education platform and analyze learner's solutions for our code challenges. We parse all the output from linters and take all the values to produce some general feedback for their code. In addition, learners can use the values to simplify their code. If the actual value is displayed it's easy to see how much more a learner needs to simplify the functions. This is especially helpful for beginners in Kotlin.

@swsms swsms changed the title Return the value for the ComplexMethod rule Return the actual values for complexity rules Mar 30, 2020
@schalkms
Copy link
Member

schalkms commented Mar 30, 2020

Good idea! Please go ahead.
May I ask you @swsms to submit a PR with your suggestions, so that we can review and merge it later?
It better highlights the changes, when one sees the actual code.

The following lines need to be adapted (including tests):

https://github.com/arturbosch/detekt/blob/21ea09012e72e8f7cfd08ac0e275bfee5484ae5e/detekt-rules/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/ComplexCondition.kt#L80-L83

https://github.com/arturbosch/detekt/blob/21ea09012e72e8f7cfd08ac0e275bfee5484ae5e/detekt-rules/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/complexity/LongMethod.kt#L50-L53

@swsms
Copy link
Contributor Author

swsms commented Mar 30, 2020

@schalkms yes, I can do that. I am happy that my suggestion is right for you.
UPD: here is the PR.

@arturbosch arturbosch added this to the 1.7.3 milestone Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants