diff --git a/pkl-formatter/src/main/kotlin/org/pkl/formatter/Builder.kt b/pkl-formatter/src/main/kotlin/org/pkl/formatter/Builder.kt index c89f80469..6ce74d172 100644 --- a/pkl-formatter/src/main/kotlin/org/pkl/formatter/Builder.kt +++ b/pkl-formatter/src/main/kotlin/org/pkl/formatter/Builder.kt @@ -1239,7 +1239,7 @@ internal class Builder(sourceText: String, private val grammarVersion: GrammarVe // skip semicolons val children = children.filter { !it.isSemicolon() } // short circuit - if (children.isEmpty()) return listOf(spaceOrLine()) + if (children.isEmpty()) return emptyList() if (children.size == 1) return listOf(format(children[0])) val nodes = mutableListOf() diff --git a/pkl-formatter/src/test/kotlin/org/pkl/formatter/FormatterTest.kt b/pkl-formatter/src/test/kotlin/org/pkl/formatter/FormatterTest.kt index cd91fc6a8..bbad59816 100644 --- a/pkl-formatter/src/test/kotlin/org/pkl/formatter/FormatterTest.kt +++ b/pkl-formatter/src/test/kotlin/org/pkl/formatter/FormatterTest.kt @@ -113,4 +113,11 @@ class FormatterTest { walkDir(outputDir) } + + @Test + fun `whitespace only`() { + for (src in listOf(";;;", "\n", "\n\n\n", "\t")) { + assertThat(format(src)).isEqualTo("\n") + } + } }