14

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?

夢のの夢
  • 5,054
  • 7
  • 33
  • 63

3 Answers3

15

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

joedeandev
  • 626
  • 1
  • 6
  • 15
Alec
  • 479
  • 4
  • 6
6

I was using ktlint-gradle and using the command ./gradlew ktlintCheck and my .editorconfig wasn't getting picked up. I solved it by adding this to build.gradle

ktlint {
    disabledRules.set(setOf("no-wildcard-imports"))
}
JJ.
  • 112
  • 2
  • 10
  • This stopped working lately with the following error `UserData should not contain '.editorconfig' properties [disabled_rules]. Such properties should be passed via the 'ExperimentalParams.editorConfigOverride' field. Note that this is only required for properties that (potentially) contain a value that differs from the actual value in the '.editorconfig' file.` Use the accepted answer instead – Totò Nov 25 '22 at 03:10
5

ktlint changed the rule layout in .editoconfig (again). Now it has to be:

ktlint_standard_no-wildcard-imports = disabled
mattelacchiato
  • 317
  • 3
  • 11