Issue
When I select Code → Optimize Imports or Code → Reformat Code, the IntelliJ does optimize and sort imports, but even though I am using code style settings from Kotlin code style, the imports are not sorted in lexicographic order (not entirely at least). For example, this is the output produced:
import com.fasterxml.jackson.databind.ObjectMapper
import io.dropwizard.jackson.Jackson
import io.kotlintest.assertSoftly
import io.kotlintest.matchers.types.shouldBeNull
import io.kotlintest.shouldBe
import io.kotlintest.specs.ShouldSpec
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.intellij.lang.annotations.Language
import java.time.Instant // This should not be at the bottom!!!
while this is what expected by ktlint:
import com.fasterxml.jackson.databind.ObjectMapper
import io.dropwizard.jackson.Jackson
import io.kotlintest.assertSoftly
import io.kotlintest.matchers.types.shouldBeNull
import io.kotlintest.shouldBe
import io.kotlintest.specs.ShouldSpec
import java.time.Instant // should be here instead
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.intellij.lang.annotations.Language
In other words, it seems the formatter always puts imports from java.*
package at the bottom no matter what. Is there a way to make it be in line with what ktlint expects (and what would actually constitute lexicographic order)? Any hidden option I am missing or something?
I am using IntelliJ IDEA 2019.3.1 (Ultimate Edition) with the Kotlin plugin version 1.3.61-release-IJ2019.3-1. Version of ktlint is 0.36.0
Solution
This is a bug/missing functionality in the Kotlin IDEA plugin: https://youtrack.jetbrains.com/issue/KT-10974. Please vote.
Answered By - Alexey Belkov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.