Which is the reason to have `detekt - ReturnCount:...
# detekt
j
Which is the reason to have
detekt - ReturnCount: Function generateProperties has 3 return statements which exceeds the limit of 2.
? I would like to avoid nesting and doing multiple returns is easy, readable and avoid nesting, for example:
Copy code
override fun generateProperties(
        callableId: CallableId,
        context: MemberGenerationContext?
    ): List<FirPropertySymbol> {
        if (callableId.callableName != atomicName) return emptyList()
        val owner: FirClassSymbol<*> = context?.owner ?: return emptyList()

        ...
    }
h
Having many returns in a function decreases readability since they can be easy to miss when glancing through and thus make it hard to reason about functionality. In general there's something of a code smell if a function can be called with lots of invalid arguments and suggests there may need to be some refactoring of business logic to the callers.
j
I am not sure if I agree in all use cases. I want to skip that
generateProperties
function from the visitor does anything based on those statements, how can I do that with less code and/or being more readable?
e
Guard clauses (like in your
generateProperties
function) shouldn't count towards the return count for that rule. Although now that I think about it, that might not be the default behavior and you have to configure it.
j
That is nice, hope it was true by default
176 Views