pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.06k stars 504 forks source link

Suggest IntelliJ config of wildcard import #2639

Closed toresbe closed 2 months ago

toresbe commented 2 months ago

The documentation for the no-wildcard-import rule documents the changes to .editorconfig to make ktlint wildcard imports compatible with IntelliJ, but not the reverse case.

The solution documented for IntelliJ isn't optimal for those of us who have .idea in .gitignore but still wish to synchronize these settings across the team.

Setting IntelliJ's Code Style settings and exported them to an .editorconfig file, yielding a file from which I added these to my .editorconfig:

# Disable wildcard imports
ij_kotlin_name_count_to_use_star_import = 2147483647
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
# For java.util., ... too
ij_kotlin_packages_to_use_import_on_demand = unset

Now when I use Optimize Imports in IntelliJ, the imports produced are in line with those expected by ktlint.

PS FWIW: I believe that together with the following setting, this .editorconfig defines the settings prescribed for .idea/codeStyles/Project.xml

ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL

I also have set this one:

insert_final_newline = true
paul-dingemans commented 2 months ago

Thanks for bringing this to my attention.

The solution documented for IntelliJ could very well be outdated. In newly created Kotlin projects, I do not see the .idea/codeStyles directory being created anymore. So I will update this page that those files should be deleted. I will add below to this page (and make a reference from the wildcard import page to this section):

insert_final_newline = true

ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
ij_kotlin_name_count_to_use_star_import = 2147483647
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
ij_kotlin_packages_to_use_import_on_demand = unset