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

Do not wrap a multiline spread operator expression * #2188

Closed
paul-dingemans opened this issue Aug 18, 2023 · 3 comments · Fixed by #2193
Closed

Do not wrap a multiline spread operator expression * #2188

paul-dingemans opened this issue Aug 18, 2023 · 3 comments · Fixed by #2193
Assignees
Milestone

Comments

@paul-dingemans
Copy link
Collaborator

paul-dingemans commented Aug 18, 2023

See https://kotlinlang.org/spec/expressions.html#spread-operator-expressions for * operator.

Given code below:

fun foo(vararg items: String): Array<String> = arrayOf(*items)

fun bar(vararg items: String) = "bar"

val bar = bar(
    *foo(
        "a",
        "b"
    )
)

then it is formatted like:

fun foo(vararg items: String): Array<String> = arrayOf(*items)

fun bar(vararg items: String) = "bar"

val bar =
    bar(
        *
            foo(
                "a",
                "b",
            ),
    )

while it should have been kept unchanged. There is no sense in wrapping after the operator.

@paul-dingemans paul-dingemans added this to the 1.0 (Yeah!) milestone Aug 18, 2023
@paul-dingemans paul-dingemans self-assigned this Aug 22, 2023
@paul-dingemans paul-dingemans changed the title Do not wrap a multiline PREFIX expression after operator Do not wrap a multiline spread expression after * operator Aug 22, 2023
@paul-dingemans paul-dingemans changed the title Do not wrap a multiline spread expression after * operator Do not wrap a multiline spread operator expression * Aug 22, 2023
@FooIbar
Copy link

FooIbar commented Oct 13, 2023

Regression on the latest snapshot build ktlint-cli-1.0.1-20231013.062913-18.

val foo =
    arrayOf(
        *items,
    )

Output: Line must not begin with "*" (standard:chain-wrapping)

@paul-dingemans
Copy link
Collaborator Author

Regression on the latest snapshot build ktlint-cli-1.0.1-20231013.062913-18.

val foo =
    arrayOf(
        *items,
    )

Output: Line must not begin with "*" (standard:chain-wrapping)

Can you please try again? I fixed this problem earlier this morning in PR #2306 (snapshot version ktlint-cli-1.0.1-20231013.082432-20 and it seems that you are using a snapshot which was published a earlier today in which the problem actually existed.

@FooIbar
Copy link

FooIbar commented Oct 13, 2023

Regression on the latest snapshot build ktlint-cli-1.0.1-20231013.062913-18.

val foo =
    arrayOf(
        *items,
    )

Output: Line must not begin with "*" (standard:chain-wrapping)

Can you please try again? I fixed this problem earlier this morning in PR #2306 (snapshot version ktlint-cli-1.0.1-20231013.082432-20 and it seems that you are using a snapshot which was published a earlier today in which the problem actually existed.

Can confirm it's fixed in ktlint-cli-1.0.1-20231013.082432-20.
Thank you!

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

Successfully merging a pull request may close this issue.

2 participants