Skip to content

Commit

Permalink
Refactor TrimMultilineRawString
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisGabin committed Jul 20, 2022
1 parent 0f3a359 commit 1db1c5a
Showing 1 changed file with 13 additions and 9 deletions.
Expand Up @@ -50,14 +50,7 @@ class TrimMultilineRawString(val config: Config) : Rule(config) {

if (expression.text.lines().count() <= 1) return

val nextCall = expression.getQualifiedExpressionForSelectorOrThis()
.getQualifiedExpressionForReceiver()
?.selectorExpression
?.asKtCallExpression()
?.calleeExpression
?.text

if (nextCall !in trimFunctions) {
if (!expression.isTrimmed()) {
report(
CodeSmell(
issue,
Expand All @@ -69,6 +62,17 @@ class TrimMultilineRawString(val config: Config) : Rule(config) {
}
}

private fun KtExpression.asKtCallExpression(): KtCallExpression? = this as? KtCallExpression
fun KtStringTemplateExpression.isTrimmed(): Boolean {
fun KtExpression.asKtCallExpression(): KtCallExpression? = this as? KtCallExpression

val nextCall = getQualifiedExpressionForSelectorOrThis()
.getQualifiedExpressionForReceiver()
?.selectorExpression
?.asKtCallExpression()
?.calleeExpression
?.text

return nextCall in trimFunctions
}

private val trimFunctions = listOf("trimIndent", "trimMargin")

0 comments on commit 1db1c5a

Please sign in to comment.