Skip to content

OneCasePerLine rule doesn't format properly with existing line breaks #1009

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

Open
ebgraham opened this issue Apr 30, 2025 · 1 comment
Open

Comments

@ebgraham
Copy link
Contributor

before formatting is appplied:

public enum TestEnum: Int {
  case a = 0,
    b = 1,
    c = 2
}

with OneCasePerLine formatting:

public enum TestEnum: Int {
  case a = 0
  case
    b = 1
  case
    c = 2
}

The correct format should be:

public enum TestEnum: Int {
  case a = 0
  case b = 1
  case c = 2
}
@allevato
Copy link
Member

allevato commented Apr 30, 2025

Presumably this is because we're keeping the leading newline trivia on the case's names. That's easy enough to remove.

It needs to be done with care though, since we'd also need to handle the following situations:

public enum TestEnum {
  case a,
    // line comment
    b,
    /* block comment */ c
}

The desired outcome for the line comment case is probably straightforward—move the trivia to the front of the injected case keyword:

  // line comment
  case b

For block comments, there's a bit more flexibility:

  /* block comment */ case c  ???
  case /* block comment */ c  ???

The first one is probably fine, and would at least be consistent with the line comment case.

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