Does anyone have problems getting all of these Cor...
# detekt
k
Does anyone have problems getting all of these Coroutine rules to run? https://detekt.dev/docs/rules/coroutines Only the Globalscope one seems to run in our project (gradle and custom detekt.yml) but I have all of them enabled 🤔 Also tested using the CLI version of Detekt and the --all-rules parameter but that doesn't even show the GlobalScope violation.
I threw all the sample incorrect code into a file to test:
Copy code
// test a few detekt warnings
suspend fun detektWarningMess() {
    GlobalScope.launch {
        withContext(Dispatchers.Unconfined) {
            Thread.sleep(3000)
            unneededSecondSuspend()
        }
    }
}

suspend fun unneededSecondSuspend() {
    println("blah")
}

suspend fun CoroutineScope.unneededExtensionSuspend() {
    launch {
        delay(1000)
    }
}

suspend fun unneededSuspendFlow(): Flow<Unit> {
    val pollingInterval = 123L
    return flow {
        while (true) {
            delay(pollingInterval)
            emit(Unit)
        }
    }
}
Also added --debug to the CLI version of detekt and it claims the coroutines ruleset is loaded 🤔
Copy code
Registered rule sets:
    io.gitlab.arturbosch.detekt.rules.bugs.PotentialBugProvider@fe34b86
    io.gitlab.arturbosch.detekt.rules.complexity.ComplexityProvider@3c98781a
    io.gitlab.arturbosch.detekt.rules.coroutines.CoroutinesProvider@3f736a16
    io.gitlab.arturbosch.detekt.rules.documentation.CommentSmellProvider@4601203a
    io.gitlab.arturbosch.detekt.rules.empty.EmptyCodeProvider@53abfc07
    io.gitlab.arturbosch.detekt.rules.exceptions.ExceptionsProvider@2c8c16c0
    io.gitlab.arturbosch.detekt.rules.naming.NamingProvider@80bfa9d
    io.gitlab.arturbosch.detekt.rules.performance.PerformanceProvider@47c40b56
    io.gitlab.arturbosch.detekt.rules.style.StyleGuideProvider@4b039c6d
hmmm...maybe this: The rule 'InjectDispatcher' requires type resolution but it was run without it.
Not obvious...detekt should probably put up a BIG warning when rules are run w/o type resolution in the gradle plugin.
Hmm...even when you run detektMain or detektDebug, only the InjectDispatcher rule works out of the ones that are listed are requiring type resolution 🤔
The IDE flags all of them though...just that CI won't
FYI, this works when running the gradle task on detektDebug for me (all rules show up).
b
That's strange...
Enabling type resolution should work
k
Sorry it did...was just a running log of all the things I tried to get to the end state. We missed the type configuration configuration and didn't notice it was needed for the new rules when upgrading Detekt a while back.
Some more "in your face" warning when rules are enabled but skipped because type resolution isn't used would probably be a good idea..
Hmm..ok..maybe not. It's inconsistent. Sometimes the InjectDispatcher rule runs, sometimes it doesn't when I run the detektDebug task. EDIT: build cache issue....detekt results apparently go into the remote build cache so it only reruns if the code changes.
one more thing that was unexpected is if you run a different detekt<variant> task, the filename for the report changes. CI was looking for detekt.xml but if you run the detektDebug task, the report is named "debug.xml" instead...
b
A lot of things here. The information about "this rule has not been executed" was there. But it was reported as far too much noise so we removed it... It is difficult to make happy to everyone :(
If you see flaky results, please open an issue with a way to reproduce them. That should not happen.
And yes, the reports have different name because if you run
detektMain
it will execute it for debug and for release. And you don't want to get only one of those reports. You want both. So, for that reason, they should have different names.
k
yep, makes sense. I was just documenting in the thread in case anyone searches for this 🙂
Disappointed folks didn't like the "rule was not executed" warning though 🤦‍♂️ Just disable it in detekt.yml then... 😂