Closed sschuberth closed 4 years ago
@Tapchicoma, would you have an idea what the underlying problem is? Is the problem that ktlint should not assume node.getUserData(KtLint.EDITOR_CONFIG_USER_DATA_KEY)
to be non-null, or is the problem that apparently the editor config data is not injected?
From what I see Ktlint.EDITOR_CONFIG_USER_DATA_KEY
data should be always available in node. I will try to investigate this next week.
Thanks @Tapchicoma. IIRC, the private injectUserData is only called by lint and format, both of which are not called when using ktlint programmatically by detekt. However, detekt seem to insert EDITOR_CONFIG_USER_DATA_KEY
explicitly, but for some reason that does not seem to work. So maybe the issue still is on the detekt side after all.
I see that editorconfigUpdater()
in detekt code could return null
. In this case EDITOR_CONFIG_USER_DATA_KEY
will not be added to node.
Correct, I've meanwhile filed https://github.com/arturbosch/detekt/issues/2339 as I now believe the issue is in detekt, not in ktlint (although ktlint could and should make it more fool-proof to not run into this issue when calling ktlint programmatically by not blindly assuming EDITOR_CONFIG_USER_DATA_KEY
to be present in any case).
Also see the related https://github.com/arturbosch/detekt/issues/1803. The line
https://github.com/pinterest/ktlint/blob/b41aa2281f271d80255da727b838c0a111b6c293/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/FinalNewlineRule.kt#L18
results in
when running
on the detekt-ktlint-issue branch of https://github.com/heremaps/oss-review-toolkit.