Skip to content
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

Added factory function check to MemberNameEqualsClassName #653

Merged
merged 4 commits into from Jan 1, 2018
Merged

Added factory function check to MemberNameEqualsClassName #653

merged 4 commits into from Jan 1, 2018

Conversation

schalkms
Copy link
Member

@schalkms schalkms commented Dec 30, 2017

Implements the feature mentioned in #652


private fun isFactoryMethod(function: KtNamedFunction, klass: KtClass): Boolean {
val typeReference = function.typeReference
return typeReference == null && function.bodyExpression !is KtBlockExpression
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ignores functions which return a single expression since detekt cannot infer the type (at the moment).
Consider the following code for example

open class A {
  companion object {
    // return type = A
    fun a(condition: Boolean) = if (condition) B() else C()
  }
}

class B: A()
class C: A()

}
private fun getMisnamedCompanionObjectMembers(klass: KtClass): List<KtNamedDeclaration> {
val list = mutableListOf<KtNamedDeclaration>()
klass.companionObjects.forEach { list.addAll(getMisnamedMembers(it, klass.name)) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be just a flatMap-Funktion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@arturbosch arturbosch merged commit 462a1eb into detekt:master Jan 1, 2018
@arturbosch arturbosch added this to the RC6-1 milestone Jan 1, 2018
@schalkms schalkms deleted the MemberNameEqualsClassName-factory branch January 2, 2018 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants