Skip to content

fix: sort-keys autofix fully sorts keys in a single pass#235

Open
crimsonjay0 wants to merge 2 commits into
eslint:mainfrom
crimsonjay0:sort-keys-single-pass-autofix
Open

fix: sort-keys autofix fully sorts keys in a single pass#235
crimsonjay0 wants to merge 2 commits into
eslint:mainfrom
crimsonjay0:sort-keys-single-pass-autofix

Conversation

@crimsonjay0
Copy link
Copy Markdown

Prerequisites checklist

AI acknowledgment

  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

What is the purpose of this pull request?

The sort-keys autofix previously used a pairwise swap strategy, where each --fix pass only swapped two adjacent out-of-order members. For a fully reversed object with N keys, this required up to N-1 passes of eslint --fix to 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?

@eslint-github-bot eslint-github-bot Bot added the bug Something isn't working label May 5, 2026
@eslintbot eslintbot added this to Triage May 5, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage May 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the Stale label May 15, 2026
@crimsonjay0
Copy link
Copy Markdown
Author

Not stale. I just forgot this was a draft.

@crimsonjay0 crimsonjay0 marked this pull request as ready for review May 19, 2026 12:46
@lumirlumir lumirlumir removed the Stale label May 19, 2026
@DMartens
Copy link
Copy Markdown

This PR has too many unnecessary unrelated changes to making the fix sort in a single pass.
Can you please limit the changes to the context.fix method as there is no need to precompute the fixes if there are none (which should be vast majority of cases)?
You can just use break after reporting to only report once.

Note that @humanwhocodes/momoa doesn't include comments in the object.members tree, so we can't just see if a member is preceded by a comment
You can use sourceCode.getTokenBefore(property, { includeComents: true }) for this.

@lumirlumir lumirlumir moved this from Needs Triage to Triaging in Triage May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted bug Something isn't working

Projects

Status: Triaging

Development

Successfully merging this pull request may close these issues.

Bug: sort-keys autofix requires multiple passes

4 participants