You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
ComplexCondition
Complex conditions make it hard to understand which cases lead to the condition being true or false. To improve readability and understanding of complex conditions consider extracting them into well-named functions or variables and call those instead.
Severity: Maintainability
Debt: 20min
Configuration options:
threshold (default: 4) - the number of conditions which will trigger the rule
Noncompliant Code:
val str = "foo"
val isFoo = if (str.startsWith("foo") && !str.endsWith("foo") && !str.endsWith("bar") && !str.endsWith("_")) {
// ...
}
Compliant Code:
val str = "foo"
val isFoo = if (str.startsWith("foo") && hasCorrectEnding()) {
// ...
}
fun hasCorrectEnding() = return !str.endsWith("foo") && !str.endsWith("bar") && !str.endsWith("_")
What is actually displayed in sonarqube:
Complex conditions should be simplified and extracted into well-named methods if necessary.
You see the usability of the plugin is much lower if developers have to always go to the website to find out what each rule actually means.
The text was updated successfully, but these errors were encountered:
It would be great if the rule descriptions insider sonarqube were better than just a single sentence.
For example what is on the website:
https://detekt.github.io/detekt/complexity.html#complexcondition
What is actually displayed in sonarqube:
You see the usability of the plugin is much lower if developers have to always go to the website to find out what each rule actually means.
The text was updated successfully, but these errors were encountered: