Hello everyone! Are any of you having trouble with...
# ktlint
s
Hello everyone! Are any of you having trouble with one of the latest rules introduced? The alphabetical imports one. It can only be fixed by doing
ktlintFormat
and that takes too much time compared to just formatting. I tried updating idea codestyle through ktlint again but it doesn't seem to be included.
s
I'm not sure what you mean by ktlintFormat vs just formatting
Do you mean formatting in IntelliJ?
I'm not at my computer right now, but there's a bug/issue in IntelliJ at the moment where you can't specify import layout for Kotlin files the way you can for Java files
There's not a great workaround atm but if you like you can disable the import ordering rule entirely (see the README for details)
At Pinterest we basically run ktlint -F as a pre-commit hook
i
you can disable it for now by creating
.editorconfig
file in the project root directory containing
disabled_rules = import-ordering
👍 2
BTW The issue is that ktlint import-ordering rule follows a bit different import order than AS build-in import ordering
s
thanks shasha and @igor.wojda 🙂 I was asking to see if there is a third approach (rather than disabling or adding it as pre-commit hook) Will ask my team and decide what to do next
t
Introduction of alphabetical import ordering was due to the fact, that, with versions, IDE default settings for it changed several times. When developer touched some old code and has enabled feature of autoformatting imports - PRs was cluttered with imports reshuffling lines that brings additional unnecessary noise. I would say solution for now would be adding pre-commit hook that autoformats all git commit code. And vote for the related issue in kotlin issue tracker.