Skip to content

Commit

Permalink
Fix indentation with new line before return type
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn committed Dec 1, 2019
1 parent 375509f commit 55542a7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,10 @@ class IndentationRule : Rule("indent"), Rule.Modifier.RestrictToRootLast {
// value
// }
adjustExpectedIndentAfterArrow(n, ctx)
prevLeaf?.elementType == COLON ->
// fun fn():
// Int
adjustExpectedIndentAfterColon(n, ctx)
}
visitWhiteSpace(n, autoCorrect, emit, editorConfig)
if (ctx.localAdj != 0) {
Expand Down Expand Up @@ -727,6 +731,12 @@ class IndentationRule : Rule("indent"), Rule.Modifier.RestrictToRootLast {
}
}

private fun adjustExpectedIndentAfterColon(n: ASTNode, ctx: IndentContext) {
expectedIndent++
debug { "++after(COLON) -> $expectedIndent" }
ctx.exitAdjBy(n.treeParent, -1)
}

private fun indentStringTemplate(
node: ASTNode,
autoCorrect: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,37 @@ class IndentationRuleTest {
)
)
}

@Test
fun `lint indentation new line before return type`() {
assertThat(
IndentationRule().lint(
"""
abstract fun doPerformSomeOperation(param: ALongParameter):
SomeLongInterface<ALongParameter.InnerClass, SomeOtherClass>
val s:
String = ""
fun process(
fileName:
String
): List<Output>
""".trimIndent()
)
).isEmpty()
}

@Test
fun `format indentation new line before return type`() {
val code = """
abstract fun doPerformSomeOperation(param: ALongParameter):
SomeLongInterface<ALongParameter.InnerClass, SomeOtherClass>
val s:
String = ""
fun process(
fileName:
String
): List<Output>
""".trimIndent()
assertThat(IndentationRule().format(code)).isEqualTo(code)
}
}

0 comments on commit 55542a7

Please sign in to comment.