Skip to content

feat: implement autofix for sort-keys#216

Open
sethamus wants to merge 3 commits intoeslint:mainfrom
sethamus:sort-keys-autofix
Open

feat: implement autofix for sort-keys#216
sethamus wants to merge 3 commits intoeslint:mainfrom
sethamus:sort-keys-autofix

Conversation

@sethamus
Copy link
Contributor

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?

This PR adds autofix support to sort-keys so eslint can automatically reorder object keys, while avoiding fixes that could detach/misplace comments.

What changes did you make? (Give an overview)

  • Marked sort-keys as fixable and implemented a fixer that swaps out-of-order adjacent members.
  • Updated/added tests to assert autofix output across existing invalid cases

Related Issues

Fixes #122

Is there anything you'd like reviewers to focus on?

@lumirlumir lumirlumir moved this from Needs Triage to Implementing in Triage Feb 20, 2026
@nzakas
Copy link
Member

nzakas commented Mar 9, 2026

@sethamus there are some comments to review.

includeComments: true,
});

if (after?.type === "Comma") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use the filter method for sourceCode.getTokenAfter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSONSourceCode doesn't support the filter option for getTokenAfter/getTokenBefore. I can open a separate PR to add support for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Implementing

Development

Successfully merging this pull request may close these issues.

Rule Change: make sort-keys rule fixable

4 participants