-
-
Notifications
You must be signed in to change notification settings - Fork 766
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
LongMethod should not consider parameters while calculating the number of lines #2804
Comments
Agree, this sounds like a false positive. Would you be able to work on a fix and make the tests in #2806 green (thank you for doing so btw)? We can support you in that if needed 👍 |
Yes, I am working on it. Will make some noise if I get stuck. |
Assigning the issue to you so that we don't step on your toes 👍 |
I wanted to get opinions from others before making any further changes. For a top-level method, should the lines used by a nested method parameter list be considered in calculating the method length. In the example below, the top-level body has 4 lines if we ignore the nested method.
|
It is a good practice to decompose a large function into smaller ones. In kotlin we have local functions. So we should exclude them completely (whole signature). I've answered in #2806; so basically #loc of longMethod.body - #loc of whole nestedLongMethod |
* failing tests for #2804 LongMethod with params * fix test * skipTrees for KtParameterList for linesOfCode * use test snippets that compile * [ci ckip] use fun body for LongMethod - revert changes in LinesOfCode.kt - still need to update nested methods * remove unused import * add functionToBodyLinesCache to track fun body length * remove spaces from test asserts
Expected Behavior
LongMethod should consider the method definition without the input parameters.
Example:
If
LongMethod
threshold is set to 7, then the below method shouldn't be tagged as the method implementation is actually 3 loc and detekt already hasLongParameterList
to check the param listObserved Behavior
The above snippet of code gets tagged with
LongMethod
code smellSteps to Reproduce
#2806
Context
More LongMethod code smell then expected
Your Environment
The text was updated successfully, but these errors were encountered: