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 e120aa4 commit c92c850
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class IndentationRule(configRules: List<RulesConfig>) : DiktatRule("indentation"
}

val expectedIndent = checkResult?.expectedIndent ?: indentError.expected
if (checkResult?.adjustNext == true && !astNode.hasParent(LONG_STRING_TEMPLATE_ENTRY)) {
if (checkResult?.adjustNext == true && astNode.parents().none { it.elementType == LONG_STRING_TEMPLATE_ENTRY }) {
val exceptionInitiatorNode = astNode.getExceptionalIndentInitiator()
context.addException(exceptionInitiatorNode, expectedIndent - indentError.expected, checkResult.includeLastChild)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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.hasParameters
import org.cqfn.diktat.ruleset.utils.hasParent
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
Expand Down Expand Up @@ -205,10 +204,10 @@ internal class DotCallChecker(config: IndentationConfig) : CustomIndentationChec
override fun checkNode(whiteSpace: PsiWhiteSpace, indentError: IndentationError): CheckResult? {
whiteSpace.nextSibling.node
.takeIf { nextNode ->
nextNode.isDotBeforeCallOrReference() ||
(nextNode.isDotBeforeCallOrReference() ||
nextNode.elementType == OPERATION_REFERENCE && nextNode.firstChildNode.elementType.let {
it == ELVIS || it == IS_EXPRESSION || it == AS_KEYWORD || it == AS_SAFE
} || nextNode.isCommentBeforeDot()
} || nextNode.isCommentBeforeDot()) && whiteSpace.parents.none { it.node.elementType == LONG_STRING_TEMPLATE_ENTRY }
}
?.let {
if (it.isFromStringTemplate()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,8 @@ 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)
LintError(6, 1, ruleId, warnText(16, 12), true),
rulesConfigList = rulesConfigList
)
}

Expand Down

0 comments on commit c92c850

Please sign in to comment.