ktlint
ktlint copied to clipboard
Errant comma added between parameter lambda and parenthesis (when trailing lambda present)
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.
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.
Heh, I was upgrading from 0.41 😄
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).
I feel like this is an IntelliJ bug. Filed https://youtrack.jetbrains.com/issue/KTIJ-23068/ijkotlinallowtrailingcommaoncallsite-adds-extraneous-comma-after-lambda
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.
Resolved by #1648 in version 0.48.0.