ktlint icon indicating copy to clipboard operation
ktlint copied to clipboard

Errant comma added between parameter lambda and parenthesis (when trailing lambda present)

Open JakeWharton opened this issue 3 years ago • 3 comments
trafficstars

ktlint 0.46.1

Rules:

        'disabled_rules': 'filename',
        'insert_final_newline': 'true',
        'end_of_line': 'lf',
        'indent_size': '2',
        'ij_kotlin_allow_trailing_comma': 'true',
        'ij_kotlin_allow_trailing_comma_on_call_site': 'true',
        'ij_kotlin_imports_layout': '*',

Input:

fun twoLambdas(one: () -> Unit, two: () -> Unit) = Unit

fun test() {
  twoLambdas({
    println("one")
  }) {
    println("two")
  }
}

Actual output:

 fun twoLambdas(one: () -> Unit, two: () -> Unit) = Unit

 fun test() {
   twoLambdas({
     println("one")
-  }) {
+  },) {
     println("two")
   }
}

Expected output:

No change from input.

JakeWharton avatar Jul 26 '22 13:07 JakeWharton

Tnx for reporting. This bug already seems to be around since version 0.42.x. The trailing comma should not be added to the argument list whenever a function call is followed by a lambda.

paul-dingemans avatar Jul 26 '22 18:07 paul-dingemans

Heh, I was upgrading from 0.41 😄

JakeWharton avatar Jul 26 '22 19:07 JakeWharton

Tnx for reporting. This bug already seems to be around since version 0.42.x. The trailing comma should not be added to the argument list whenever a function call is followed by a lambda.

Current behavior of KtLint is consistent with default formatting of IntelliJ IDEA. Omitting the trailing comma in this would lead to a conflict with IntelliJ IDEA. As of that it can not be fixed in KtLint for now (see #1526).

paul-dingemans avatar Aug 14 '22 11:08 paul-dingemans

I feel like this is an IntelliJ bug. Filed https://youtrack.jetbrains.com/issue/KTIJ-23068/ijkotlinallowtrailingcommaoncallsite-adds-extraneous-comma-after-lambda

Hexcles avatar Sep 28 '22 15:09 Hexcles

I do agree with you that this is a bug on the IntelliJ side. Tnx for creating the bug there and copy the reference here.

paul-dingemans avatar Sep 28 '22 19:09 paul-dingemans

Resolved by #1648 in version 0.48.0.

paul-dingemans avatar Jan 03 '23 17:01 paul-dingemans