https://kotlinlang.org logo
#ktlint
Title
# ktlint
v

Vince

10/19/2021, 11:39 PM
Hi! I'm noticing different behavior around the
import-ordering
rule between ktlint and ktlint-gradle (gradle wrapper). Specifically around the ordering of java/javax/kotlin and aliases: ktlint 0.42.1
Copy code
Imports must be ordered in lexicographic order without any empty lines in-between with "java", "javax", "kotlin" and aliases in the end
JLLeitschuh/ktlint-gradle wrapper 10.2.0 using ktlint 0.42.1
Copy code
Imports must be ordered in lexicographic order without any empty lines in-between (import-ordering)
Any idea what could be causing this discrepancy? The gradle wrapper `ktlintCheck`/`ktlintFormat` tasks aren't respecting the latter part of the rule around java/javax/kotlin + alias imports going at the end. Seems to have been added into ktlint around 0.42 based on some closed issues in the repo.
s

Sha Sha Chu

10/20/2021, 12:16 AM
i’m not 100% sure how the ktlint-gradle-wrapper plugin passes through those properties
v

Vince

10/20/2021, 12:30 AM
hmm, I actually don't have my own custom
.editorconfig
file, so I assume it would just use a default one provided from ktlint?
r

romtsn

10/20/2021, 1:57 PM
@Vince are you setting
android = true
in the ktlint-gradle configuration? if so, then this is default behavior - android codestyle requires just alphabetical ordering
v

Vince

10/20/2021, 4:58 PM
ah, indeed that was the cause (I've configured it to
android = true
). Thanks Roman! and shasha as well 🙂
👍 1
1448 Views