https://kotlinlang.org logo
#ktlint
Title
# ktlint
b

Brais Gabin

08/21/2022, 3:55 PM
Hello! I’m writing a custom rule with autoCorrect. To do so I need to add
.trimMargin()
after a
KtStringTemplateExpression
but I don’t know how to manipulate the psi to do that. I tried to find an example in the ktlint code base but the ones that I find doesn’t work for my use case.
Right now I have this and it doesn’t work:
Copy code
expression.addAfter(LeafPsiElement(ElementType.IDENTIFIER, ".trimIndent()"), expression)
p

Paul Dingemans

08/21/2022, 4:51 PM
Best thing that you can do is first write the code sample that you're targeting at. Then next use 'ktlint --print-ast' to output the AST you have to replicate.
b

Brais Gabin

08/21/2022, 4:55 PM
Good one! Thanks!
25 Views