Dektet or other clients can configure ImportOrderingRule by invoking UserDataHolder.putUserData(Key<T>, T)
https://github.com/pinterest/ktlint/pull/935 defines PatternEntry as the internal type, which makes it impossible for Detekt to generate the value to invoke UserDataHolder.putUserData(). Therefore,
Detekt now either need to use a ugly hack (https://github.com/detekt/detekt/pull/3281) or needs to bypass the internal visibility of PatternEntry.
ImportOrderingRule is now in FeatureInAlphaState, so I expect API or implementation to change in the future. But I would like to use this issue to discuss the way moving forward.
ImportOrderingRule has FeatureInAlphaState because it uses experimental .editorconfig loading/generating feature.
Generally this rule should be configured by .editorconfig file and not directly via user data.
Probably we could expose some method/structure to pass .editorconfig "content", so it will be used instead of any existing one, but I would prefer not to do it.
but I would prefer not to do it.
Why this? Ideally KtLint API users should be able to properly configure the linter behavior without having to rely on .editorconfig files. I can see how that is a useful feature for KtLint when considered as a standalone tool, but it makes harder to integrate KtLint with other systems.
After some discussion we most probably expose some way to pass Map<Key, String> that will override any loaded .editorconfig configuration from files. Probably whether to override could be also set via flag.
Most helpful comment
After some discussion we most probably expose some way to pass
Map<Key, String>that will override any loaded.editorconfigconfiguration from files. Probably whether to override could be also set via flag.