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

Add rule to separate case from return statement #493

Open
pronebird opened this issue Mar 23, 2023 · 5 comments
Open

Add rule to separate case from return statement #493

pronebird opened this issue Mar 23, 2023 · 5 comments

Comments

@pronebird
Copy link

Currently swift-format would squash case and return statement together like this:

switch self {
    case .primary: return 0
    case .secondary: return 1
}

Ideally it should be able to produce something more readable but I don't see any option to achieve that.

switch self {
    case .primary: 
        return 0
    case .secondary: 
        return 1
}
@allevato
Copy link
Member

allevato commented Apr 7, 2023

Are you using a configuration that disables respectsExistingLineBreaks, or does this occur even when respectsExistingLineBreaks is enabled?

@pronebird
Copy link
Author

Using a configuration disabling existing line breaks

@allevato
Copy link
Member

allevato commented Apr 7, 2023

Then yes, this is working as intended; the single statement in the case fits on the same line and no line break is forced there so it makes the opinionated choice.

If this is desired behavior, we'd have to add a new configuration option to require a line break after a case.

I don't think I'd want to specialize case statements though; if we do this we should probably treat all single-statement control flow statements equally, e.g.:

// Today, if it fits
if x { foo() }

// With some new option
if x {
  foo()
}

@Optiroc
Copy link

Optiroc commented Jul 5, 2023

I’ve been evaluating swift-format the last few days and the eagerness to fit as much as possible on single lines is a bit hard to swallow, while the option to respect existing breaks is too respectful. :)

This PR seemed promising until I saw the date. Is there any current work being done in this area?

@ahoppen
Copy link
Contributor

ahoppen commented Apr 23, 2024

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

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

4 participants