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

Alternate formatting of ternary operator - Keep condition on same line as assignment. #557

Open
MarqueIV opened this issue Jun 29, 2023 · 1 comment

Comments

@MarqueIV
Copy link

MarqueIV commented Jun 29, 2023

Love swift-format, but one thing that really bugs me is for the life of me, I can't get it to not touch my ternary formatting. For instance, this is how my team and I like them to appear...

let message = someCondition
    ? "The condition was true"
    : "The condition was false"

To us, it's clear because the condition is up by the assignment (as that's what's driving it), and the true and false parts are each on their own line making it dead-simple to grep, even when speed-reading through code.

But what swift-format keeps doing is moving the condition to its own line entirely! Why?! And that dangling equals sign just makes it that much more annoying.

let message =
    someCondition
    ? "The condition was true"
    : "The condition was false"

Now even if this is something that is deemed not worthy of inclusion in the source code proper, I'd still love to be able to make that change in our own copy of swift-format, but I'm not sure where to begin.

@ahoppen
Copy link
Contributor

ahoppen commented Apr 23, 2024

Tracked in Apple’s issue tracker as rdar://126948384

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