ktfmt icon indicating copy to clipboard operation
ktfmt copied to clipboard

Version 1.1.0.51 does not format correctly for style "Kotlinlang"

Open kay-horst opened this issue 1 year ago • 1 comments

  • Reformat code, formerly formatted with "Kotlinlang"-style => formatting is changed
  • Apply Gradle Spotless plugin (./gradlew spotlessapply) => Formatting back to old (correct) state

Settings for the Spotless plugin:

    kotlin {
        target 'src/main/**/*.kt'
        ktfmt().kotlinlangStyle()
    }

The workaround mentioned in #486 did not work for me.

kay-horst avatar Jul 09 '24 09:07 kay-horst

This was also reported here https://github.com/facebook/ktfmt/issues/490 and is supposedly fixed, but the fix is not released yet.

I'm hoping they release it soon, so that the IntelliJ plugin, gradle-ktfmt and ktfmt jar all result in the same formatting again.

darioseidl avatar Jul 11 '24 10:07 darioseidl

Any news on a possible release for the mentioned fix? It's quite annoying to work around this.

theovier avatar Jul 30 '24 19:07 theovier

https://github.com/facebook/ktfmt/releases/tag/v0.52 🎉

rock3r avatar Aug 15 '24 07:08 rock3r

Ah no, release failed :(

rock3r avatar Aug 15 '24 07:08 rock3r

v0.52 is out now. Let us know if you still face the issues reported here

hick209 avatar Aug 27 '24 18:08 hick209

Also make sure that spotless is using the same version of ktfmt that you are using in your IDE

hick209 avatar Aug 27 '24 18:08 hick209

v0.52 is out now. Let us know if you still face the issues reported here

It works for me now: ktfmt 0.52, the IntelliJ plugin, and ktfmt-gradle 0.20.1 all produce the same result.

darioseidl avatar Aug 28 '24 09:08 darioseidl

The plugin now adds commas after each last parameter of a method, if each parameter is on its own line:

class Foo(
    private val value1: String,
    private val value2: String,
    private val value3: String,
    private val value3: String
) {

becomes

class Foo(
    private val value1: String,
    private val value2: String,
    private val value3: String,
    private val value3: String,
) {

It was not the case before.

Is this standard behaviour?

kay-horst avatar Aug 28 '24 11:08 kay-horst

@kay-horst it is as now it handles trailing lambdas for the kotlinlang style (see #442)

hick209 avatar Aug 28 '24 13:08 hick209