pinterest / ktlint

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

Allow configuring ktlint to allow star imports #606

Closed ScottPierce closed 4 years ago

ScottPierce commented 4 years ago

I realize this is an odd request given the Android Style Guidelines explicit disaproval of no wildcard imports, but I've recently encountered an issue with the kotlinx.coroutines library where the API wasn't working as intended because I didn't have star imports enabled for kotlinx.coroutines (i.e. the Flow#consume call requires wildcard imports to work, and doesn't suggest an auto import if you don't have it enabled). When I brought this up in slack, Roman Elizarov, the Kotlin library team lead, had this to say:

Kotlin, the language, and its libraries are designed with start imports in mind. If standard library weren’t imported by default, you’d have the same issue with it. Any Kotlin DSL would look ugly without star import. However, indeed, when you work with Android, which is mostly Java, you should prefer Java-style single-class import, since in Java a class is usually a single unit of an API. In Kotlin a single unit of API is usually a package. I can only think of solution that would somehow distinguish Kotlin/Java packages or classes and make imports individual or star depending on that.

It seems there isn't going to be a consensus from the Android style perspective, but given that certain official jetbrains APIs are designed with the expectation of star imports, it seems reasonable to allow opting into something to disable the ktlint requirement of no star imports in the .editorconfig.

ScottPierce commented 4 years ago

I just found something new in the documentation:

disabled_rules=no-wildcard-imports,experimental:annotation,my-custom-ruleset:my-custom-rule

Seems like this is already implemented.

Thanks!

stewart-newscorp commented 2 months ago

Now after version 0.49.0 of ktlint it might be: ktlint_standard_no-wildcard-imports = disabled https://stackoverflow.com/questions/61124868/ktlint-doesnt-allow-wildcard-import-using-intellij-auto-import-feature