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

Treat trailing Elvis operator as part of a call chain #445

Open
sgrimm opened this issue Mar 26, 2024 · 2 comments
Open

Treat trailing Elvis operator as part of a call chain #445

sgrimm opened this issue Mar 26, 2024 · 2 comments
Labels
enhancement New feature or request formatting-discussions Discussions about how formatting should look like, when there's no clear consensus.

Comments

@sgrimm
Copy link
Contributor

sgrimm commented Mar 26, 2024

This is a followup to #213.

Currently, a trailing Elvis operator is placed on the same line as the last step of a call chain if it fits:

desiredWithdrawals
    ?.filter { it.id == null && it.status == Status.New }
    ?.flatMap { it.userIds } ?: emptyList()

This makes it easy to miss the fact that there's an Elvis operator if I'm quickly skimming the code, because it looks like it's part of the last step of the chained call. For example, the above code snippet isn't very visually distinct from:

desiredWithdrawals
    ?.filter { it.id == null && it.status == Status.New }
    ?.flatMap { it.userIds ?: emptyList() }

I believe it'd be clearer to treat ?: the same as ?. for purposes of line break placement and indentation, such that the first example turns into

desiredWithdrawals
    ?.filter { it.id == null && it.status == Status.New }
    ?.flatMap { it.userIds }
    ?: emptyList()
@hick209 hick209 added enhancement New feature or request formatting-discussions Discussions about how formatting should look like, when there's no clear consensus. labels Mar 27, 2024
@avi-cenna
Copy link

I agree with this.

@nreid260
Copy link
Contributor

nreid260 commented Apr 9, 2024

The current behaviour is consistent with the other binary operators. Although, the other operators are constrained by needing to be on the same line, or else they get parsed as unary operators in a second statement.

Aligning the elvis with the dot of the call chain is also inconsistent; it would need to be indented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request formatting-discussions Discussions about how formatting should look like, when there's no clear consensus.
Projects
None yet
Development

No branches or pull requests

4 participants