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

single-line switch statements become harder to read #1251

Open
chipweinberger opened this issue Aug 22, 2023 · 3 comments
Open

single-line switch statements become harder to read #1251

chipweinberger opened this issue Aug 22, 2023 · 3 comments

Comments

@chipweinberger
Copy link

chipweinberger commented Aug 22, 2023

I'd love to turn the formatter on for my own code, but it objectively hurts carefully indented code.

Is there anyone that would actually find the after format more readable?

Before format:

BluetoothAdapterState _bmToBluetoothAdapterState(BmAdapterStateEnum value) {
  switch (value) {
    case BmAdapterStateEnum.unknown:      return BluetoothAdapterState.unknown;
    case BmAdapterStateEnum.unavailable:  return BluetoothAdapterState.unavailable;
    case BmAdapterStateEnum.unauthorized: return BluetoothAdapterState.unauthorized;
    case BmAdapterStateEnum.turningOn:    return BluetoothAdapterState.turningOn;
    case BmAdapterStateEnum.on:           return BluetoothAdapterState.on;
    case BmAdapterStateEnum.turningOff:   return BluetoothAdapterState.turningOff;
    case BmAdapterStateEnum.off:          return BluetoothAdapterState.off;
  }
}

After format:

BluetoothAdapterState _bmToBluetoothAdapterState(BmAdapterStateEnum value) {
  switch (value) {
    case BmAdapterStateEnum.unknown:
      return BluetoothAdapterState.unknown;
    case BmAdapterStateEnum.unavailable:
      return BluetoothAdapterState.unavailable;
    case BmAdapterStateEnum.unauthorized:
      return BluetoothAdapterState.unauthorized;
    case BmAdapterStateEnum.turningOn:
      return BluetoothAdapterState.turningOn;
    case BmAdapterStateEnum.on:
      return BluetoothAdapterState.on;
    case BmAdapterStateEnum.turningOff:
      return BluetoothAdapterState.turningOff;
    case BmAdapterStateEnum.off:
      return BluetoothAdapterState.off;
  }
}
@chipweinberger chipweinberger changed the title Dart format makes this switch statement much harder to read Dart format makes single-line switch statements much harder to read Aug 22, 2023
@chipweinberger chipweinberger changed the title Dart format makes single-line switch statements much harder to read single-line switch statements become much harder to read Aug 22, 2023
@chipweinberger chipweinberger changed the title single-line switch statements become much harder to read single-line switch statements become harder to read Aug 22, 2023
@chipweinberger
Copy link
Author

Similar to this issue: #1252

@srawlins
Copy link
Member

Is there anyone that would actually find the after format more readable?

I more-or-less find the after format more readable, as the former format extends past 80 characters.

In my IDE, or on GitHub, or in a vertical diff, I find the former more readable, and would find it more readable even if it extended to ~100 characters. But in a side-by-side diff, I find the after format more readable, depending on my window size. Sometimes two side-by-side views at 80 characters wide barely fit, and sometimes there is room for 100 characters. Since I sometimes look at code in my IDE, sometimes at GitHub, and sometimes a side-by-side diff, the after format is the one that is least likely to soft wrap on whitespace, or extend to the right past the screen.

@chipweinberger
Copy link
Author

chipweinberger commented Aug 22, 2023

Appreciate your input. Yes it is a little wider than 80. I should have chosen a less wide example.

But I use a 120 character line length, and this behavior still happens.

For the sake of this issue, assume it was skinnier :)

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