UnnecessaryAbstractClass: fix false positive when the abstract class has properties in the primary constructor#4628
Merged
picklebento merged 2 commits intodetekt:mainfrom Mar 12, 2022
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.
|
BraisGabin
approved these changes
Mar 12, 2022
cortinico
approved these changes
Mar 12, 2022
picklebento
approved these changes
Mar 12, 2022
Comment on lines
+87
to
+97
| 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)) | ||
| } |
Member
There was a problem hiding this comment.
Nit: The previous detectAbstractAndConcreteType() seems cleaner to me.
Comment on lines
+106
to
+107
| private fun KtClass.members() = body?.children?.filterIsInstance<KtCallableDeclaration>().orEmpty() + | ||
| primaryConstructor?.valueParameters?.filter { it.hasValOrVar() }.orEmpty() |
Member
There was a problem hiding this comment.
For future readers: This line of change is the fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4626