in rules/common/src/main/kotlin/com/twitter/compose/rules/ComposeNaming.kt [15:39]
override fun visitComposable(function: KtFunction, autoCorrect: Boolean, emitter: Emitter) {
// If it's a block we can't know if there is a return type or not from ktlint
if (!function.hasBlockBody()) return
val functionName = function.name?.takeUnless(String::isEmpty) ?: return
val firstLetter = functionName.first()
if (function.returnsValue) {
// If it returns value, the composable should start with a lowercase letter
if (firstLetter.isUpperCase()) {
// If it's allowed, we don't report it
val isAllowed = function.config().getSet("allowedComposableFunctionNames", emptySet())
.any {
it.toRegex().matches(functionName)
}
if (isAllowed) return
emitter.report(function, ComposablesThatReturnResultsShouldBeLowercase)
}
} else {
// If it returns Unit or doesn't have a return type, we should start with an uppercase letter
// If the composable has a receiver, we can ignore this.
if (firstLetter.isLowerCase() && !function.hasReceiverType) {
emitter.report(function, ComposablesThatDoNotReturnResultsShouldBeCapitalized)
}
}
}