pinterest / ktlint

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

Maintain consistent order of imports #189

Closed gabrielittner closed 5 years ago

gabrielittner commented 6 years ago

Currently imports aren't sorted at all and single empty lines within the imports aren't removed.

See https://android.github.io/kotlin-guides/style.html#import-statements

shyiko commented 6 years ago

ktlint has ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/ImportOrderingRule.kt (test) but it's disabled as it's incompatible with the way AS orders imports (not with the actual Android Koltin Style Guide, though). At least that was the case when I wrote the rule.

gabrielittner commented 6 years ago

Is there a way to manually enable the rule?

shyiko commented 6 years ago

Other than copy&pasting ImportOrderingRule to your own ruleset, not at the moment (unfortunately).

gabrielittner commented 5 years ago

@shyiko Can you describe the incompatibility you mentioned?

iikirilov commented 5 years ago

This may be offtopic but I do not find a way to specify an import order :( - I can live without alphabetical order until there is some proposal how to fix it.

Tapchicoma commented 5 years ago

@shyiko would it make sense to include disabled ImportOrderingRule into --experimental flag rules? So those who need it can use it.

shashachu commented 5 years ago

@Tapchicoma That seems totally reasonable.