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 main #5292

Merged
merged 2 commits into from Sep 10, 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 @@ -822,7 +822,7 @@ class IgnoredReturnValueSpec(private val env: KotlinCoreEnvironment) {
flowOfChecked("hello")
return 42
}
"""
""".trimIndent()
val findings = subject.compileAndLintWithContext(env, code)
assertThat(findings)
.singleElement()
Expand Down Expand Up @@ -913,7 +913,7 @@ class IgnoredReturnValueSpec(private val env: KotlinCoreEnvironment) {
fun foo() {
flowOf(1, 2, 3)
}
"""
""".trimIndent()
val findings = subject.compileAndLintWithContext(env, code)

assertThat(findings)
Expand All @@ -931,7 +931,7 @@ class IgnoredReturnValueSpec(private val env: KotlinCoreEnvironment) {
flowOf(1, 2, 3)
.onEach { println(it) }
}
"""
""".trimIndent()
val findings = subject.compileAndLintWithContext(env, code)

assertThat(findings)
Expand All @@ -946,7 +946,7 @@ class IgnoredReturnValueSpec(private val env: KotlinCoreEnvironment) {
import kotlinx.coroutines.flow.flowOf

fun foo() = flowOf(1, 2, 3)
"""
""".trimIndent()
val findings = subject.compileAndLintWithContext(env, code)
assertThat(findings).isEmpty()
}
Expand All @@ -961,7 +961,7 @@ class IgnoredReturnValueSpec(private val env: KotlinCoreEnvironment) {
.onEach { println(it) }
.collect()
}
"""
""".trimIndent()
val findings = subject.compileAndLintWithContext(env, code)
assertThat(findings).isEmpty()
}
Expand Down
Expand Up @@ -38,6 +38,8 @@ class TopLevelPropertyNaming(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) {
super.visitProperty(property)
if (!property.isTopLevel) return
if (property.isConstant()) {
handleConstant(property)
} else {
Expand Down
Expand Up @@ -12,18 +12,12 @@ class TopLevelPropertyNamingSpec {
val subject = TopLevelPropertyNaming()

@Test
fun `should use custom name top level propeties`() {
assertThat(
TopLevelPropertyNaming(TestConfig(mapOf(TopLevelPropertyNaming.CONSTANT_PATTERN to "^lowerCaseConst$"))).compileAndLint(
"""
class Foo{
companion object {
const val lowerCaseConst = ""
}
}
""".trimIndent()
)
).isEmpty()
fun `should use custom name top level properties`() {
val code = """
const val lowerCaseConst = ""
""".trimIndent()
val subject = TopLevelPropertyNaming(TestConfig(TopLevelPropertyNaming.CONSTANT_PATTERN to "^lowerCaseConst$"))
assertThat(subject.lint(code)).isEmpty()
}

@Nested
Expand Down Expand Up @@ -87,4 +81,19 @@ class TopLevelPropertyNamingSpec {
io.gitlab.arturbosch.detekt.test.assertThat(subject.lint(code)).hasSize(1)
}
}

@Test
fun `should not care about no top level properties`() {
val code = """
class Foo{
val __baz = ""
companion object {
const val __bar = ""
val __foo = ""
}
}
""".trimIndent()

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