Skip to content

Commit

Permalink
bugfix/indentation-inside-string-templates(#758)
Browse files Browse the repository at this point in the history
### What's done:
  * Fixed bug
  • Loading branch information
aktsay6 committed Feb 16, 2021
1 parent f2d3a98 commit 8a5ecfc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import com.pinterest.ktlint.core.ast.ElementType.STRING_TEMPLATE
import com.pinterest.ktlint.core.ast.ElementType.THEN
import com.pinterest.ktlint.core.ast.ElementType.WHITE_SPACE
import com.pinterest.ktlint.core.ast.visit
import org.cqfn.diktat.ruleset.utils.hasParent
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package org.cqfn.diktat.ruleset.utils.indentation

import org.cqfn.diktat.ruleset.rules.chapter3.files.IndentationError
import org.cqfn.diktat.ruleset.rules.chapter3.files.lastIndent
import org.cqfn.diktat.ruleset.utils.hasParent

import com.pinterest.ktlint.core.ast.ElementType.ARROW
import com.pinterest.ktlint.core.ast.ElementType.AS_KEYWORD
Expand Down Expand Up @@ -39,7 +40,6 @@ import com.pinterest.ktlint.core.ast.ElementType.VALUE_PARAMETER_LIST
import com.pinterest.ktlint.core.ast.ElementType.WHITE_SPACE
import com.pinterest.ktlint.core.ast.nextCodeSibling
import com.pinterest.ktlint.core.ast.prevSibling
import org.cqfn.diktat.ruleset.utils.hasParent
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace
Expand Down Expand Up @@ -205,8 +205,8 @@ internal class DotCallChecker(config: IndentationConfig) : CustomIndentationChec
whiteSpace.nextSibling.node
.takeIf { nextNode ->
(nextNode.isDotBeforeCallOrReference() ||
nextNode.elementType == OPERATION_REFERENCE && nextNode.firstChildNode.elementType.let {
it == ELVIS || it == IS_EXPRESSION || it == AS_KEYWORD || it == AS_SAFE
nextNode.elementType == OPERATION_REFERENCE && nextNode.firstChildNode.elementType.let { type ->
type == ELVIS || type == IS_EXPRESSION || type == AS_KEYWORD || type == AS_SAFE
} || nextNode.isCommentBeforeDot()) && whiteSpace.parents.none { it.node.elementType == LONG_STRING_TEMPLATE_ENTRY }
}
?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule) {
@Tag(WarningNames.WRONG_INDENTATION)
fun `should trigger on string templates starting with new line`() {
lintMethod(
"""
"""
|fun foo(some: String) {
| fun bar() {
| val a = "${'$'}{
Expand All @@ -624,10 +624,10 @@ class IndentationRuleWarnTest : LintTestBase(::IndentationRule) {
|}
|
""".trimMargin(),
LintError(4, 1, ruleId, warnText(12, 8), true),
LintError(5, 1, ruleId, warnText(16, 12), true),
LintError(6, 1, ruleId, warnText(16, 12), true),
rulesConfigList = rulesConfigList
LintError(4, 1, ruleId, warnText(12, 8), true),
LintError(5, 1, ruleId, warnText(16, 12), true),
LintError(6, 1, ruleId, warnText(16, 12), true),
rulesConfigList = rulesConfigList
)
}

Expand Down

0 comments on commit 8a5ecfc

Please sign in to comment.