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

ComplexMethod should treat "return when" as "single when" expression when ignoring #1054

Closed
dimsuz opened this issue Aug 17, 2018 · 2 comments
Milestone

Comments

@dimsuz
Copy link
Contributor

dimsuz commented Aug 17, 2018

Expected Behavior

When detekt is configured like this:

  ComplexMethod:
    active: true
    threshold: 10
    ignoreSingleWhenExpression: true

This kind of when should be treated as "single when expression" and ignored

fun someFunction(s: String): Boolean {
  return when (s) {
     "bear" -> true
     "log" -> false
     // ... 15 more branches
  }
}

Current Behavior

Currently the code above will report a ComplexMethod rule failure, because it ignores only "non-expression "when's", like

fun someFunction(s: String): Unit {
  when (s) {
     "bear" -> doSomething()
     "log" -> doSomethingElse()
     // ... 15 more branches
  }
}

If you are OK with the proposed change I could create a PR.

@schalkms
Copy link
Member

This shouldn't be the case.
That would be nice if you could create a PR.

dimsuz pushed a commit to dimsuz/detekt that referenced this issue Aug 21, 2018
If configured with "ignoreSingleWhenExpression", ComplexMethod should
not only skip "when", but also "return when"

Fixes detekt#1054
dimsuz pushed a commit to dimsuz/detekt that referenced this issue Aug 22, 2018
If configured with "ignoreSingleWhenExpression", ComplexMethod should
not only skip "when", but also "return when"

Fixes detekt#1054
arturbosch pushed a commit that referenced this issue Aug 31, 2018
If configured with "ignoreSingleWhenExpression", ComplexMethod should
not only skip "when", but also "return when"

Fixes #1054
@arturbosch arturbosch added this to the RC9 milestone Sep 10, 2018
DSamaryan pushed a commit to DSamaryan/detekt that referenced this issue Oct 18, 2018
If configured with "ignoreSingleWhenExpression", ComplexMethod should
not only skip "when", but also "return when"

Fixes detekt#1054
@lock
Copy link

lock bot commented Jun 20, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants