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 Elvis operator as part of a call chain #213

Closed
sgrimm opened this issue Apr 21, 2021 · 3 comments
Closed

Treat Elvis operator as part of a call chain #213

sgrimm opened this issue Apr 21, 2021 · 3 comments

Comments

@sgrimm
Copy link
Contributor

sgrimm commented Apr 21, 2021

Currently, it looks like an Elvis expression isn't counted as part of a call chain for purposes of figuring out where to put line breaks in the chain.

Example:

    val newWithdrawals =
        desiredWithdrawals?.filter {
          it.id == null && it.purpose != WithdrawalPurpose.GerminationTesting
        }
            ?: emptyList()

If I replace the Elvis operator with a chained method call, the format changes:

    val newWithdrawals =
        desiredWithdrawals
            ?.filter { it.id == null && it.purpose != WithdrawalPurpose.GerminationTesting }
            ?.also {}

and at that point, the Elvis operator gets formatted as part of the chain if I put it back:

    val newWithdrawals =
        desiredWithdrawals
            ?.filter { it.id == null && it.purpose != WithdrawalPurpose.GerminationTesting }
            ?.also {}
            ?: emptyList()

I think it would be more consistent if the first example were formatted like:

    val newWithdrawals =
        desiredWithdrawals
            ?.filter { it.id == null && it.purpose != WithdrawalPurpose.GerminationTesting }
            ?: emptyList()

Worth noting that this request possibly conflicts with #197.

@hick209
Copy link
Contributor

hick209 commented Sep 18, 2023

With current version(after #416)

    val newWithdrawals =
        desiredWithdrawals?.filter {
          it.id == null && it.purpose != WithdrawalPurpose.GerminationTesting
        } ?: emptyList()
    val newWithdrawals =
        desiredWithdrawals
            ?.filter { it.id == null && it.purpose != WithdrawalPurpose.GerminationTesting }
            ?.also {} ?: emptyList()

Would that be an acceptable output for this case, @sgrimm?

@hick209
Copy link
Contributor

hick209 commented Mar 26, 2024

Closing as I believe this is fixed. Feel free to reopen in case you think we still need to look into this

@hick209 hick209 closed this as completed Mar 26, 2024
@sgrimm
Copy link
Contributor Author

sgrimm commented Mar 26, 2024

Oops, sorry, I missed the earlier comment here. The new behavior is definitely an improvement over the old one, but I think it would still be better to treat the operator as a step in the call chain. I'll file a new issue to clarify.

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

No branches or pull requests

2 participants