Is there a way to enable wildcard imports but enfo...
# ktlint
d
Is there a way to enable wildcard imports but enforce the rules set by
ij_kotlin_name_count_to_use_star_import
?
p
If you want to allow wildcard imports than you will need to disable the rule that forbids them. See docs.
d
I read the docs and I know that I can enable wildcard imports. I'm asking whether I can set additional restrictions to the wildcarding behaviour, such as name count.
p
Yes you can set them, but ktlint is not using them. But they will still affect the formatting done by the default Intellij IDEA formatter.
d
Would you consider making ktlint using them?
p
I don't know because it is not clear to me what you expect. But in general I am hesitant about adding configuration option for minor optimization (https://pinterest.github.io/ktlint/latest/faq/#can-a-new-toggle-be-added-to-optionally-enabledisable-format-code-in-a-particular-way)
d
I expect that a linter would cover and enforce all agreed rules. So if the team agrees that we should use wildcard imports if there are 3 or more imports from the same package I would like to enforce that. Currently, that's not possible with ktlint (while it's possible -although not in the enforcing mode - in IDEA)
Since IDEA itself has an option to fine-tune wildcard imports (with quite a bad UX, though) I wouldn't consider this just a minor option.
p
As I understand it, ktlint only has access to a model of the code in the file. As such, it cannot count the number of imports used from
java.util.*
, for example. The only enforcement it could do is to replace
>n
imports from a package with an
import package.*
but it wouldn't be able to unpack the
import package.*
to two distinct imports if you were to remove one of the usages.
d
I see, makes sense. I would say that for me even packing >n imports would be useful but I understand that it's not fully consistent.
130 Views