Skip to content

Commit

Permalink
Replace trimMargin usages (#5827)
Browse files Browse the repository at this point in the history
* Replace trimMargins with trimIndents.

* Minor code cleanup

* Fix StringShouldBeRawString docs: there's no margin in that raw string.

* Reformat and trimIndent some of StringShouldBeRawStringSpec
  • Loading branch information
TWiStErRob committed Feb 24, 2023
1 parent 059afea commit 9c4adb7
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ class DefaultConfigProviderSpec {
val actual = path.readText()
val expected = resourceAsPath("default-detekt-config.yml").readText() +
"""
|
|sample:
| TooManyFunctions:
| active: true
| TooManyFunctionsTwo:
| active: true
|
""".trimMargin()
sample:
TooManyFunctions:
active: true
TooManyFunctionsTwo:
active: true
""".trimIndent()

assertThat(actual).isEqualTo(expected)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ class DetektPrinter(private val arguments: GeneratorArgs) {
private fun markdownHeader(ruleSet: String): String {
check(ruleSet.length > 1) { "Rule set name must be not empty or less than two symbols." }
return """
|---
|title: ${ruleSet[0].uppercaseChar()}${ruleSet.substring(1)} Rule Set
|sidebar: home_sidebar
|keywords: [rules, $ruleSet]
|permalink: $ruleSet.html
|toc: true
|folder: documentation
|---
""".trimMargin()
---
title: ${ruleSet[0].uppercaseChar()}${ruleSet.substring(1)} Rule Set
sidebar: home_sidebar
keywords: [rules, $ruleSet]
permalink: $ruleSet.html
toc: true
folder: documentation
---
""".trimIndent()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ internal class RuleSetConfigPrinterTest {
val given = configurationTemplate.copy(defaultValue = DefaultValue.of(listOf("a", "b", "c")))
val actual = yaml { printConfiguration(given) }
val expected = """
|name:
| - 'a'
| - 'b'
| - 'c'
""".trimMargin()
name:
- 'a'
- 'b'
- 'c'
""".trimIndent()
assertThat(actual).isEqualTo(expected)
}

Expand All @@ -223,13 +223,13 @@ internal class RuleSetConfigPrinterTest {
)
val actual = yaml { printConfiguration(given) }
val expected = """
|name:
| - reason: 'reason a'
| value: 'a'
| - value: 'b'
| - reason: 'reason c'
| value: 'c'
""".trimMargin()
name:
- reason: 'reason a'
value: 'a'
- value: 'b'
- reason: 'reason c'
value: 'c'
""".trimIndent()
assertThat(actual).isEqualTo(expected)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class HtmlUtilsSpec {

@Test
fun `all line`() {
val snippet = createHTML().div() {
snippetCode("ruleName", code.asSequence(), SourceLocation(7, 1), 34)
val snippet = createHTML().div {
snippetCode("ruleName", code, SourceLocation(7, 1), 34)
}

assertThat(snippet).isEqualTo(
Expand All @@ -52,8 +52,8 @@ class HtmlUtilsSpec {

@Test
fun `part of line`() {
val snippet = createHTML().div() {
snippetCode("ruleName", code.asSequence(), SourceLocation(7, 7), 26)
val snippet = createHTML().div {
snippetCode("ruleName", code, SourceLocation(7, 7), 26)
}

assertThat(snippet).isEqualTo(
Expand All @@ -75,8 +75,8 @@ class HtmlUtilsSpec {

@Test
fun `more than one line`() {
val snippet = createHTML().div() {
snippetCode("ruleName", code.asSequence(), SourceLocation(7, 7), 66)
val snippet = createHTML().div {
snippetCode("ruleName", code, SourceLocation(7, 7), 66)
}

assertThat(snippet).isEqualTo(
Expand All @@ -98,44 +98,44 @@ class HtmlUtilsSpec {

@Test
fun `first line`() {
val snippet = createHTML().div() {
snippetCode("ruleName", code.asSequence(), SourceLocation(1, 1), 1)
val snippet = createHTML().div {
snippetCode("ruleName", code, SourceLocation(1, 1), 1)
}

assertThat(snippet).contains((1..4).map { " $it " })
}

@Test
fun `second line`() {
val snippet = createHTML().div() {
snippetCode("ruleName", code.asSequence(), SourceLocation(2, 1), 1)
val snippet = createHTML().div {
snippetCode("ruleName", code, SourceLocation(2, 1), 1)
}

assertThat(snippet).contains((1..5).map { " $it " })
}

@Test
fun `penultimate line`() {
val snippet = createHTML().div() {
snippetCode("ruleName", code.asSequence(), SourceLocation(15, 1), 1)
val snippet = createHTML().div {
snippetCode("ruleName", code, SourceLocation(15, 1), 1)
}

assertThat(snippet).contains((12..16).map { " $it " })
}

@Test
fun `last line`() {
val snippet = createHTML().div() {
snippetCode("ruleName", code.asSequence(), SourceLocation(16, 1), 1)
val snippet = createHTML().div {
snippetCode("ruleName", code, SourceLocation(16, 1), 1)
}

assertThat(snippet).contains((13..16).map { " $it " })
}

@Test
fun `when we provide an invalid source location the exception div is shown`() {
val snippet = createHTML().div() {
snippetCode("ruleName", code.asSequence(), SourceLocation(7, 100), 1)
val snippet = createHTML().div {
snippetCode("ruleName", code, SourceLocation(7, 100), 1)
}

assertThat(snippet).contains("""<div class="exception">""")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import org.jetbrains.kotlin.psi2ir.deparenthesize
* "height": 500
* }
* }
* """.trimMargin()
* """.trimIndent()
*
* val patRegex = """/^(\/[^\/]+){0,2}\/?$/gm"""
* </compliant>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ class StringShouldBeRawStringSpec {
fun getViolations() = listOf(
Arguments.of(""""\"[^\"\\\\\\n]*(?:\\\\.[^\"\\\\\\n]*)*\""""", 0, listOf("\\\\", "\\n", "\\\"")),
Arguments.of(
@Suppress("TrimMultilineRawString")
"""
"{\n" +
" \"window\": {\n" +
Expand All @@ -385,7 +384,7 @@ class StringShouldBeRawStringSpec {
" \"height\": 500\n" +
" }\n" +
"}"
""",
""".trimIndent(),
2,
listOf("\\n", "\\\""),
),
Expand Down Expand Up @@ -456,11 +455,7 @@ class StringShouldBeRawStringSpec {
0,
listOf("\\n"),
),
Arguments.of(
""""\n \\".isEmpty()""",
0,
listOf("\\n", "\\\\"),
),
Arguments.of(""""\n \\".isEmpty()""", 0, listOf("\\n", "\\\\")),
)

@Suppress("LongMethod")
Expand All @@ -485,8 +480,8 @@ class StringShouldBeRawStringSpec {
2
),
Arguments.of(
@Suppress("TrimMultilineRawString")
"""""${'"'}
"""
""${'"'}
{
"window": {
"title": "Sample Quantum With AI and ML Widget",
Expand All @@ -496,7 +491,7 @@ class StringShouldBeRawStringSpec {
}
}
""${'"'}
""",
""".trimIndent(),
0
),
Arguments.of(
Expand Down Expand Up @@ -525,7 +520,6 @@ class StringShouldBeRawStringSpec {
Arguments.of(""""This is point number ${'$'}i In java new line char is \n"""", 1, listOf("\\n")),
Arguments.of(""" "abc" + "\n" + "efg" + "\n" + "hij" """, 2, listOf("\\n")),
Arguments.of(
@Suppress("TrimMultilineRawString")
"""
"{\n" +
" \"window\": {\n" +
Expand All @@ -535,7 +529,7 @@ class StringShouldBeRawStringSpec {
" \"height\": 500\n" +
" }\n" +
"}"
""",
""".trimIndent(),
21,
listOf("\\n", "\\\""),
),
Expand Down

0 comments on commit 9c4adb7

Please sign in to comment.