facebook / ktfmt

A program that reformats Kotlin source code to comply with the common community standard for Kotlin code conventions.
https://facebook.github.io/ktfmt/
Apache License 2.0
933 stars 78 forks source link

Version 1.1.0.51 does not format correctly for style "Kotlinlang" #493

Closed kay-horst closed 3 months ago

kay-horst commented 4 months ago

Settings for the Spotless plugin:

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

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

darioseidl commented 4 months ago

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.

theovier commented 4 months ago

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

rock3r commented 3 months ago

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

rock3r commented 3 months ago

Ah no, release failed :(

hick209 commented 3 months ago

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

hick209 commented 3 months ago

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

darioseidl commented 3 months ago

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.

kay-horst commented 3 months ago

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?

hick209 commented 3 months ago

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