Description
Hi everyone! We incorporated detekt in our project a while ago and, while we like it very much, we've been noticing that it seems to report issues even when the checks are "on" the threshold and not after crossing it.
Expected Behavior
For this example, imagine any function, with three nested blocks.
fun myFunction(): Boolean {
someNullableVariable?.let {
if (something) {
// do something
if (something else) {
return true
}
}
return false
}
We expect detekt not to report anything, since it's configure like so:
NestedBlockDepth:
active: true
threshold: 3
Observed Behavior
The function is reported to have infringed the NestedBlockDepth rule:
NestedBlockDepth - 3/3 - [applyInternal] at <path>/<file>.kt:16:18
My team and I believe that this should not be reported, since the number of nested blocks is 3 from the allowed 3 nested blocks. The issue should only be raised, when the set threshold is crossed, for instance at an event where 4/3
could be observed.
Steps to Reproduce
- Write a similar function
- Have detekt in your project with the same settings for NestedBlockDepth
Context
This does not only happen with NestedBlockDepth, but every single rule is treated as such in detekt. While we want to use detekt to ensure code quality, we do not want to have "add one to the real threshold" or suppress the rule in order to get away with it. Also after a while the question could become "Was this a 3 or a 4? The config says 4, so why is 4 not allowed?", mainly if new colleagues come to the project, or the ones that instituted detekt and the rules move to another project.
Your Environment
- Version of detekt used: 1.15.0
- Version of Gradle used (if applicable): 6.8
- Operating System and version: macOS Big Sur 11.2.3