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

fix: TopLevelPropertyNaming also detecting extension property name #7212

Merged
merged 1 commit into from May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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