detekt / detekt

Static code analysis for Kotlin
https://detekt.dev
Apache License 2.0
6.07k stars 751 forks source link

False-positve `UnusedImports` when there are mutiple functions of the same name #7224

Open sschuberth opened 3 weeks ago

sschuberth commented 3 weeks ago

Expected Behavior

Detekt should not report UnusedImports for imports that are actually required.

Observed Behavior

Detekt flags an import that is required as UnusedImports.

Steps to Reproduce

In this code

import org.eclipse.apoapsis.ortserver.dao.createDataSource

private fun Application.createDataSource(): DataSource {
    val configManager: ConfigManager by inject()

    val dataSourceConfig = DatabaseConfig.create(configManager)

    return createDataSource(dataSourceConfig)
}

there is both the imported createDataSource (non-extension) function, and a function of the same name in the same file. Needless to say that createDataSource(dataSourceConfig) cannot call Application.createDataSource() as the former has an argument provided, but the latter takes none. So it's clear that only org.eclipse.apoapsis.ortserver.dao.createDataSource can be meant, and has to be imported.

Context

I'm trying to resolve all Detekt hints in my code base, using type resolution.

Your Environment