Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiline string indent #1052

Merged
merged 10 commits into from
Oct 24, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -938,11 +938,12 @@ class AnnotationRuleTest {

@Test
fun `lint file annotations should be separated with a blank line in script 1`() {
val code = """
val code =
"""
@file:Suppress("UnstableApiUsage")
pluginManagement {
}
""".trimIndent()
""".trimIndent()
assertThat(AnnotationRule().lint(code, script = true)).isEqualTo(
listOf(
LintError(1, 34, "annotation", AnnotationRule.fileAnnotationsShouldBeSeparated)
Expand All @@ -952,12 +953,13 @@ class AnnotationRuleTest {

@Test
fun `lint file annotations should be separated with a blank line in script 2`() {
val code = """
val code =
"""
@file:Suppress("UnstableApiUsage")

pluginManagement {
}
""".trimIndent()
""".trimIndent()
assertThat(AnnotationRule().lint(code, script = true)).isEmpty()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ class AnnotationSpacingRuleTest {
fun `annotations should not be separated by comments from the annotated construct`() {
val code =
"""
@Suppress("DEPRECATION") @Hello
/**
* block comment
*/
class Foo {
}
@Suppress("DEPRECATION") @Hello
/**
* block comment
*/
class Foo {
}
""".trimIndent()
assertThat(
AnnotationSpacingRule().lint(code)
Expand All @@ -352,41 +352,41 @@ class AnnotationSpacingRuleTest {
fun `annotations should be moved after comments`() {
val code =
"""
@Suppress("DEPRECATION") @Hello
/**
* block comment
*/
class Foo {
}
@Suppress("DEPRECATION") @Hello
/**
* block comment
*/
class Foo {
}
""".trimIndent()
assertThat(
AnnotationSpacingRule().format(code)
).isEqualTo(
"""
/**
* block comment
*/
@Suppress("DEPRECATION") @Hello
class Foo {
}
/**
* block comment
*/
@Suppress("DEPRECATION") @Hello
class Foo {
}
""".trimIndent()
)

val codeEOL =
"""
@Suppress("DEPRECATION") @Hello
// hello
class Foo {
}
@Suppress("DEPRECATION") @Hello
// hello
class Foo {
}
""".trimIndent()
assertThat(
AnnotationSpacingRule().format(codeEOL)
).isEqualTo(
"""
// hello
@Suppress("DEPRECATION") @Hello
class Foo {
}
// hello
@Suppress("DEPRECATION") @Hello
class Foo {
}
""".trimIndent()
)
}
Expand All @@ -395,33 +395,33 @@ class AnnotationSpacingRuleTest {
fun `preceding whitespaces are preserved`() {
val code =
"""
package a.b.c
package a.b.c

val hello = 5
val hello = 5


@Suppress("DEPRECATION") @Hello
/**
* block comment
*/
class Foo {
}
@Suppress("DEPRECATION") @Hello
/**
* block comment
*/
class Foo {
}
""".trimIndent()
assertThat(
AnnotationSpacingRule().format(code)
).isEqualTo(
"""
package a.b.c
package a.b.c

val hello = 5
val hello = 5


/**
* block comment
*/
@Suppress("DEPRECATION") @Hello
class Foo {
}
/**
* block comment
*/
@Suppress("DEPRECATION") @Hello
class Foo {
}
""".trimIndent()
)
}
Expand All @@ -443,18 +443,18 @@ class AnnotationSpacingRuleTest {
fun `format eol comment on the same line as the annotation`() {
val code =
"""
@SuppressWarnings // foo
@SuppressWarnings // foo

fun bar() {
}
fun bar() {
}
""".trimIndent()
assertThat(
AnnotationSpacingRule().format(code)
).isEqualTo(
"""
@SuppressWarnings // foo
fun bar() {
}
@SuppressWarnings // foo
fun bar() {
}
""".trimIndent()
)
}
Expand All @@ -463,19 +463,19 @@ class AnnotationSpacingRuleTest {
fun `format eol comment on the same line as the annotation 2`() {
val code =
"""
@SuppressWarnings // foo
// bar
fun bar() {
}
@SuppressWarnings // foo
// bar
fun bar() {
}
""".trimIndent()
assertThat(
AnnotationSpacingRule().format(code)
).isEqualTo(
"""
// bar
@SuppressWarnings // foo
fun bar() {
}
// bar
@SuppressWarnings // foo
fun bar() {
}
""".trimIndent()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class ArgumentListWrappingRuleTest {
assertThat(
ArgumentListWrappingRule().lint(
"""
val x = f(
a,
b, c
)
val x = f(
a,
b, c
)
""".trimIndent()
)
).isEqualTo(
Expand All @@ -36,19 +36,19 @@ class ArgumentListWrappingRuleTest {
assertThat(
ArgumentListWrappingRule().format(
"""
val x = f(
a,
b, c
)
val x = f(
a,
b, c
)
""".trimIndent()
)
).isEqualTo(
"""
val x = f(
a,
b,
c
)
val x = f(
a,
b,
c
)
""".trimIndent()
)
}
Expand All @@ -58,25 +58,25 @@ class ArgumentListWrappingRuleTest {
assertThat(
ArgumentListWrappingRule().format(
"""
val x = test(
one("a", "b",
"c"),
"Two", "Three", "Four"
)
val x = test(
one("a", "b",
"c"),
"Two", "Three", "Four"
)
""".trimIndent()
)
).isEqualTo(
"""
val x = test(
one(
"a",
"b",
"c"
),
"Two",
"Three",
"Four"
)
val x = test(
one(
"a",
"b",
"c"
),
"Two",
"Three",
"Four"
)
""".trimIndent()
)
}
Expand All @@ -86,7 +86,7 @@ class ArgumentListWrappingRuleTest {
assertThat(
ArgumentListWrappingRule().lint(
"""
val x = f(a, b, c)
val x = f(a, b, c)
""".trimIndent(),
userData = mapOf("max_line_length" to "10")
)
Expand Down
Loading