Ktlint: Expose configurability of ImportOrderingRule

Created on 17 Dec 2020  路  4Comments  路  Source: pinterest/ktlint

Expected Behavior

Dektet or other clients can configure ImportOrderingRule by invoking UserDataHolder.putUserData(Key<T>, T)

Observed Behavior

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.

Your Environment

  • Version of ktlint used: 0.40.0
enhancement

Most helpful comment

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.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vanniktech picture vanniktech  路  5Comments

filipedelimabrito picture filipedelimabrito  路  3Comments

ZakTaccardi picture ZakTaccardi  路  3Comments

xenomachina picture xenomachina  路  5Comments

pkubowicz picture pkubowicz  路  4Comments