Skip to content

Commit

Permalink
Print a single space for empty do-while bodies. (#305)
Browse files Browse the repository at this point in the history
Summary:
Currently two spaces are emitted for empty bodies, because it is assumed a body will always be present.

Pull Request resolved: #305

Reviewed By: strulovich

Differential Revision: D35345203

Pulled By: cgrushko

fbshipit-source-id: 637a9d9a4c1c6685f833e360897f7a9d4fa955f8
  • Loading branch information
nreid260 authored and facebook-github-bot committed Apr 4, 2022
1 parent 18990a4 commit b640331
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2064,8 +2064,10 @@ class KotlinInputAstVisitor(
builder.sync(expression)
builder.token("do")
builder.space()
visit(expression.body)
builder.space()
if (expression.body != null) {
visit(expression.body)
builder.space()
}
builder.token("while")
builder.space()
builder.token("(")
Expand Down
2 changes: 2 additions & 0 deletions core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3025,6 +3025,8 @@ class FormatterTest {
| do {
| println("Everything is okay")
| } while (1 < 2)
|
| do while (1 < 2)
|}
|""".trimMargin())

Expand Down

0 comments on commit b640331

Please sign in to comment.