Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ktfmt invocation is not strictly idempotent (running it a second time gives a different result) #521

Open
staktrace opened this issue Nov 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@staktrace
Copy link

staktrace commented Nov 14, 2024

Put this snippet of (sanitized and mostly-reduced) kotlin code into a file:

class SomeClass {
  private fun someFunction(
  ) {
    ListAssert(blah)
      .blahBlahBlah(
        "abcdefghijklmnopqurstuvw",
        "alsdkf jlasjf lkasjdlsadfjl" // A long comment that gets wrapped and then reformatted again after running ktfmt twice, what!!!!
      ).isEqualTo(someOtherThing)
  }
}

Download the ktfmt CLI tool per the instructions on the web page:

wget https://repo1.maven.org/maven2/com/facebook/ktfmt/0.53/ktfmt-0.53-jar-with-dependencies.jar

And run it on the file:

java -jar ktfmt-0.53-jar-with-dependencies.jar --google-style file.kt

This formats the file so it looks like this:

class SomeClass {
  private fun someFunction() {
    ListAssert(blah)
      .blahBlahBlah(
        "abcdefghijklmnopqurstuvw",
        "alsdkf jlasjf lkasjdlsadfjl", // A long comment that gets wrapped and then reformatted again
                                      // after running ktfmt twice, what!!!!
      )
      .isEqualTo(someOtherThing)
  }
}

Now run it a second time:

java -jar ktfmt-0.53-jar-with-dependencies.jar --google-style file.kt

I would expect that running it a second time would do nothing, but instead it moves that wrapped comment line so the file looks like this:

class SomeClass {
  private fun someFunction() {
    ListAssert(blah)
      .blahBlahBlah(
        "abcdefghijklmnopqurstuvw",
        "alsdkf jlasjf lkasjdlsadfjl", // A long comment that gets wrapped and then reformatted again
        // after running ktfmt twice, what!!!!
      )
      .isEqualTo(someOtherThing)
  }
}

After this running ktfmt again on the file does nothing and it seems to be "stable". However the fact that the first invocation produces a result that is not "fully formatted" seems unexpected and possibly a bug.

@hick209 hick209 added the bug Something isn't working label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants