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

Wrap binary expression before wrapping arguments of function call #1940

Closed
paul-dingemans opened this issue Apr 12, 2023 · 0 comments · Fixed by #2053
Closed

Wrap binary expression before wrapping arguments of function call #1940

paul-dingemans opened this issue Apr 12, 2023 · 0 comments · Fixed by #2053

Comments

@paul-dingemans
Copy link
Collaborator

Given code below with max-line-length set to 140:

fun foo() {
    if ((hasName(name) || absenceIsNull(descriptor, index)) && (!json.configuration.coerceInputValues || !coerceInputValue(descriptor, index, name)))
        return index
}

IntelliJ formats this as:

fun foo() {
    if ((hasName(name) || absenceIsNull(
            descriptor,
            index
        )) && (!json.configuration.coerceInputValues || !coerceInputValue(descriptor, index, name))
    )
        return index
}

Ktlint 0.48.2 formats it as:

fun foo() {
    if ((hasName(name) || absenceIsNull(descriptor, index)) && (!json.configuration.coerceInputValues || !coerceInputValue(
            descriptor,
            index,
            name
        ))) {
        return index
    }
}

Both are not optimal. First the binary expression should be split per part of the expression. It should ideally result in:

fun foo() {
    if ((hasName(name) || absenceIsNull(descriptor, index)) &&
        (!json.configuration.coerceInputValues || !coerceInputValue(descriptor, index, name))
    ) {
        return index
    }
}
@paul-dingemans paul-dingemans added this to the 1.0 (Yeah!) milestone Apr 16, 2023
@paul-dingemans paul-dingemans self-assigned this May 22, 2023
@paul-dingemans paul-dingemans changed the title Wrap binary expression before wrapping parameters of function call Wrap binary expression before wrapping arguments of function call May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant