Search code examples
kotlinintellij-ideaktlint

Ktlint doesn't allow wildcard import? (Using IntelliJ auto import feature)


I am running a Kotlin project with ktlint maven plugin (first time user). but whenever I do a maven build. I often see the failure along the lines of

src/main/kotlin/com/myproject/model/User.kt:7:1: Wildcard import (cannot be auto-corrected)

Since I use IntelliJ, I often rely on auto import where many subpackages are grouped into a wildcard (*). Is this what ktline used to enforce good import practices?


Solution

  • As of version 0.34 or thereabouts you can override individual rules via EditorConfig. Add this to your .editorconfig file in the root of the project:

    [*.{kt,kts}]
    ktlint_no-wildcard-imports = disabled
    

    https://pinterest.github.io/ktlint/faq/#how-do-i-globally-disable-a-rule