-
-
Notifications
You must be signed in to change notification settings - Fork 757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change OptionalUnit to report Unit returned by method implementations in interfaces #3099
Comments
I think that this is a legit use of Unit. I think that this is better than an empty block. It demostrate more intentionality. I'm not sure if I prefer that or an empty block with a |
Brais is right. I remember this discussion from another thread. I think we decided to keep it like that, because otherwise the EmptyFunction rule would be triggered. |
EmptyFunction ignores that case: override fun visitNamedFunction(function: KtNamedFunction) {
super.visitNamedFunction(function)
if (function.isOpen() || function.isDefaultFunction()) {
return
}
...
}
private fun KtNamedFunction.isDefaultFunction() =
getParentOfType<KtClass>(true)?.isInterface() == true && hasBody() So writing this should not flag any rule: interface Foo {
fun onMapClicked(point: Point?) {}
} |
It was an intentional commit back then (7797809) without further context though. |
It seems like that I missed this. This change came in after the linked PR. |
Expected Behavior of the rule
This gets flagged by OptionalUnit:
Right now though that use of Unit isn't reported.
Context
This could instead be written as:
The use of Unit in the first example is therefore optional and should be reported. This means reverting the logic introduced in #1176.
The text was updated successfully, but these errors were encountered: