Skip to content

Commit

Permalink
Merge pull request #326 from rom4ek/colon-spacing-constructor-fix
Browse files Browse the repository at this point in the history
Fix constructor's colon-spacing lint and format
  • Loading branch information
shyiko authored Feb 4, 2019
2 parents bff39f6 + 4d1f6dc commit 195fcb7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class SpacingAroundColonRule : Rule("colon-spacing") {
}
}
val missingSpacingBefore = node.prevSibling !is PsiWhiteSpace &&
(node.parent is KtClassOrObject || node.parent.parent is KtTypeParameterList)
(node.parent is KtClassOrObject || node.parent is KtConstructor<*> ||
node.parent is KtTypeConstraint || node.parent.parent is KtTypeParameterList)
val missingSpacingAfter = node.nextSibling !is PsiWhiteSpace
when {
missingSpacingBefore && missingSpacingAfter -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ class SpacingAroundColonRuleTest {
class A {
@Deprecated("") @Throws(IOException::class, SecurityException::class)
protected abstract fun <T> f(
@Nullable thing: String, things: List<T>): Runnable where T : Runnable, T : Closeable
@Nullable thing: String, things: List<T>): Runnable where T : Runnable, T: Closeable
}
class A : B {
constructor(): super()
constructor(param: String) : super(param)
}
""".trimIndent()
)).isEmpty()
)).isEqualTo(listOf(
LintError(9, 82, "colon-spacing", "Missing spacing before \":\""),
LintError(12, 18, "colon-spacing", "Missing spacing before \":\"")
))
}

@Test
Expand All @@ -74,6 +81,15 @@ class SpacingAroundColonRuleTest {
}
interface D
interface C: D
class F(param: String):D(param)
class F2 constructor(param: String): D3(param)
class F3 : D3 {
constructor():super()
constructor(param: String): super(param)
val x = object:D3 { }
}
fun <T> max(a: T, b: T) where T: Comparable<T>
""".trimIndent()
)).isEqualTo(
"""
Expand All @@ -84,6 +100,15 @@ class SpacingAroundColonRuleTest {
}
interface D
interface C : D
class F(param: String) : D(param)
class F2 constructor(param: String) : D3(param)
class F3 : D3 {
constructor() : super()
constructor(param: String) : super(param)
val x = object : D3 { }
}
fun <T> max(a: T, b: T) where T : Comparable<T>
""".trimIndent()
)
}
Expand Down

0 comments on commit 195fcb7

Please sign in to comment.