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

UnusedPrivateMember: highlight declaration name #4928

Merged
merged 1 commit into from Jun 7, 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 @@ -153,7 +153,7 @@ private class UnusedFunctionVisitor(
else -> emptyList()
}
unusedFunctions.map {
CodeSmell(issue, Entity.from(it), "Private function `$functionName` is unused.")
CodeSmell(issue, Entity.atName(it), "Private function `$functionName` is unused.")
}
}
}
Expand Down Expand Up @@ -212,7 +212,7 @@ private class UnusedParameterVisitor(allowedNames: Regex) : UnusedMemberVisitor(

override fun getUnusedReports(issue: Issue): List<CodeSmell> {
return unusedParameters.map {
CodeSmell(issue, Entity.from(it), "Function parameter `${it.nameAsSafeName.identifier}` is unused.")
CodeSmell(issue, Entity.atName(it), "Function parameter `${it.nameAsSafeName.identifier}` is unused.")
}
}

Expand Down Expand Up @@ -284,7 +284,7 @@ private class UnusedPropertyVisitor(allowedNames: Regex) : UnusedMemberVisitor(a
.map {
CodeSmell(
issue,
Entity.from(it),
Entity.atName(it),
"Private property `${it.nameAsSafeName.identifier}` is unused."
)
}
Expand Down
Expand Up @@ -1321,7 +1321,7 @@ class UnusedPrivateMemberSpec(val env: KotlinCoreEnvironment) {
"""
val findings = subject.compileAndLintWithContext(env, code)
assertThat(findings).hasSize(1).hasSourceLocations(
SourceLocation(3, 5)
SourceLocation(3, 30)
)
}
}
Expand Down Expand Up @@ -1593,4 +1593,48 @@ class UnusedPrivateMemberSpec(val env: KotlinCoreEnvironment) {
assertThat(subject.lintWithContext(env, code)).hasSize(0)
}
}

@Nested
inner class `highlights declaration name` {
@Test
fun function() {
val code = """
class Test {
/**
* kdoc
*/
private fun foo() = 1
}
"""
assertThat(subject.lint(code)).hasSize(1).hasSourceLocation(5, 17)
}

@Test
fun property() {
val code = """
class Test {
/**
* kdoc
*/
private val foo = 1
}
"""
assertThat(subject.lint(code)).hasSize(1).hasSourceLocation(5, 17)
}

@Test
fun parameter() {
val code = """
class Test {
fun test(
/**
* kdoc
*/
x: Int
) = 1
}
"""
assertThat(subject.lint(code)).hasSize(1).hasSourceLocation(6, 9)
}
}
}