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

Kotlinter 3.7.0 removes needed star imports #227

Closed
henrik242 opened this issue Nov 11, 2021 · 17 comments
Closed

Kotlinter 3.7.0 removes needed star imports #227

henrik242 opened this issue Nov 11, 2021 · 17 comments

Comments

@henrik242
Copy link

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.

@jeremymailen
Copy link
Owner

jeremymailen commented Nov 13, 2021

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.

@henrik242
Copy link
Author

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.

@jeremymailen
Copy link
Owner

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.

@henrik242
Copy link
Author

henrik242 commented Nov 15, 2021

I tried adding disabled_rules=no-wildcard-imports to .editorconfig, but kotlinter doesn't seem to pick it up. Is it named differently?

@henrik242
Copy link
Author

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.

@paulschuetz
Copy link

Hey, how is the state here? We experience this issue after upgrading from 3.4.5 to 3.8.0. Greetings 😄

@henrik242
Copy link
Author

@paulschuetz The latest working version is still 3.6.0 😕

@paulschuetz
Copy link

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!

@jeremymailen
Copy link
Owner

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.

@InTheCloudDan
Copy link

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.*

@jeremymailen
Copy link
Owner

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.

@henrik242
Copy link
Author

This is now fixed in ktlint 0.45.0! pinterest/ktlint#1402

@jeremymailen
Copy link
Owner

This is now fixed in ktlint 0.45.0! pinterest/ktlint#1402

Or will once there's been a release :)

@henrik242
Copy link
Author

@jeremymailen 0.45.1 is out! 🥳

@jeremymailen
Copy link
Owner

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.

@henrik242
Copy link
Author

@jeremymailen Cool, looking forward to that : )

@jeremymailen
Copy link
Owner

Fixed via 3.10.0 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants