Skip to content

Commit

Permalink
ObjectPropertyNaming: fix false positive with top level properties (#…
Browse files Browse the repository at this point in the history
…5390)

Closes #5340
  • Loading branch information
DJtheRedstoner committed Oct 8, 2022
1 parent b6ad99d commit cdb5928
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit cdb5928

Please sign in to comment.