pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.26k stars 506 forks source link

Extension imports from 3rd party library detected as "Unused import" #531

Closed tinder-mhernandez closed 5 years ago

tinder-mhernandez commented 5 years ago

I have an Android library module that depends on the toSpannable() extension from Android core-ktx and version 0.34.0 of ktlint is detecting import androidx.core.text.toSpannable as an unused import. When I run the formatter, it removes the import which then cause the code to fail compilation.

Sample Repro:

package com.foo

import android.text.Spannable
import androidx.core.text.toSpannable // <-- Considered as unused

fun foo(text: String): Spannable {
    return text.toSpannable()
}
tinder-mhernandez commented 5 years ago

No repro on 0.33.0 Only seems to repro on 0.34.0.

shashachu commented 5 years ago

Thanks, Marcelo. This is the second regression reported on this rule in 0.34.0 so I'll take a look but if it's not obvious what's going on, I'll go ahead and revert the changes we made in this release. Sorry for the inconvenience!