https://kotlinlang.org logo
#detekt
Title
# detekt
j

Joe

03/19/2021, 8:01 PM
I have factory methods in a companion object that are inline so that they can use a reified type parameter which are triggering the
MemberNameEqualsClassName
rule. Is inline factory functions a known issue with this rule (or am I perhaps doing something else wrong that's making it trigger)?
b

Brais Gabin

03/19/2021, 9:21 PM
That's strange. The inline should not affect at all. Could you provide a sample?
j

Joe

03/19/2021, 11:22 PM
Copy code
data class FieldInfo<T>(

    val alias: String,
    val extractor: (String) -> T
) {
    companion object {
        // this complains about MemberNameEqualsClassName
        inline fun <reified T> fieldInfo(
            alias: String,
            noinline extractor: (String) -> T
        ): FieldInfo<T> {
            return FieldInfo(alias, extractor)
        }
    }
}
b

Brais Gabin

03/20/2021, 12:23 AM
It's not related with the inline. The function inside your companion object has the same name as your class so
MemberNameEqualsClassName
flags it. I don't know what's the reason behind this rule but it flags your code correctly. If you don't agree with the rule you can disable it or if you agree with it you should rename the function.
j

Joe

03/20/2021, 5:20 AM
Ok, the rule docs claim "factory" functions are allowed though... Not exactly sure what the definition of factory it uses is?
b

Brais Gabin

03/22/2021, 10:52 AM
No idea you can check the tests of that rule and maybe it gives you some hints. Anyway you can open an issue about this. Because, at least, there is an issue in the documentation
j

Joe

03/22/2021, 3:48 PM
👍 thanks, i'll try to find the minimum reproducible case and file one
5 Views