diff --git a/detekt-rules-naming/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/naming/BooleanPropertyNaming.kt b/detekt-rules-naming/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/naming/BooleanPropertyNaming.kt index 061b187fb35f..83bacb158ac2 100644 --- a/detekt-rules-naming/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/naming/BooleanPropertyNaming.kt +++ b/detekt-rules-naming/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/naming/BooleanPropertyNaming.kt @@ -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" ) } diff --git a/detekt-rules-naming/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/naming/BooleanPropertyNamingSpec.kt b/detekt-rules-naming/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/naming/BooleanPropertyNamingSpec.kt index feefd0690d56..cba37b0c67db 100644 --- a/detekt-rules-naming/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/naming/BooleanPropertyNamingSpec.kt +++ b/detekt-rules-naming/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/naming/BooleanPropertyNamingSpec.kt @@ -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(197 to 210) + } } @Nested @@ -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(193 to 206) + } } }