Skip to content

Conversation

Pixel998
Copy link
Contributor

@Pixel998 Pixel998 commented Aug 19, 2025

Prerequisites checklist

What is the purpose of this pull request?

This PR enables autofix for the sort-keys rule so objects with unsorted keys are automatically reordered when running with --fix.

What changes did you make? (Give an overview)

  • Added a fixer that reorders object keys.
  • Updated tests.

Related Issues

Fixes #122

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

@eslintbot eslintbot added this to Triage Aug 19, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Aug 19, 2025
@lumirlumir lumirlumir requested a review from Copilot August 19, 2025 10:17
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements autofix functionality for the sort-keys ESLint rule, allowing objects with unsorted keys to be automatically reordered when running with the --fix option.

  • Adds autofix capability to the sort-keys rule by marking it as fixable: "code"
  • Implements a sorting algorithm that respects existing configuration options (asc/desc, case sensitivity, natural sorting, line-separated groups)
  • Updates comprehensive test coverage with expected output for all invalid test cases

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/rules/sort-keys.js Adds fixable metadata and implements autofix logic with key comparison and object reconstruction
tests/rules/sort-keys.test.js Adds expected output assertions for all invalid test cases to verify autofix behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

comment.range[1] <= node.range[1],
);

if (hasComments) {
Copy link
Preview

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

The comment detection logic should be documented to explain why autofix is disabled when comments are present within the object, as this might not be obvious to maintainers.

Copilot uses AI. Check for mistakes.

@mdjermanovic mdjermanovic moved this from Needs Triage to Implementing in Triage Aug 23, 2025
@@ -226,6 +255,126 @@ const rule = {
sensitivity,
sortName,
},
fix(fixer) {
Copy link
Member

Choose a reason for hiding this comment

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

This aims to sort the entire object at once, not just the reported property?

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
3 participants