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

False positive for unused imports #4815 #4818

Merged
merged 2 commits into from May 9, 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 @@ -113,15 +113,16 @@ class UnusedImports(config: Config) : Rule(config) {
}

override fun visitDeclaration(dcl: KtDeclaration) {
val kdoc = dcl.docComment?.getDefaultSection()
val kdoc = dcl.docComment?.getAllSections()

kdoc?.getChildrenOfType<KDocTag>()
?.map { it.text }
?.forEach { handleKDoc(it) }
kdoc?.forEach { kdocSection ->
kdocSection.getChildrenOfType<KDocTag>()
.map { it.text }
.forEach { handleKDoc(it) }

kdoc?.getContent()?.let {
handleKDoc(it)
handleKDoc(kdocSection.getContent())
}

super.visitDeclaration(dcl)
}

Expand Down
Expand Up @@ -609,4 +609,29 @@ class UnusedImportsSpec(val env: KotlinCoreEnvironment) {
"""
assertThat(subject.lintWithContext(env, mainFile, additionalFile)).isEmpty()
}

@Test
fun `does not report unused import for import used in kdoc - #4815`() {
val mainFile = """
import x.y.z.SomeClass

class MyView

/**
* Style for [MyView]
* Blablabla
*
* @property someVal Someval for [SomeClass]
*/
data class StyleClass(val someVal: String)
"""

val additionalFile = """
package x.y.z

class SomeClass
"""

assertThat(subject.lintWithContext(env, mainFile, additionalFile)).isEmpty()
}
}