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

BooleanPropertyNaming highlight only the name of the variable #5431

Merged
merged 2 commits into from Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -79,7 +79,7 @@ class BooleanPropertyNaming(config: Config = Config.empty) : Rule(config) {
val description = "Boolean property name should match a $allowedPattern pattern."
return CodeSmell(
TWiStErRob marked this conversation as resolved.
Show resolved Hide resolved
issue,
Entity.from(declaration),
Entity.from(declaration.nameIdentifier ?: declaration),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be statically checked in the new ruleset as a best practice? e.g. if the "thing" passed into Entity.from has a "name" (e.g. inherits from PsiNameIdentifierOwner), then report("use '.nameIdentifier' instead")?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this could apply to all the cases. But that seems like a doable rule so anyone can implement it and check if my statment is true.

TWiStErRob marked this conversation as resolved.
Show resolved Hide resolved
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"))
BraisGabin marked this conversation as resolved.
Show resolved Hide resolved
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