Skip to content

Conversation

@lekhitha333
Copy link

@lekhitha333 lekhitha333 commented Jan 25, 2026

This change only cleans up the unnecessary empty lines between multiline comments without attempting to reattach them to imports.

Input:

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

Old Output:

// used for doc comments

// used for doc comments

// used for doc comments
import "pkl:json"
import "pkl:jsonnet"
import "pkl:math"

New Output:

    // 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"

related screenshots:
Screenshot 2026-01-25 at 4 38 56 PM

Related Issue
Fixes #1388

@lekhitha333
Copy link
Author

lekhitha333 commented Jan 25, 2026

Hi! I wanted to try contributing, so took on this one. If all looks good I'd love to take on the trailing comments as well!

Copy link
Contributor

@HT154 HT154 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! ❤️

We usually define tests like the one you've added using our snippet tests system instead of adding a test case in a file under pkl-formatter/src/test/kotlin/. You can create a Pkl file under pkl-formatter/src/test/files/FormatterSnippetTests/input. When you run the tests with OVERWRITE_SNIPPETS=1 ./gradlew test the first time a corresponding file with the formatted output will be created under pkl-formatter/src/test/files/FormatterSnippetTests/output. Subsequent test run without OVERWRITE_SNIPPETS set will fail if the output changes. We also have an "internal" IntelliJ plugin that makes it much easier to work with snippet tests, see DEVELOPMENT.adoc for more info on it.

Also, you can run CI checks locally with ./gradlew check so you don't need to wait for a maintainer to approve github actions.

@lekhitha333
Copy link
Author

Thank you for your feedback @HT154 !! The snippet test system is fantastic! I went ahead and added a snippet test and removed the test case!! Happy to make any other changes needed :)

@HT154 HT154 changed the title Remove empty lines in multiline comments for non-trailing imports (#1388) Jan 27, 2026
private fun getBaseSeparator(prev: Node, next: Node): FormatNode? {

return when {
endsInLineComment(prev) && endsInLineComment(next) -> mustForceLine()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too broad of a fix. You are changing how every line comment gets formatted.

// foo

// bar

The above code will have the newlines removed. You have to fix the import list specifically if you want to remove newlines from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants