-
-
Notifications
You must be signed in to change notification settings - Fork 774
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
Make "ComplexMethod" rule also ignore "return when" if configured #1062
Make "ComplexMethod" rule also ignore "return when" if configured #1062
Conversation
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.
Looks good to me!
Can you please also test this with single-expression functions. I don't think that the rule reports this atm. fun f(): Int {
return when { ... }
} |
Do you mean that this rule should treat |
@dimsuz Sry I have updated my comment. I meant that the rule should also report a comment if the single expression syntax is used. |
Ah, ok! I will test this tomorrow and write back:
|
Okay. I think we were talking at cross purposes. Adding the following snippet as another test case should report a violation. Note that I took your test code and just used the single expression syntax. Atm this case is not handled by the fun complexMethodWithSingleWhen4(i: Int) = when (i) {
1 -> "one"
2 -> "two"
3 -> "three"
else -> ""
} |
Oh, right! I got mixed up between "single expression inside the body" and "single expression function syntax" . Ok, so I should test that your snippet above
In other words I hope I got it right this time 🙂. I will also add test(s) for these cases. |
If configured with "ignoreSingleWhenExpression", ComplexMethod should not only skip "when", but also "return when" Fixes detekt#1054
73f25c4
to
5d154eb
Compare
I have updated the code and the tests to handle a "function single expression" syntax. In |
It turned out that your snippet above is already handled and is reported as |
If configured with "ignoreSingleWhenExpression", ComplexMethod should
not only skip "when", but also "return when"
Fixes #1054