keep-sorted could handle trailing commas better
- Dominant language
- Go
- Stars
- 403
- Forks
- 36
- Avg merge
- 4h 24m
- Merged PRs (30d)
- 1
Description
There's some logic in keep-sorted to try and gracefully handle lists that don't have a final trailing comma like
```java
ImmutableList.of(
// keep-sorted start
1,
3,
2
// keep-sorted end
);
```
would become the following (commas added and removed as necessary)
```java
ImmutableList.of(
// keep-sorted start
1,
2,
3
// keep-sorted end
);
```
https://github.com/google/keep-sorted/blob/62dd1440b1c8456b372bff09161ea9d847247671/keepsorted/block.go#L338-L340
There's a couple edge cases here that aren't handled very well right now
1. Trailing comments after a comma
This prevents the special case from being triggered
```java
ImmutableList.of(
// keep-sorted start
1,
3, // three
2
// keep-sorted end
);
```
would become
```java
ImmutableList.of(
// keep-sorted start
1,
2
3, // three
// keep-sorted end
);
```
2. Trailing comment after the last line
The logic still triggers, but we add a comma to the comment
```java
ImmutableList.of(
// keep-sorted start
1,
3,
2 // two
// keep-sorted end
);
```
would become
```java
ImmutableList.of(
// keep-sorted start
1,
2 // two,
3
// keep-sorted end
);
```
Contributor guide
Assessment
This issue has not been assessed yet.