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
Currently else if is assessed as nested if, so it counted as +1 +nesting level complexity, and else is not counted as complexity.
@Test
fun`else should counts as complexity`() {
val code = compileContentForTest(
""" fun test(condition: Boolean) { if (condition) { // do something } else { // do something } }""".trimIndent()
)
assertThat(CognitiveComplexity.calculate(code)).isEqualTo(2) // was: 1
}
@Test
fun`else if should counts as 1 complexity`() {
val code = compileContentForTest(
""" fun test(condition: Boolean) { if (condition) { // do something } else if (condition) { // do something } }""".trimIndent()
)
assertThat(CognitiveComplexity.calculate(code)).isEqualTo(2) // but was: 3
}
It assesses hybrid increments for:
● else if, elif, else, …
No nesting increment is assessed for these structures because the mental cost has already been paid when reading the if.
Not including else affects the accuracy of complexity, and the explanation of why else if should be counted as +1 seems to be logical, so it would be good to follow the implementation of the paper.
The text was updated successfully, but these errors were encountered:
Expected Behavior
Count
else if
orelse
as +1 complexity.Current Behavior
Currently
else if
is assessed as nestedif
, so it counted as +1 +nesting level complexity, andelse
is not counted as complexity.Context
According to paper of Cognitive Complexity,
else if
orelse
should be counted as +1 code complexity.Not including
else
affects the accuracy of complexity, and the explanation of whyelse if
should be counted as +1 seems to be logical, so it would be good to follow the implementation of the paper.The text was updated successfully, but these errors were encountered: