A suspend function returns a Flow, which is cold and needs no suspension to create
What it finds
suspend fun updates(): Flow<Int>: a flow does its work when it is collected, so creating one needs no suspension. The modifier makes callers suspend for nothing, and work done before the flow is returned runs at the call instead of at collection, which surprises callers.
Reported for Flow, StateFlow and SharedFlow as the declared result.
From the rule's source, suspend_returns_flow.rs.
import kotlinx.coroutines.flow.* interface Repository { suspend fun updates(): Flow<Int>tx0 reports: updates is suspend but returns a Flow fun changes(): Flow<Int> suspend fun state(): StateFlow<String>tx0 reports: returns a StateFlow suspend fun current(): Int} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:suspend-function-returns-flow" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/kotlin:suspend-function-returns-flow] reason="..."tx0 explain tx0/kotlin:suspend-function-returns-flow shows the same in the terminal. Found a false positive? Report it.