Kotlinter 3.7.0 removes needed star imports
henrik242 opened this issue · comments
Kotlinter removes the star import here, which makes our builds fail:
import com.example.processor.*
import com.example.processor.LocationType.CITY
import com.example.processor.LocationType.COUNTRY
Here's LocationType
:
enum class LocationType {
CITY,
COUNTRY;
}
I refer to CITY
, COUNTRY
and LocationType
in the calling code.
Thanks for the report @henrik242. I assume this is a new issue in kotlinter 3.7.0?
It might be a manifestation of this bug that's new with ktlint 0.43.0 which was incorporated in the latest release:
pinterest/ktlint#1277
I would assume if lint erroneously made it an error, format would remove the import.
Are you using disabled_rules=no-wildcard-imports
?
If it's in fact the same issue, I'm watching ktlint for a patch release and will incorporate.
If it appears to you to be a different issue, I think you'll want to file it, because it would be an issue in ktlint.
I assume this is a new issue in kotlinter 3.7.0?
Correct!
Are you using disabled_rules=no-wildcard-imports?
Yup:
kotlinter {
disabledRules = arrayOf("no-wildcard-imports", "import-ordering")
}
If it's in fact the same issue, I'm watching ktlint for a patch release and will incorporate.
I guess it's the same.
Ok, thanks. Just in case, also try moving that configuration to .editorconfig and see if the result is the same. I don't think there's a bug picking up the config in either place, but might as well eliminate that.
I tried adding disabled_rules=no-wildcard-imports
to .editorconfig
, but kotlinter doesn't seem to pick it up. Is it named differently?
Never mind, I still had disabledRules = arrayOf("import-ordering")
in place, which overwrote any disabled_rules
in .editorconfig
. After removing disabledRules from the kotlinter config the .editorconfig worked, and still had the bug described here.
Hey, how is the state here? We experience this issue after upgrading from 3.4.5 to 3.8.0. Greetings 😄
@paulschuetz The latest working version is still 3.6.0 😕
Yea just tried it out and downgraded to 3.6.0 😄 Thanks for your quick reply and confirmation. And thanks to @jeremymailen for the great library!
Thanks appreciate it! And sorry, yeah the issue still exists upstream and the efforts to fix it seem to be a little stuck.
In the projects I work on we do use the newest kotlinter, but have just avoided using * imports for these specific cases -- we are able to use * imports in most situations.
I'm running with 3.9.0
and no-wildcard-imports
seems to work for most files. But I have a single file where it is removing the wildcard and I cannot understand why. Here's an example of the output. Is there some kind of additional debugging I can enable to see why it's doing this?
/intellij/toolwindow/FlagNodeDefaults.kt:7:1: Format could not fix > [no-wildcard-imports] Wildcard import
/intellij/FlagStore.kt: Format fixed
The diff for the FlagStore file is:
-import com.launchdarkly.intellij.featurestore.*
You might need to dig into the ktlint level debugging. Do you get the same result running the ktlint
command line on it? If so you might up the debug level there and see if it gives you more insight on why.
This is now fixed in ktlint 0.45.0! pinterest/ktlint#1402
This is now fixed in ktlint 0.45.0! pinterest/ktlint#1402
Or will once there's been a release :)
@jeremymailen 0.45.1 is out! 🥳
Yup, there's some design discussions about how to incorporate the new release since it changes the api to ktlint. Hopefully have an update soon.
@jeremymailen Cool, looking forward to that : )
Fixed via 3.10.0 release