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

Inconsistent code formatting of parameter list in lambda #1681

Closed
paul-dingemans opened this issue Oct 24, 2022 · 3 comments
Closed

Inconsistent code formatting of parameter list in lambda #1681

paul-dingemans opened this issue Oct 24, 2022 · 3 comments

Comments

@paul-dingemans
Copy link
Collaborator

Ktlint accepts code below as IntelliJ IDEA default formatter forces this format

val bar =
    BarBarBarBar { paramA,
                   paramB,
                   paramC ->
        Bar(paramA, paramB, paramC)
    }

However, format below would be more consistent when compared to parameter lists in classes and functions:

val bar =
    BarBarBarBar {
            paramA,
            paramB,
            paramC ->
        Bar(paramA, paramB, paramC)
    }

class Foo(
    paramA: String,
    paramB: String,
    paramC: String,
) {
    // ...
}

fun foo(
    paramA: String,
    paramB: String,
    paramC: String,
) {
    // ...
}            

As this change conflicts with IntelliJ IDEA Default formatting it should only be applied whenever ktlint allows to deviate from default formatting.

@eygraber
Copy link
Contributor

Ktlint accepts code below as IntelliJ IDEA default formatter forces this format

It looks like ktlint 0.47.1 is not accepting that format in my project:

fun combine(a: Any, b: Any, c: (Any, Any) -> Unit) {
  c(a, b)
}

class Foo {
  fun foo() {
    combine(
      Any(),
      Any()
    ) { a,
        b ->
      TODO()
    }
  }
}

.editorconfig

[*.{kt,kts}]
indent_size = 2
indent_style = space

error

Foo.kt:11:1: Unexpected indentation (8) (should be 6) (indent)

@paul-dingemans
Copy link
Collaborator Author

paul-dingemans commented Dec 15, 2022

val bar =
    BarBarBarBar { paramA,
                   paramB,
                   paramC ->
        Bar(paramA, paramB, paramC)
    }

Although your problem looks same as my problem it is actually different. But we can agree anyways that the result produced by ktlint is not good for either example.

@paul-dingemans paul-dingemans added this to the 0.49.0 milestone Dec 15, 2022
paul-dingemans added a commit to paul-dingemans/ktlint that referenced this issue Jan 18, 2023
…meter list (only in `ktlint_official` code style).

Closes pinterest#1681

The parameters of a function literal containing a multiline parameter list are aligned with first parameter whenever the first parameter is on the same line as the start of that function literal (not allowed in `ktlint_official` code style)

Closes pinterest#1756
@eygraber
Copy link
Contributor

eygraber commented Apr 24, 2023

After updating to 0.49.0 this is still not working as ktlint expects the formatting to look like this:

Sorry, I didn't realize you opened a separate issue for my case (#1756). I'll update there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants