is there a rule, that would check for unnecessary ...
# detekt
p
is there a rule, that would check for unnecessary functions in final classes? For example
isInputValid()
:
Copy code
data class EmailSignUpState(
    val emailValid: Boolean = false,
    val passwordValid: Boolean = false,
) {
    fun isInputValid(): Boolean {
        return emailValid && passwordValid
    }
}
b
There is a rule that forbids functions on data classrs
m
Why do you consider this function unnecessary?
👍 1
p
hm, I think there are some use cases for functions, sometimes
because all fields are final?
Copy code
val isInputValid = emailValid && passwordValid
I felt like that makes sense 🤔
m
That is true but to me this feels very nitpicky to prohibit this. How big is the performance impact really?
p
probably no performance gain. Maybe more like a code style choice. More compact and less brackets, dunno 🙂
b
But even if they are not final you can do the same using
val ... get()
. Any function without parameters can be replaced with a property
But, anyways I feel that something like that would be a very controversial role so a third party rule seems the place for it.
p
I guess it could still be a rule that is disabled by default, if my use case seems valid to you
b
To me it is not valid. I mean, I don't see any problem with that function. Probably I would write it as an extension function or extension property.
👍 1