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 6ce74d172..89306e339 100644 --- a/pkl-formatter/src/main/kotlin/org/pkl/formatter/Builder.kt +++ b/pkl-formatter/src/main/kotlin/org/pkl/formatter/Builder.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved. + * Copyright © 2025-2026 Apple Inc. and the Pkl project authors. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1302,7 +1302,10 @@ internal class Builder(sourceText: String, private val grammarVersion: GrammarVe } private fun getBaseSeparator(prev: Node, next: Node): FormatNode? { + return when { + endsInLineComment(prev) && endsInLineComment(next) -> mustForceLine() + endsInLineComment(prev) -> { if (prev.linesBetween(next) > 1) { TWO_NEWLINES diff --git a/pkl-formatter/src/test/files/FormatterSnippetTests/input/multi-line-comments.pkl b/pkl-formatter/src/test/files/FormatterSnippetTests/input/multi-line-comments.pkl new file mode 100644 index 000000000..30ec97738 --- /dev/null +++ b/pkl-formatter/src/test/files/FormatterSnippetTests/input/multi-line-comments.pkl @@ -0,0 +1,7 @@ +import "pkl:json" // used for doc comments +import "pkl:jsonnet" +import "pkl:math" // used for doc comments +import "pkl:pklbinary" +import "pkl:protobuf" +import "pkl:xml" +import "pkl:yaml" // used for doc comments \ No newline at end of file diff --git a/pkl-formatter/src/test/files/FormatterSnippetTests/output/multi-line-comments.pkl b/pkl-formatter/src/test/files/FormatterSnippetTests/output/multi-line-comments.pkl new file mode 100644 index 000000000..15bd7e970 --- /dev/null +++ b/pkl-formatter/src/test/files/FormatterSnippetTests/output/multi-line-comments.pkl @@ -0,0 +1,10 @@ +// used for doc comments +// used for doc comments +// used for doc comments +import "pkl:json" +import "pkl:jsonnet" +import "pkl:math" +import "pkl:pklbinary" +import "pkl:protobuf" +import "pkl:xml" +import "pkl:yaml" 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 bbad59816..b9002f58e 100644 --- a/pkl-formatter/src/test/kotlin/org/pkl/formatter/FormatterTest.kt +++ b/pkl-formatter/src/test/kotlin/org/pkl/formatter/FormatterTest.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved. + * Copyright © 2025-2026 Apple Inc. and the Pkl project authors. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.