Skip to content

Commit

Permalink
### Whats added:
Browse files Browse the repository at this point in the history
 * 1 new fix test
 * first corrected code

### Issue (#811)
  • Loading branch information
Arrgentum committed Jun 6, 2022
1 parent 9423868 commit 2b0a521
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.pinterest.ktlint.core.ast.ElementType.SAFE_ACCESS_EXPRESSION
import com.pinterest.ktlint.core.ast.ElementType.SHORT_STRING_TEMPLATE_ENTRY
import com.pinterest.ktlint.core.ast.ElementType.STRING_TEMPLATE
import com.pinterest.ktlint.core.ast.ElementType.THEN
import com.pinterest.ktlint.core.ast.ElementType.VALUE_ARGUMENT
import com.pinterest.ktlint.core.ast.ElementType.WHITE_SPACE
import com.pinterest.ktlint.core.ast.visit
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
Expand Down Expand Up @@ -217,11 +218,15 @@ class IndentationRule(configRules: List<RulesConfig>) : DiktatRule(
actualIndent: Int
) {
val nextNode = whiteSpace.node.treeNext
if (nextNode != null &&
nextNode.elementType == DOT_QUALIFIED_EXPRESSION &&
nextNode.firstChildNode.elementType == STRING_TEMPLATE &&
nextNode.firstChildNode.text.startsWith("\"\"\"") &&
nextNode.findChildByType(CALL_EXPRESSION)?.text?.let {
val nextNodeDot = if (nextNode.elementType == DOT_QUALIFIED_EXPRESSION) {
nextNode
} else {
nextNode.getFirstChildWithType(DOT_QUALIFIED_EXPRESSION)
}
if (nextNodeDot != null &&
nextNodeDot.firstChildNode.elementType == STRING_TEMPLATE &&
nextNodeDot.firstChildNode.text.startsWith("\"\"\"") &&
nextNodeDot.findChildByType(CALL_EXPRESSION)?.text?.let {
it == "trimIndent()" ||
it == "trimMargin()"
} == true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,10 @@ class IndentationRuleFixTest : FixTestBase("test/paragraph3/indentation",
fun `regression - incorrect fixing in constructor parameter list`() {
fixAndCompare("ConstructorExpected.kt", "ConstructorTest.kt")
}

@Test
@Tag(WarningNames.WRONG_INDENTATION)
fun `multiline string`() {
fixAndCompare("MultilionStringTest.kt", "MultilionStringTest.kt")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package test.paragraph3.indentation

fun checkScript() {
lintMethod(
"""
|val q = 1
|
""".trimMargin(),
fileName = "src/main/kotlin/org/cqfn/diktat/Example.kts"
)
}

fun lintMethod(trimMargin: String, fileName: String) {
TODO("Not yet implemented")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package test.paragraph3.indentation

fun checkScript() {
lintMethod(
"""
|val q = 1
|
""".trimMargin(),
fileName = "src/main/kotlin/org/cqfn/diktat/Example.kts"
)
}

fun lintMethod(trimMargin: String, fileName: String) {
TODO("Not yet implemented")
}

0 comments on commit 2b0a521

Please sign in to comment.