Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest IntelliJ config of wildcard import #2639

Closed
toresbe opened this issue Apr 18, 2024 · 1 comment · Fixed by #2642
Closed

Suggest IntelliJ config of wildcard import #2639

toresbe opened this issue Apr 18, 2024 · 1 comment · Fixed by #2642
Milestone

Comments

@toresbe
Copy link

toresbe commented Apr 18, 2024

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants