detekt/detekt

New rule: Forbidden return type

Aberta

#7.790 aberto em 18 de nov. de 2024

 (8 comentários) (3 reações) (0 responsável)Kotlin (834 forks)batch import
help wantedrules

Métricas do repositório

Stars
 (6.942 estrelas)
Métricas de merge de PR
 (Mesclagem média 4d 9h) (65 fundiu PRs em 30d)

Description

I went through existing rules and I haven't find existing rule. Sorry if I happened to miss it 🙏🏼

Expected Behavior of the rule

"style" rule, that prevents specific function / property return types. I want to prevent specific type, but only for code with public API.

Context

In my case, I want to prevent having public functions or properties, that have Pair return type. I think this kind of types make code harder to understand.

// Bad
fun query(): Pair<Int, String> = TODO()
val query: Pair<Int, String> = TODO()

// Good
data class QueryResult(
    val id: Int,
    val name: String
)
fun query(): QueryResult = TODO()
val query: QueryResult = TODO()
private fun somethingInternal(): Pair<Int, Int>

Guia do colaborador