Skip to content

Commit

Permalink
Removed UnnecessaryAbstractClass if it inherits from an interface or …
Browse files Browse the repository at this point in the history
…abstract class that has concrete members

Removed deprecated annotations

Revert "Removed deprecated annotations"

This reverts commit 326a356

fix return count rule violation
  • Loading branch information
gouri-panda committed Jun 29, 2022
1 parent 2f75d2c commit 8445bee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Expand Up @@ -79,7 +79,7 @@ class UnnecessaryAbstractClass(config: Config = Config.empty) : Rule(config) {
super.visitClass(klass)
}

@Suppress("ComplexMethod")
@Suppress("ComplexMethod", "ReturnCount")
private fun KtClass.check() {
val nameIdentifier = this.nameIdentifier ?: return
if (annotationExcluder.shouldExclude(annotationEntries) || isInterface() || !isAbstract()) return
Expand All @@ -98,6 +98,7 @@ class UnnecessaryAbstractClass(config: Config = Config.empty) : Rule(config) {
report(CodeSmell(issue, Entity.from(nameIdentifier), noConcreteMember))
}
}
hasInheritedMember(true) -> return
!hasConstructorParameter() ->
report(CodeSmell(issue, Entity.from(nameIdentifier), noConcreteMember))
else ->
Expand Down
Expand Up @@ -73,8 +73,7 @@ class UnnecessaryAbstractClassSpec(val env: KotlinCoreEnvironment) {
}
abstract class B : A
"""
val findings = subject.compileAndLintWithContext(env, code)
assertFindingMessage(findings, message)
assertThat(subject.compileAndLintWithContext(env, code)).isEmpty()
}

@Test
Expand All @@ -86,6 +85,16 @@ class UnnecessaryAbstractClassSpec(val env: KotlinCoreEnvironment) {
}
abstract class B : A()
"""
assertThat(subject.compileAndLintWithContext(env, code)).isEmpty()
}

@Test
fun `that inherits from another empty abstract class`() {
val code = """
@Deprecated("We don't care about this first class")
abstract class A
abstract class B : A()
"""
val findings = subject.compileAndLintWithContext(env, code)
assertFindingMessage(findings, message)
}
Expand Down

0 comments on commit 8445bee

Please sign in to comment.