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

ObjectPropertyNaming: fix false positive with top level properties #5390

Merged
merged 1 commit into from Oct 8, 2022
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 @@ -38,7 +38,7 @@ class ObjectPropertyNaming(config: Config = Config.empty) : Rule(config) {
private val privatePropertyPattern: Regex by config("(_)?[A-Za-z][_A-Za-z0-9]*") { it.toRegex() }

override fun visitProperty(property: KtProperty) {
if (property.isLocal) {
if (property.isLocal || property.isTopLevel) {
return
}

Expand Down
Expand Up @@ -237,6 +237,20 @@ class ObjectPropertyNamingSpec {
assertThat(subject.compileAndLint(code)).isEmpty()
}
}

@Nested
inner class `top level properties` {
@Test
fun `should not detect top level properties`() {
val subject = ObjectPropertyNaming()

val code = """
val _invalidNaming = 1
""".trimIndent()

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

@Suppress("UnnecessaryAbstractClass")
Expand Down