Skip to content

Commit

Permalink
Fix error on formatting annotation for primary constructor (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
yukukotani authored and shashachu committed Oct 29, 2019
1 parent fc5f03d commit 8d4ebca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class AnnotationRule : Rule("annotation") {
// text in the file
val newLineWithIndent = (nodeBeforeAnnotations?.text ?: "\n").let {
// Make sure we only insert a single newline
it.substring(it.lastIndexOf('\n'))
if (it.contains('\n')) it.substring(it.lastIndexOf('\n'))
else it
}

if (noWhiteSpaceAfterAnnotation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,19 @@ class AnnotationRuleTest {
""".trimIndent()
)
}

@Test
fun `no error with formatting annotation for primary constructor`() {
val code =
"""
class Foo @Inject internal constructor()
""".trimIndent()
assertThat(
AnnotationRule().format(code)
).isEqualTo(
"""
class Foo @Inject internal constructor()
""".trimIndent()
)
}
}

0 comments on commit 8d4ebca

Please sign in to comment.