-
Notifications
You must be signed in to change notification settings - Fork 503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alphabetical import ordering enabled by default is a problem in Android Studio/IntelliJ #527
Comments
@dimsuz as of 0.34.0 you can disable rules via the So in this case it would be |
Thanks for the hint, will do that! Just wanted to report this in case having it as a default is up for review. |
Thanks for the report! Of course anything and everything is up for discussion; I will close this ticket for now but I will keep an eye out for feedback if this rule proves controversial. |
You also can follow this issue from Kotlin side: https://youtrack.jetbrains.com/issue/KT-10974 |
Thanks, voted! |
Adding a property to |
Hi Jan, Just to get more information, can you give an example of where the IntelliJ optimized imports ends up not in Alphabetical order? I understand it's frustrating to have ktlint disagree with IDEA, it's not clear to me whether the IDEA ordering is a bug or desired behavior. Thanks! |
fyi: IDEA puts |
Yep, I have provided an example of invalid order in the original post, that is where it did go wrong for us. |
Thanks. I just added a comment onto https://youtrack.jetbrains.com/issue/KT-10974 to ask if putting all the |
It does invalidate the claim on the ktlint README that...
If this is 'expected behavior', calling the cli suggested |
Sure. I understand your frustration, I just want to make sure the IDEA Optimize Imports ordering is not going to change before mimicing the same behavior in ktlint. |
Just want to add that if the rule is changed it shouldn't be changed for
|
For what it is worth, the Google Java style guide used to have the
Which the Google Checkstyle stylesheet also uses. I don't see import order mentioned on https://kotlinlang.org/docs/reference/coding-conventions.html |
And Google's Kotlin style guide (not yet public) also matches Java and the Android Kotlin guide in that regard. |
One thing we're also considering is breaking the android-specific rules into a different ruleset rather than using a flag. |
That bug was open in 2016 it looks like, not sure it is going to be resolved quickly. This issue caused quite a bit of headache for us today. Is there any reason not to keep inline with Intellij until if/when it changes? |
Our whole backend team has this problem, so it would really be great if we could turn off this inspection by ktlint by some configuration option (at the very least) :) |
@VaclavDedik check this comment to the way how to disable it: #527 (comment) |
We definitely have this issue too. How painful would it be to add a configuration option for ktlint to handle this case? Even if we have to remove it later once IntelliJ sorts this out. |
@greenkiwi There's a way to disable this check, see the first comment above. |
@dimsuz - We've disabled the check. It would be great to have the option to have it match the IntelliJ order. i.e. still check, just with java/javax at the end. |
Any further changes on this? Seems like the kotlin.* imports are being put at the bottom as well. |
The following code block will cause ktlint to report incorrect order
This seems to be the default IJ import ordering for koltin and it mismatches ktlint. |
* feat(repository): apply repository modularization with dagger2 * feat(app): use repository module with coroutine * fix(ktlint): ignore import ordering pinterest/ktlint#527 * docs: modify readme * feat(ui): add username, password * fix: repository test, jdk11(x64), gradle jvm heap size up
* Update `gradle` to `6.5` * Update `klint` version and add `klint-idea` plugin to generate IDEA specific tasks * Disable `import-ordering` klint check (see [PR](pinterest/ktlint#527) for details.
* Update `gradle` to `6.5` * Update `klint` version and add `klint-idea` plugin to generate IDEA specific tasks * Disable `import-ordering` klint check (see [PR](pinterest/ktlint#527) for details. Fixes #1155
* Upgrade gradle ktlint plugin * The old version has a [bug](pinterest/ktlint#527) where it cannot properly sync formatting rules with intellij * Auto-format code accordingly by running `./scripts/lint.sh` Co-authored-by: Peter Chen <pchen@pivotal.io>
Mostly to fix pinterest/ktlint#527
For those watching at home, this is also fixed on the IDEA side in Kotlin plugin 1.4 - JetBrains/kotlin#3336 |
Lists ktlint problem: pinterest/ktlint#527 ktlint import ordering ignored, using Android Studio default settings
Massive changes ktlint problem: pinterest/ktlint#527 ktlint import ordering ignored, using Android Studio default settings
I guess this is related, but if it's not, I can create a new issue for it. When using ktlint @@ -15,14 +15,14 @@ import android.service.notification.StatusBarNotification
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.edit
-import java.security.SecureRandom
-import java.util.concurrent.locks.ReentrantLock
-import kotlin.concurrent.withLock
-import kotlin.text.Regex
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
+import java.security.SecureRandom
+import java.util.concurrent.locks.ReentrantLock
+import kotlin.concurrent.withLock
+import kotlin.text.Regex I'm not sure if this is intentional (to match intellij behavior, for example), or a bug. |
oh never mind just saw that intellij also doesn't add kotlinx there. |
I just found out with the "Import Layout" settings in IDEA/AS, you can simply enforce lexicographical import-ordering by removing all entries from "Import Layout" settings for Kotlin aside from "import all other imports" and disable the option "Import aliases separately". Then IDEA/AS orders imports just the same as ktlint does by default with --android flag (tested with the unofficial ktlint-plugin in AS, which includes ktlint 0.42.1 atm according to changelog). |
Although my settings look like this in I'm unable to get AS to organize imports the way Android Studio Dolphin 2021.3.1 |
Ktlint file
|
thank you @igorwojda |
In our project
ktlint 0.34.0
now reports a lot of incorrect import ordering, although we use a default import layou of IDE. All our developers have "Optimize imports" enabled by default, but this still creates an order like the following (which seems to be default one of Kotlin IDE plugin):Notice that the last one comes in non alphabetical order.
The unfortunate thing is that this cannot be changed.
Import order editing is there only for Java CodeStyle, kotlin plugin seems not to provide it. Correct me if I'm wrong.
If you think that this is still something that should be default, then please close.
But currently I suspect that many Android Studio/IntelliJ users will be disabling this rule, otherwise they'll have an endless conflict between IDE autoformatter/ktlint.
The text was updated successfully, but these errors were encountered: