You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What you can do now is to modify the AST in your custom rule inside a withAutoCorrect { ... } closure the same way KtLint does it.
This plugin ships an AutoCorrect by detekt action which will than trigger your rule's auto correct feature.
Thanks! I didn't know that.
I'm not sure I understand - withAutoCorrect { ... } is a workaround until this feature is done?
Or is it the way to go?
Also, If you have an example, that would be great.
(But don't bother creating one just for me - when I get to it, I'll dig, and If I succeed I can contribute documentation)
You can look up examples how to manipulate the AST in the KtLint rules of the FormattingRule.wrapper e.g.: detekt/detekt-formatting/src/main/kotlin/io/gitlab/arturbosch/detekt/formatting/wrappers/FinalNewline.kt
if (autoCorrect) {
node.addChild(PsiWhiteSpaceImpl("\n"), null)
}
if (autoCorrect) {
lastNode.node.treeParent.removeChild(lastNode.node)
}
withAutoCorrect { ... } is just the same as if (autoCorect) { } - a helper to only edit code when the user wants it.
It's a feature we ship with detekt from like milestone 4 and there is no plan to remove it as long as we have wrappers for KtLint.
In the standard detekt rule set we just do not want to mess around with users code :).
Something like this:
(Yes, this issue looks somewhat like Feature request: intention action to add @Suppress #12
)
The text was updated successfully, but these errors were encountered: