You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Preserve trailing commas for enums with members when commas are preserved (#1703)
This PR changes the formatter to have it maintain trailing commas of last enum constants when there are members.
So:
```dart
enum E { a, b, c,; int x; }
```
Becomes:
```dart
enum E {
a,
b,
c,
;
int x;
}
```
Instead of:
```dart
enum E {
a,
b,
c;
int x;
}
```
Fixes#1678Fixes#1729
Additionally, a similar style choice was presented in #1660 (comment)
**Affected users**:
- Those passing the `trailing_commas: preserve` config option and adding a trailing comma to their enum cases.
- Users who don't already pass a trailing comma, aren't affected. So this PR shouldn't have undesirable effects on existing users.
**Benefits**:
- Maintains developer's intent
- Less churn when adding additional member cases
(Personally, I always add a trailing semicolon to avoid churn and to also make it even clearer this is an advanced enum with members.)
**Downsides**:
- 7 additional logical lines of code to maintain
**Additional considerations**:
I also considered implementing this for `enum E { a, b,; }`, however, that would require more drastic changes to the formatter as far as I can tell.
Additionally, in this case the trailing semicolon provides fewer benefits:
- churn when adding new members is the same if there was a trailing semicolon or not
- giving the enum other members also only amounts to new lines being added rather than changed so again, no real churn.
**Notes**
- One test was changed due to this being a change in behavior.
- This was surprisingly easy and enjoyable to implement (compliment to the existing code base).
- I didn't make any changes to the `CHANGELOG.md` since this trailing commas preservation hasn't shipped yet so its behaviour is still undefined.
0 commit comments