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?
Disable wildcard imports In the Settings/Preferences dialog ( Ctrl+Alt+S ), select Editor | Code Style | Java | Imports. Make sure that the Use single class import option is enabled.
To avoid IntelliJ IDEA replacing imports with * , you need to configure the Class count to use import with '*' and Names count to use static import with '*' preferences: Go to Preferences > Editor > Code Style > Java.
Use Alt + Enter for importing a single package or use Alt + Shift + Enter to auto import all the unambiguous packages in the current file.
In fact, the book recommends using wildcard imports when using multiple classes from the same source. In other words, when we import two or more classes imported from a package, it's better to import the whole package.
As of version 0.34 or thereabouts you can override individual rules via editorconfig. This worked for me. https://github.com/pinterest/ktlint#editorconfig
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With