Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 669
夢のの夢 Avatar asked Apr 09 '20 15:04

夢のの夢


People also ask

How do I fix wildcard imports in IntelliJ?

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.

Do not import * IntelliJ?

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.

How do I automatically import packages in IntelliJ?

Use Alt + Enter for importing a single package or use Alt + Shift + Enter to auto import all the unambiguous packages in the current file.

Should you use wildcard imports Java?

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.


Video Answer


1 Answers

As of version 0.34 or thereabouts you can override individual rules via editorconfig. This worked for me. https://github.com/pinterest/ktlint#editorconfig

like image 93
Alec Avatar answered Sep 28 '22 00:09

Alec