mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
UnusedPrivateMember: highlight declaration name (#4928)
This commit is contained in:
committed by
GitHub
parent
9146e4d1f6
commit
0ecebd4f61
@@ -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.")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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."
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user