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

Remove default for allowed wildcard imports in ktlint_official codestyle #1797

Closed
paul-dingemans opened this issue Jan 28, 2023 · 2 comments · Fixed by #1852
Closed

Remove default for allowed wildcard imports in ktlint_official codestyle #1797

paul-dingemans opened this issue Jan 28, 2023 · 2 comments · Fixed by #1852

Comments

@paul-dingemans
Copy link
Collaborator

paul-dingemans commented Jan 28, 2023

Expected Behavior
When java.util.* is included as a wildcard import, it should trigger the warning for no-wildcard-imports.
...
Given that, I think it makes sense that ktlint should stop including those two paths as default wildcard exceptions.

Originally posted by @greg-patterson in #1792 (comment)

@paul-dingemans
Copy link
Collaborator Author

The feature to respect setting ij_kotlin_packages_to_use_import_on_demand was implemented not too long ago in ktlint 0.45.x via #1272. The reason for adding the default values is that they seems to be hard-coded in IntelliJ IDEA as well (https://github.com/JetBrains/kotlin/blob/ffdab473e28d0d872136b910eb2e0f4beea2e19c/idea/formatter/src/org/jetbrains/kotlin/idea/core/formatter/KotlinCodeStyleSettings.java#L81-L82).

If the property is not set explicitly, IntelliJ IDEA allows imports java.util.* and kotlinx.android.synthetic.*. If ktlint would not do the same, this would result in a conclict between ktlint and IntelliJ IDEA. Lots of users of ktlint dislike that.

In the new codestyle ktlint_official the default value for allowed wildcard imports shoulbe be cleared.

@paul-dingemans
Copy link
Collaborator Author

Removing the default value for code ktlint_official resulted in ktlint to report wildcard imports for java.util.* in case that property ij_kotlin_packages_to_use_import_on_demand is not set. But IntelliJ IDEA interpret the absence of the property differently and stil add the the java.util.* import.

To keep KtLint and IntelliJ IDEA formatter in sync, it is needed to set .editorconfig property below explitcily:

ij_kotlin_packages_to_use_import_on_demand = unset

paul-dingemans added a commit that referenced this issue Mar 12, 2023
paul-dingemans added a commit that referenced this issue Mar 12, 2023
* For the new code style `ktlint_official`, do not allow wildcard imports `java.util` and `kotlinx.android.synthetic` by default

* Fix propagation of CODE_STYLE_PROPERTY to the EditorConfig so that the correct default can be determined

* Set 'ij_kotlin_packages_to_use_import_on_demand' to 'unset' to comply with this new default and resolve lint violation.
* When generating the '.editorconfig' file generate value "unset" for property 'ij_kotlin_packages_to_use_import_on_demand' in case the list of on demand imports is empty.

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

Successfully merging a pull request may close this issue.

1 participant