Skip to content

Commit

Permalink
fix: TopLevelPropertyNaming also detecting extension property (#7212)
Browse files Browse the repository at this point in the history
  • Loading branch information
psuzn committed May 1, 2024
1 parent 36d0f27 commit acc8e74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -10,6 +10,7 @@ import io.gitlab.arturbosch.detekt.api.config
import io.gitlab.arturbosch.detekt.rules.identifierName
import io.gitlab.arturbosch.detekt.rules.isConstant
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration
import org.jetbrains.kotlin.psi.psiUtil.isPrivate

/**
Expand All @@ -32,7 +33,8 @@ class TopLevelPropertyNaming(config: Config) : Rule(

override fun visitProperty(property: KtProperty) {
super.visitProperty(property)
if (!property.isTopLevel) return
if (!property.isTopLevel || property.psiOrParent.isExtensionDeclaration()) return

if (property.isConstant()) {
handleConstant(property)
} else {
Expand Down
Expand Up @@ -46,6 +46,15 @@ class TopLevelPropertyNamingSpec {
}
}

@Test
fun `should not report on top level extension properties`() {
val code = """
val String._foo = "foo"
""".trimIndent()

assertThat(subject.lint(code)).isEmpty()
}

@Nested
inner class `variables on top level` {

Expand Down

0 comments on commit acc8e74

Please sign in to comment.