pinterest / ktlint

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

Java or Javax Imports doesn't fall under lexicographic order #650

Closed kasingal closed 4 years ago

kasingal commented 4 years ago

https://github.com/pinterest/ktlint/blob/bc08930a1f0848e7ee774b24512ba6ae4e25e9be/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/ImportOrderingRule.kt#L36

Using Intellij with Google Kotlin Style Guide (https://github.com/pinterest/ktlint#-with-intellij-idea)

When running Reformat Code (*.kt) by default java. or javax. related import statements comes in last after other import statements and ImportOrderingRule always fails to validate same.

ImportOrderingRule should skip lexicographic order on import statements starting from java or javax

JakeWharton commented 4 years ago

Google Kotlin Style Guide

To be clear, Google's Kotlin style guide does not make any exceptions for java or javax. They are subject to regular ordering like any other package.

kasingal commented 4 years ago

@JakeWharton I agree, but IntelliJ (with default Kotlin Style Guide) is not formatting code in same way as ktlint is formatting.

As Intellij auto add required import statements and doesn't keep java or javax related imports in lexicographic order, which makes process tedeous to always run ktlint format on codebase.

Either there should be some .editorConfig which alligns with all ktlint rules, same can be imported to IntelliJ so that it doesn't handle java or javax imports in different way.

Tapchicoma commented 4 years ago

Closing as duplicate of #527