Skip to content

Commit

Permalink
BooleanPropertyNaming highlight only the name of the variable
Browse files Browse the repository at this point in the history
  • Loading branch information
TWiStErRob committed Oct 17, 2022
1 parent 37ce264 commit e0514d9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Expand Up @@ -79,7 +79,7 @@ class BooleanPropertyNaming(config: Config = Config.empty) : Rule(config) {
val description = "Boolean property name should match a $allowedPattern pattern."
return CodeSmell(
issue,
Entity.from(declaration),
Entity.from(declaration.nameIdentifier ?: declaration),
message = "$description Actual name is $name"
)
}
Expand Down
Expand Up @@ -254,6 +254,24 @@ class BooleanPropertyNamingSpec(val env: KotlinCoreEnvironment) {

assertThat(findings).isEmpty()
}

@Test
fun `should highlight only the name`() {
val code = """
data class Test(
/**
* True if the user's e-mail address has been verified; otherwise false.
*/
@Deprecated("Don't use this", replaceWith = ReplaceWith("email_verified"))
val emailVerified: Boolean?,
)
""".trimIndent()
val findings = subject.compileAndLintWithContext(env, code)

assertThat(findings)
.hasSize(1)
.hasTextLocations("emailVerified")
}
}

@Nested
Expand Down Expand Up @@ -617,6 +635,24 @@ class BooleanPropertyNamingSpec(val env: KotlinCoreEnvironment) {
assertThat(BooleanPropertyNaming(config).compileAndLint(code))
.isEmpty()
}

@Test
fun `should highlight only the name`() {
val code = """
class Test {
/**
* True if the user's e-mail address has been verified; otherwise false.
*/
@Deprecated("Don't use this", replaceWith = ReplaceWith("email_verified"))
var emailVerified: Boolean? = false
}
""".trimIndent()
val findings = subject.compileAndLintWithContext(env, code)

assertThat(findings)
.hasSize(1)
.hasTextLocations("emailVerified")
}
}
}

Expand Down

0 comments on commit e0514d9

Please sign in to comment.