- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 794
UnnecessaryAbstractClass: fix false positive when the abstract class has properties in the primary constructor #4628
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
Conversation
…has properties in the primary constructor
Codecov Report
@@ Coverage Diff @@
## main #4628 +/- ##
===========================================
+ Coverage 0 84.52% +84.52%
- Complexity 0 3358 +3358
===========================================
Files 0 481 +481
Lines 0 11193 +11193
Branches 0 2042 +2042
===========================================
+ Hits 0 9461 +9461
- Misses 0 698 +698
- Partials 0 1034 +1034
Continue to review full report at Codecov.
|
val (abstractMembers, concreteMembers) = members.partition { it.isAbstract() } | ||
if (abstractMembers.isEmpty() && !hasInheritedMember(true)) { | ||
report(CodeSmell(issue, Entity.from(this), noAbstractMember)) | ||
return | ||
} | ||
if (abstractMembers.any { it.isInternal() || it.isProtected() } || hasConstructorParameter()) { | ||
return | ||
} | ||
if (concreteMembers.isEmpty() && !hasInheritedMember(false)) { | ||
report(CodeSmell(issue, Entity.from(this), noConcreteMember)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: The previous detectAbstractAndConcreteType()
seems cleaner to me.
private fun KtClass.members() = body?.children?.filterIsInstance<KtCallableDeclaration>().orEmpty() + | ||
primaryConstructor?.valueParameters?.filter { it.hasValOrVar() }.orEmpty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future readers: This line of change is the fix.
Fixes #4626