Repository: detekt/detekt (kotlin)

Issue:
UnusedPrivateMember highlights KDoc, instead of member name.
## Steps to Reproduce
```kotlin
/**
 * Don't look here.
 */
private fun mockActivityManager(): IActivityManager =
    TODO()
```

## Expected Behavior
Highlight focuses on `mockActivityManager`.

## Observed Behavior
Highlight focuses on `/**`.



## Context
Just forgot to call a function and got this:
![image](https://user-images.githubusercontent.com/2906988/172020023-2b0ba2e8-879c-4791-afa4-078a0d75247a.png)
had to open the file to see what I messed up.
I would imagine this also affects how baselines are treating the fun.

## Your Environment
<!-- Include as many relevant details about the environment you experienced the bug in -->
* Version of detekt used: 1.20.0
* Version of Gradle used (if applicable): 7.4.2
* Gradle scan link (add `--scan` option when running the gradle task): N/A
* Operating System and version: Unix
* Link to your project (if it's a public repository): https://github.com/TWiStErRob/net.twisterrob.sun/security/code-scanning/24

Pull request:
Fixes #4916

Patch:
diff --git a/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivateMember.kt b/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivateMember.kt
index 592499c2e768..9180de718ad6 100644
--- a/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivateMember.kt
+++ b/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivateMember.kt
@@ -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."
                 )
             }


Test patch:
diff --git a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivateMemberSpec.kt b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivateMemberSpec.kt
index c538acf537bf..e8b7078e96a7 100644
--- a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivateMemberSpec.kt
+++ b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UnusedPrivateMemberSpec.kt
@@ -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)
+        }
+    }
 }