Skip to content

Commit

Permalink
Fix unwanted whitespace between super class constructor and its argum…
Browse files Browse the repository at this point in the history
…ent list
  • Loading branch information
paul-dingemans committed Apr 16, 2024
1 parent 51c289d commit db2c9ef
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,21 @@ public class ClassSignatureRule :
}
}

// Disallow:
// class Foo : Bar<String> ("foobar")
superTypes
.filter { it.elementType == SUPER_TYPE_CALL_ENTRY }
.forEach { superTypeCallEntry ->
superTypeCallEntry
.findChildByType(WHITE_SPACE)
?.let { whitespace ->
emit(whitespace.startOffset, "No whitespace expected", true)
if (autoCorrect) {
whitespace.treeParent.removeChild(whitespace)
}
}
}

return whiteSpaceCorrection
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,55 @@ class ClassSignatureRuleTest {
.hasNoLintViolations()
}

@Nested
inner class `Issue 2630 - White space in super type call entry` {
@Test
fun `Issue 2630 - Given a super type call entry without type argument list`() {
val code =
"""
class Foo1 : Bar("foobar")
class Foo2 : Bar ("foobar")
class Foo3 : Bar
("foobar")
""".trimIndent()
val formattedCode =
"""
class Foo1 : Bar("foobar")
class Foo2 : Bar("foobar")
class Foo3 : Bar("foobar")
""".trimIndent()
classSignatureWrappingRuleAssertThat(code)
.hasLintViolations(
LintViolation(2, 17, "No whitespace expected"),
LintViolation(3, 14, "Super type should start on a newline"),
LintViolation(3, 17, "No whitespace expected"),
).isFormattedAs(formattedCode)
}

@Test
fun `Issue 2630 - Given a super type call entry with type argument list`() {
val code =
"""
class Foo1 : Bar<String>("foobar")
class Foo2 : Bar<String> ("foobar")
class Foo3 : Bar<String>
("foobar")
""".trimIndent()
val formattedCode =
"""
class Foo1 : Bar<String>("foobar")
class Foo2 : Bar<String>("foobar")
class Foo3 : Bar<String>("foobar")
""".trimIndent()
classSignatureWrappingRuleAssertThat(code)
.hasLintViolations(
LintViolation(2, 25, "No whitespace expected"),
LintViolation(3, 14, "Super type should start on a newline"),
LintViolation(3, 25, "No whitespace expected"),
).isFormattedAs(formattedCode)
}
}

private companion object {
const val UNEXPECTED_SPACES = " "
const val NO_SPACE = ""
Expand Down

0 comments on commit db2c9ef

Please sign in to comment.