-
-
Notifications
You must be signed in to change notification settings - Fork 12
feat: implement autofix for sort-keys #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.
@@ -226,6 +255,126 @@ const rule = { | |||
sensitivity, | |||
sortName, | |||
}, | |||
fix(fixer) { |
There was a problem hiding this comment.
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?
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)
Related Issues
Fixes #122
Is there anything you'd like reviewers to focus on?