fix: sort-keys autofix fully sorts keys in a single pass#235
fix: sort-keys autofix fully sorts keys in a single pass#235crimsonjay0 wants to merge 5 commits into
Conversation
|
Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update. |
|
Not stale. I just forgot this was a draft. |
|
This PR has too many unnecessary unrelated changes to making the fix sort in a single pass.
|
| ) { | ||
| end++; | ||
| } | ||
| group = node.members.slice(start, end + 1); |
There was a problem hiding this comment.
Note for other reviewers: This would change the current behavior of reporting every unsorted key but only fixing the first group (because of the break after the context.report). I think this behavior is okay as the other groups will be fixed in subsequent rounds. The alternative would be to group everything and do the fixes for every group.
|
Thank you for refactoring this, I only have some small notes. |
| return null; | ||
| let group = node.members; | ||
|
|
||
| if (allowLineSeparatedGroups) { |
There was a problem hiding this comment.
Currently there is no test condition which effectively checks that the separated groups before or after are unchanged (group is currently always all members)
| const nameA = getKey(a); | ||
| const nameB = getKey(b); | ||
|
|
||
| if (nameA === nameB) { |
There was a problem hiding this comment.
This if is unnecessary as the next if with the test condition aFirst && bFirst also matches with the same return value.
Prerequisites checklist
AI acknowledgment
What is the purpose of this pull request?
The
sort-keysautofix previously used a pairwise swap strategy, where each--fixpass only swapped two adjacent out-of-order members. For a fully reversed object with N keys, this required up to N-1 passes ofeslint --fixto reach a fully sorted state.What changes did you make? (Give an overview)
I replaced the pairwise swap fixer with a segment-based sorting approach that fully sorts all keys in a single pass.
Related Issues
Fixes #222
Is there anything you'd like reviewers to focus on?